nehapasricha94 commited on
Commit
eb70cbe
1 Parent(s): 9961a70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -173,10 +173,15 @@ def analyze_emotion_from_text(text):
173
  def analyze_emotion_from_image(image):
174
  try:
175
  # Ensure the input image is a PIL image
 
176
  if isinstance(image, dict) and "path" in image:
177
- image = Image.open(requests.get(image["path"], stream=True).raw) # Load image from URL
 
178
  elif isinstance(image, np.ndarray):
179
- image = Image.fromarray(image) # Convert to PIL Image if it's a NumPy array
 
 
 
180
 
181
  # Analyze colors
182
  dominant_colors = analyze_colors(image)
@@ -184,20 +189,24 @@ def analyze_emotion_from_image(image):
184
  return "Error analyzing colors"
185
 
186
  color_emotions, stress_levels = color_emotion_analysis(dominant_colors)
 
187
 
188
  # Analyze patterns
189
  pattern_analysis, pattern_stress = analyze_patterns(image)
 
190
 
191
  # Compute overall result
192
  overall_result = compute_overall_result(color_emotions, stress_levels, pattern_analysis, pattern_stress)
193
 
194
  return overall_result
195
  except Exception as e:
 
196
  return f"Error processing image: {str(e)}"
197
 
198
 
199
 
200
 
 
201
  # Gradio interface to upload image files and perform analysis
202
  iface = gr.Interface(fn=analyze_emotion_from_image, inputs="image", outputs="text")
203
 
 
173
  def analyze_emotion_from_image(image):
174
  try:
175
  # Ensure the input image is a PIL image
176
+ print(f"Initial input type: {type(image)}")
177
  if isinstance(image, dict) and "path" in image:
178
+ image = Image.open(requests.get(image["path"], stream=True).raw)
179
+ print("Loaded image from URL.")
180
  elif isinstance(image, np.ndarray):
181
+ image = Image.fromarray(image)
182
+ print("Converted image from NumPy array.")
183
+
184
+ print(f"Image size: {image.size}, mode: {image.mode}")
185
 
186
  # Analyze colors
187
  dominant_colors = analyze_colors(image)
 
189
  return "Error analyzing colors"
190
 
191
  color_emotions, stress_levels = color_emotion_analysis(dominant_colors)
192
+ print(f"Color emotions: {color_emotions}, Stress levels: {stress_levels}")
193
 
194
  # Analyze patterns
195
  pattern_analysis, pattern_stress = analyze_patterns(image)
196
+ print(f"Pattern analysis: {pattern_analysis}, Pattern stress: {pattern_stress}")
197
 
198
  # Compute overall result
199
  overall_result = compute_overall_result(color_emotions, stress_levels, pattern_analysis, pattern_stress)
200
 
201
  return overall_result
202
  except Exception as e:
203
+ print(f"Error processing image: {str(e)}")
204
  return f"Error processing image: {str(e)}"
205
 
206
 
207
 
208
 
209
+
210
  # Gradio interface to upload image files and perform analysis
211
  iface = gr.Interface(fn=analyze_emotion_from_image, inputs="image", outputs="text")
212