Spaces:
Sleeping
Sleeping
293droid commited on
Commit ·
2ef9c19
1
Parent(s): ddbe441
fix: shea butter parser, superfat display, stop hallucination tokens
Browse files
app.py
CHANGED
|
@@ -49,7 +49,8 @@ def ask_model(prompt: str, context: str) -> str:
|
|
| 49 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 50 |
{"role": "user", "content": full_prompt}
|
| 51 |
],
|
| 52 |
-
max_tokens=
|
|
|
|
| 53 |
)
|
| 54 |
return response.choices[0].message.content
|
| 55 |
except Exception as e:
|
|
@@ -69,11 +70,19 @@ def parse_recipe(text: str) -> dict[str, float]:
|
|
| 69 |
weight = float(weight_str)
|
| 70 |
oil_fragment = oil_fragment.strip().rstrip(',').strip()
|
| 71 |
matched_key = None
|
|
|
|
| 72 |
for key in OILS:
|
| 73 |
-
|
| 74 |
-
if any(word in oil_fragment for word in key_words if len(word) > 3):
|
| 75 |
matched_key = key
|
| 76 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
if matched_key and weight > 0:
|
| 78 |
recipe[matched_key] = recipe.get(matched_key, 0) + weight
|
| 79 |
return recipe
|
|
|
|
| 49 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 50 |
{"role": "user", "content": full_prompt}
|
| 51 |
],
|
| 52 |
+
max_tokens=500,
|
| 53 |
+
stop=["user ", "User ", "\nuser", "\nUser"],
|
| 54 |
)
|
| 55 |
return response.choices[0].message.content
|
| 56 |
except Exception as e:
|
|
|
|
| 70 |
weight = float(weight_str)
|
| 71 |
oil_fragment = oil_fragment.strip().rstrip(',').strip()
|
| 72 |
matched_key = None
|
| 73 |
+
# Try exact match first
|
| 74 |
for key in OILS:
|
| 75 |
+
if key == oil_fragment.strip():
|
|
|
|
| 76 |
matched_key = key
|
| 77 |
break
|
| 78 |
+
# Then try word match
|
| 79 |
+
if not matched_key:
|
| 80 |
+
for key in OILS:
|
| 81 |
+
key_words = key.replace('(','').replace(')','').split()
|
| 82 |
+
scored_words = [w for w in key_words if len(w) > 4 and w not in ["butter","oil","seed","palm"]]
|
| 83 |
+
if scored_words and all(w in oil_fragment for w in scored_words):
|
| 84 |
+
matched_key = key
|
| 85 |
+
break
|
| 86 |
if matched_key and weight > 0:
|
| 87 |
recipe[matched_key] = recipe.get(matched_key, 0) + weight
|
| 88 |
return recipe
|