Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,7 +83,8 @@ async def predict_image_and_nutrition(file: UploadFile = File(...)):
|
|
| 83 |
|
| 84 |
# Define the repository ID and your token
|
| 85 |
#repo_id = "google/gemma-2-9b-it"
|
| 86 |
-
repo_id = "
|
|
|
|
| 87 |
# repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 88 |
api_token = "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21"
|
| 89 |
|
|
@@ -106,13 +107,24 @@ 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 |
-
# prompt = f"Provide all the nutrition information for {prediction}, including Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, and Pantothenic acid. Please present the information in a clear, formatted list only, without additional explanations."
|
| 111 |
-
response = call_llm(llm_client, prompt)
|
| 112 |
|
| 113 |
-
return {"predicted_label": prediction, "nutrition_info": response}
|
| 114 |
|
|
|
|
|
|
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
except Exception as e:
|
| 117 |
return JSONResponse(
|
| 118 |
status_code=500,
|
|
|
|
| 83 |
|
| 84 |
# Define the repository ID and your token
|
| 85 |
#repo_id = "google/gemma-2-9b-it"
|
| 86 |
+
repo_id = "Qwen/Qwen2.5-72B-Instruct"
|
| 87 |
+
# repo_id = "microsoft/Phi-3-mini-4k-instruct"
|
| 88 |
# repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 89 |
api_token = "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21"
|
| 90 |
|
|
|
|
| 107 |
return json.loads(response.decode())[0]["generated_text"]
|
| 108 |
|
| 109 |
# Use the prediction to generate nutrition information
|
| 110 |
+
# 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"
|
| 111 |
+
# # prompt = f"Provide all the nutrition information for {prediction}, including Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, and Pantothenic acid. Please present the information in a clear, formatted list only, without additional explanations."
|
| 112 |
+
# response = call_llm(llm_client, prompt)
|
| 113 |
|
| 114 |
+
# return {"predicted_label": prediction, "nutrition_info": response}
|
| 115 |
|
| 116 |
+
nutrition_prompt = f"Provide the nutrition information (Calories, Protein, Carbohydrates, Dietary Fiber, Sugars, Fat, Sodium, Potassium, Vitamin C, Vitamin B6, Folate, Niacin, Pantothenic acid) for {prediction} per 100 grams in a formatted list only."
|
| 117 |
+
nutrition_info = call_llm(llm_client, nutrition_prompt)
|
| 118 |
|
| 119 |
+
# Second prompt: Health benefits and tips
|
| 120 |
+
health_benefits_prompt = f"Provide the health benefits and considerations for {prediction} and give tips for making it healthier."
|
| 121 |
+
health_benefits_and_tips = call_llm(llm_client, health_benefits_prompt)
|
| 122 |
+
|
| 123 |
+
return {
|
| 124 |
+
"predicted_label": prediction,
|
| 125 |
+
"nutrition_info": nutrition_info,
|
| 126 |
+
"health_benefits_and_tips": health_benefits_and_tips
|
| 127 |
+
}
|
| 128 |
except Exception as e:
|
| 129 |
return JSONResponse(
|
| 130 |
status_code=500,
|