SURESHBEEKHANI commited on
Commit
51cd072
·
verified ·
1 Parent(s): 8e64a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -89,11 +89,13 @@ def generate_analysis(uploaded_file, client):
89
  """Generate AI-powered food analysis"""
90
  base64_image, img_format = process_image(uploaded_file)
91
  if not base64_image:
 
92
  return None
93
 
94
  image_url = f"data:image/{img_format.lower()};base64,{base64_image}"
95
 
96
  try:
 
97
  response = client.chat.completions.create(
98
  model="llama-3.2-11b-vision-preview",
99
  messages=[
@@ -120,7 +122,10 @@ def generate_analysis(uploaded_file, client):
120
  max_tokens=400,
121
  top_p=0.5
122
  )
123
- return response.choices[0].message.content
 
 
 
124
  except Exception as e:
125
  st.error(f"API communication error: {e}")
126
  return None
@@ -172,8 +177,12 @@ def render_sidebar(client):
172
  if st.button("Analyze Meal 🍽️"):
173
  with st.spinner("Analyzing image..."):
174
  report = generate_analysis(uploaded_file, client)
175
- st.session_state.analysis_result = report
176
- st.rerun()
 
 
 
 
177
 
178
  # APPLICATION ENTRYPOINT
179
  def main():
 
89
  """Generate AI-powered food analysis"""
90
  base64_image, img_format = process_image(uploaded_file)
91
  if not base64_image:
92
+ st.error("Image processing failed")
93
  return None
94
 
95
  image_url = f"data:image/{img_format.lower()};base64,{base64_image}"
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=[
 
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
128
+ return analysis_result
129
  except Exception as e:
130
  st.error(f"API communication error: {e}")
131
  return None
 
177
  if st.button("Analyze Meal 🍽️"):
178
  with st.spinner("Analyzing image..."):
179
  report = generate_analysis(uploaded_file, client)
180
+ if report:
181
+ st.session_state.analysis_result = report
182
+ st.write("Analysis Result:", report) # Debugging line to display result
183
+ st.rerun()
184
+ else:
185
+ st.error("Analysis failed. Please try again.")
186
 
187
  # APPLICATION ENTRYPOINT
188
  def main():