Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,10 +106,23 @@ async def predict_image_and_nutrition(file: UploadFile = File(...)):
|
|
| 106 |
return json.loads(response.decode())[0]["generated_text"]
|
| 107 |
|
| 108 |
# Use the prediction to generate nutrition information
|
| 109 |
-
prompt = f"Nutrition information (Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, Pantothenic acid) for {prediction} in formatted list"
|
| 110 |
-
response = call_llm(llm_client, prompt)
|
| 111 |
|
| 112 |
-
return {"predicted_label": prediction, "nutrition_info": response}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
return JSONResponse(
|
| 115 |
status_code=500,
|
|
|
|
| 106 |
return json.loads(response.decode())[0]["generated_text"]
|
| 107 |
|
| 108 |
# Use the prediction to generate nutrition information
|
| 109 |
+
# prompt = f"Nutrition information (Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, Pantothenic acid) for {prediction} in formatted list"
|
| 110 |
+
# response = call_llm(llm_client, prompt)
|
| 111 |
|
| 112 |
+
# return {"predicted_label": prediction, "nutrition_info": response}
|
| 113 |
+
|
| 114 |
+
nutrition_prompt = f"Nutrition information (Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, Pantothenic acid) for {prediction} in formatted list only."
|
| 115 |
+
nutrition_info = call_llm(llm_client, nutrition_prompt)
|
| 116 |
+
|
| 117 |
+
# Second prompt: Information about the prediction label
|
| 118 |
+
info_prompt = f"Provide information about the label {prediction}, including its origin, general uses, and key characteristics."
|
| 119 |
+
prediction_info = call_llm(llm_client, info_prompt)
|
| 120 |
+
|
| 121 |
+
return {
|
| 122 |
+
"predicted_label": prediction,
|
| 123 |
+
"nutrition_info": nutrition_info,
|
| 124 |
+
"prediction_info": prediction_info
|
| 125 |
+
}
|
| 126 |
except Exception as e:
|
| 127 |
return JSONResponse(
|
| 128 |
status_code=500,
|