Update app.py
Browse files
app.py
CHANGED
|
@@ -12,13 +12,16 @@ def get_nutritional_info(description):
|
|
| 12 |
prompt = f"{nutrition_prompt}: {description}"
|
| 13 |
|
| 14 |
try:
|
| 15 |
-
response = openai.
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
max_tokens=300,
|
| 19 |
temperature=0.7
|
| 20 |
)
|
| 21 |
-
return response.choices[0].
|
| 22 |
except Exception as e:
|
| 23 |
return f"Oops! Something went wrong: {str(e)}"
|
| 24 |
|
|
@@ -37,7 +40,7 @@ def analyze_meal(image, description):
|
|
| 37 |
|
| 38 |
# Gradio app layout
|
| 39 |
inputs = [
|
| 40 |
-
gr.Image(label="Upload your meal (Take a bite out of that picture!)", type="pil"
|
| 41 |
gr.Textbox(label="Describe your meal if image recognition fails", lines=2, placeholder="e.g., a plate of upma with coconut chutney"),
|
| 42 |
]
|
| 43 |
|
|
|
|
| 12 |
prompt = f"{nutrition_prompt}: {description}"
|
| 13 |
|
| 14 |
try:
|
| 15 |
+
response = openai.ChatCompletion.create(
|
| 16 |
+
model="gpt-3.5-turbo", # Using GPT-3.5 turbo model
|
| 17 |
+
messages=[
|
| 18 |
+
{"role": "system", "content": "You are a nutrition expert."},
|
| 19 |
+
{"role": "user", "content": prompt}
|
| 20 |
+
],
|
| 21 |
max_tokens=300,
|
| 22 |
temperature=0.7
|
| 23 |
)
|
| 24 |
+
return response.choices[0].message['content'].strip()
|
| 25 |
except Exception as e:
|
| 26 |
return f"Oops! Something went wrong: {str(e)}"
|
| 27 |
|
|
|
|
| 40 |
|
| 41 |
# Gradio app layout
|
| 42 |
inputs = [
|
| 43 |
+
gr.Image(label="Upload your meal (Take a bite out of that picture!)", type="pil"),
|
| 44 |
gr.Textbox(label="Describe your meal if image recognition fails", lines=2, placeholder="e.g., a plate of upma with coconut chutney"),
|
| 45 |
]
|
| 46 |
|