Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -96,12 +96,14 @@ def generate_analysis(uploaded_file, client):
|
|
| 96 |
|
| 97 |
try:
|
| 98 |
st.write("Calling the API...") # Debugging statement
|
|
|
|
|
|
|
| 99 |
response = client.chat.completions.create(
|
| 100 |
model="llama-3.2-11b-vision-preview",
|
| 101 |
messages=[
|
| 102 |
{
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
You are an expert nutritionist with advanced image analysis capabilities.
|
| 106 |
Your task is to analyze the provided image, identify all visible food items, and estimate their calorie content with high accuracy.
|
| 107 |
**Instructions:**
|
|
@@ -116,12 +118,17 @@ def generate_analysis(uploaded_file, client):
|
|
| 116 |
- **Total Estimated Calories:** [value] kcal
|
| 117 |
If the image lacks sufficient detail or is unclear, specify the limitations and include your confidence level in the estimate as a percentage.
|
| 118 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
],
|
| 121 |
temperature=0.2,
|
| 122 |
max_tokens=400,
|
| 123 |
top_p=0.5
|
| 124 |
)
|
|
|
|
| 125 |
st.write("API response received.") # Debugging statement
|
| 126 |
analysis_result = response.choices[0].message.content
|
| 127 |
st.write("Analysis Result: ", analysis_result) # Debugging statement
|
|
@@ -130,6 +137,7 @@ def generate_analysis(uploaded_file, client):
|
|
| 130 |
st.error(f"API communication error: {e}")
|
| 131 |
return None
|
| 132 |
|
|
|
|
| 133 |
# UI COMPONENTS
|
| 134 |
def display_main_interface():
|
| 135 |
"""Render primary application interface"""
|
|
|
|
| 96 |
|
| 97 |
try:
|
| 98 |
st.write("Calling the API...") # Debugging statement
|
| 99 |
+
|
| 100 |
+
# Corrected the message format
|
| 101 |
response = client.chat.completions.create(
|
| 102 |
model="llama-3.2-11b-vision-preview",
|
| 103 |
messages=[
|
| 104 |
{
|
| 105 |
+
"role": "system", # System message
|
| 106 |
+
"content": """
|
| 107 |
You are an expert nutritionist with advanced image analysis capabilities.
|
| 108 |
Your task is to analyze the provided image, identify all visible food items, and estimate their calorie content with high accuracy.
|
| 109 |
**Instructions:**
|
|
|
|
| 118 |
- **Total Estimated Calories:** [value] kcal
|
| 119 |
If the image lacks sufficient detail or is unclear, specify the limitations and include your confidence level in the estimate as a percentage.
|
| 120 |
"""
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
"role": "user", # User message
|
| 124 |
+
"content": f"Analyze the following image of food: {image_url}" # Include the image URL
|
| 125 |
}
|
| 126 |
],
|
| 127 |
temperature=0.2,
|
| 128 |
max_tokens=400,
|
| 129 |
top_p=0.5
|
| 130 |
)
|
| 131 |
+
|
| 132 |
st.write("API response received.") # Debugging statement
|
| 133 |
analysis_result = response.choices[0].message.content
|
| 134 |
st.write("Analysis Result: ", analysis_result) # Debugging statement
|
|
|
|
| 137 |
st.error(f"API communication error: {e}")
|
| 138 |
return None
|
| 139 |
|
| 140 |
+
|
| 141 |
# UI COMPONENTS
|
| 142 |
def display_main_interface():
|
| 143 |
"""Render primary application interface"""
|