yifehuang97 commited on
Commit
92192b7
Β·
verified Β·
1 Parent(s): b070181

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -16,23 +16,29 @@ device = None
16
  genai.configure(api_key='AIzaSyApqa65vVYTmw4FC4wP-6-_xpBLxXdctxE')
17
  gemini_model = genai.GenerativeModel("gemini-2.0-flash")
18
 
19
- PARSING_PROMPT = """Parse the user's counting instruction into two lists:
20
- - A (include): objects to count
21
- - B (exclude): objects to exclude from counting
22
 
23
  Rules:
24
- 1. Split on "and", "or", and commas
25
- 2. Reattach shared head nouns (e.g., "red and black beans" β†’ "red beans", "black beans")
26
- 3. Remove from B items that are equivalent to A (synonyms/variants/abbreviations)
27
- 4. Remove from B items that are more specific than A
28
- 5. If B is more general than A but shares head noun, rewrite B to specific non-overlapping forms
29
-
30
- Examples:
31
- - "Count green apples, not red apples" β†’ A: ["green apples"], B: ["red apples"]
32
- - "Count apples, not green apples" β†’ A: ["apples"], B: []
33
- - "Count green apples, not apples" β†’ A: ["green apples"], B: ["non-green apples"]
34
- - "Count fries, not chips" β†’ A: ["fries"], B: []
35
- - "Count black beans, not poker chips" β†’ A: ["black beans"], B: ["poker chips"]
 
 
 
 
 
 
 
 
36
 
37
  User instruction: {instruction}
38
 
@@ -40,7 +46,6 @@ Respond ONLY with a JSON object in this exact format, no other text:
40
  {{"A": ["item1", "item2"], "B": ["item3"]}}
41
  """
42
 
43
-
44
  def parse_counting_instruction(instruction: str) -> tuple[str, str]:
45
  """
46
  Parse natural language counting instruction using Gemini 2.0 Flash.
 
16
  genai.configure(api_key='AIzaSyApqa65vVYTmw4FC4wP-6-_xpBLxXdctxE')
17
  gemini_model = genai.GenerativeModel("gemini-2.0-flash")
18
 
19
+ PARSING_PROMPT = """Parse sentences of the form "Count A, not B" into two listsβ€”A (include) and B (exclude)β€”splitting on "and", "or", and commas, and reattaching shared head nouns (e.g., "red and black beans" β†’ "red beans", "black beans").
 
 
20
 
21
  Rules:
22
+ - Remove from B items that are equivalent to items in A (synonyms/variants/abbreviations/regional terms)
23
+ - Keep B items that are more specific than A (for fine-grained exclusion)
24
+ - If B is more general than A but shares the head noun, remove B (contradictory)
25
+
26
+ Case 1 β€” Different head nouns β†’ Keep B
27
+ Example 1: Count green apples and red beans, not yellow screws and white rice β†’ A: ["green apples", "red beans"], B: ["yellow screws", "white rice"]
28
+ Example 2: Count black beans, not poker chips or nails β†’ A: ["black beans"], B: ["poker chips", "nails"]
29
+
30
+ Case 2 β€” Equivalent items β†’ Remove from B
31
+ Example 1: Count fries and TV, not chips and television β†’ A: ["fries", "TV"], B: []
32
+ Example 2: Count garbanzo beans and couch, not chickpeas and sofa β†’ A: ["garbanzo beans", "couch"], B: []
33
+
34
+ Case 3 β€” B more specific than A β†’ Keep B (for fine-grained exclusion)
35
+ Example 1: Count apples and beans, not green apples and black beans β†’ A: ["apples", "beans"], B: ["green apples", "black beans"]
36
+ Example 2: Count beans, not white beans or yellow beans β†’ A: ["beans"], B: ["white beans", "yellow beans"]
37
+ Example 3: Count people, not women β†’ A: ["people"], B: ["women"]
38
+
39
+ Case 4 β€” B more general than A β†’ Remove B (contradictory)
40
+ Example 1: Count green apples, not apples β†’ A: ["green apples"], B: []
41
+ Example 2: Count red beans and green apples, not beans and apples β†’ A: ["red beans", "green apples"], B: []
42
 
43
  User instruction: {instruction}
44
 
 
46
  {{"A": ["item1", "item2"], "B": ["item3"]}}
47
  """
48
 
 
49
  def parse_counting_instruction(instruction: str) -> tuple[str, str]:
50
  """
51
  Parse natural language counting instruction using Gemini 2.0 Flash.