Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -5
src/streamlit_app.py
CHANGED
|
@@ -90,17 +90,29 @@ def main():
|
|
| 90 |
data = nutritional_info.get(true_label)
|
| 91 |
|
| 92 |
if data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
prompt = (
|
| 94 |
-
f"
|
| 95 |
-
f"{
|
| 96 |
-
f"{data['ingredients']} and usually {data['method']}. Try {data['substitute']} as a healthier swap.\n\n"
|
| 97 |
-
f"Paraphrase this nutritional info without changing facts:"
|
| 98 |
)
|
| 99 |
else:
|
| 100 |
prompt = f"Give the typical calories, macros, and nutrition facts for {label}. Provide realistic values even if estimated."
|
| 101 |
|
| 102 |
inputs = tokenizer_t5(prompt, return_tensors="pt", truncation=True).to(device)
|
| 103 |
-
output_ids = model_t5.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
response = tokenizer_t5.decode(output_ids[0], skip_special_tokens=True)
|
| 105 |
|
| 106 |
st.subheader("🧾 Nutrition Overview")
|
|
|
|
| 90 |
data = nutritional_info.get(true_label)
|
| 91 |
|
| 92 |
if data:
|
| 93 |
+
base_description = (
|
| 94 |
+
f"A typical {true_label} serving ({data['serving']}) contains about {data['calories']}, "
|
| 95 |
+
f"with {data['protein']} protein, {data['carbs']} carbs, and {data['fat']} fat. "
|
| 96 |
+
f"Made from {data['ingredients']} and usually {data['method']}. "
|
| 97 |
+
f"Try {data['substitute']} as a healthier swap."
|
| 98 |
+
)
|
| 99 |
prompt = (
|
| 100 |
+
f"Paraphrase this nutritional description into a friendly, conversational tone without changing any facts:\n\n"
|
| 101 |
+
f"{base_description}"
|
|
|
|
|
|
|
| 102 |
)
|
| 103 |
else:
|
| 104 |
prompt = f"Give the typical calories, macros, and nutrition facts for {label}. Provide realistic values even if estimated."
|
| 105 |
|
| 106 |
inputs = tokenizer_t5(prompt, return_tensors="pt", truncation=True).to(device)
|
| 107 |
+
output_ids = model_t5.generate(
|
| 108 |
+
inputs["input_ids"],
|
| 109 |
+
max_new_tokens=100,
|
| 110 |
+
do_sample=True,
|
| 111 |
+
temperature=1.0,
|
| 112 |
+
top_p=0.95,
|
| 113 |
+
top_k=40,
|
| 114 |
+
repetition_penalty=1.1
|
| 115 |
+
)
|
| 116 |
response = tokenizer_t5.decode(output_ids[0], skip_special_tokens=True)
|
| 117 |
|
| 118 |
st.subheader("🧾 Nutrition Overview")
|