shingguy1 commited on
Commit
1eac402
·
verified ·
1 Parent(s): bfd5c1d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +9 -7
src/streamlit_app.py CHANGED
@@ -53,7 +53,7 @@ def main():
53
  st.sidebar.header("Models Used")
54
  st.sidebar.markdown("""
55
  - 🖼️ **Image Classifier**: `shingguy1/fine_tuned_vit`
56
- - 💬 **Paraphraser**: `google/flan-t5-small`
57
  """)
58
 
59
  transform = transforms.Compose([
@@ -97,7 +97,8 @@ def main():
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:
@@ -107,14 +108,15 @@ def main():
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")
119
  st.info(response)
120
 
 
53
  st.sidebar.header("Models Used")
54
  st.sidebar.markdown("""
55
  - 🖼️ **Image Classifier**: `shingguy1/fine_tuned_vit`
56
+ - 💬 **Paraphraser**: `google/flan-t5-small` (beam search mode)
57
  """)
58
 
59
  transform = transforms.Compose([
 
97
  f"Try {data['substitute']} as a healthier swap."
98
  )
99
  prompt = (
100
+ f"Rewrite the following nutritional information in a clear and friendly tone. "
101
+ f"Do not add or change any facts. Keep the sentence structure simple:\n\n"
102
  f"{base_description}"
103
  )
104
  else:
 
108
  output_ids = model_t5.generate(
109
  inputs["input_ids"],
110
  max_new_tokens=100,
111
+ num_beams=4,
112
+ early_stopping=True
 
 
 
113
  )
114
  response = tokenizer_t5.decode(output_ids[0], skip_special_tokens=True)
115
 
116
+ # Fallback if the output seems too short or misses key phrases
117
+ if "calories" not in response.lower() or len(response.split()) < 10:
118
+ response = base_description
119
+
120
  st.subheader("🧾 Nutrition Overview")
121
  st.info(response)
122