nehapasricha94 commited on
Commit
9961a70
·
verified ·
1 Parent(s): a05253c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -173,14 +173,16 @@ 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, np.ndarray):
 
 
177
  image = Image.fromarray(image) # Convert to PIL Image if it's a NumPy array
178
 
179
  # Analyze colors
180
  dominant_colors = analyze_colors(image)
181
  if dominant_colors is None:
182
  return "Error analyzing colors"
183
-
184
  color_emotions, stress_levels = color_emotion_analysis(dominant_colors)
185
 
186
  # Analyze patterns
@@ -191,11 +193,11 @@ def analyze_emotion_from_image(image):
191
 
192
  return overall_result
193
  except Exception as e:
194
- print(f"Error processing image: {str(e)}")
195
  return f"Error processing image: {str(e)}"
196
 
197
 
198
 
 
199
  # Gradio interface to upload image files and perform analysis
200
  iface = gr.Interface(fn=analyze_emotion_from_image, inputs="image", outputs="text")
201
 
 
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)
183
  if dominant_colors is None:
184
  return "Error analyzing colors"
185
+
186
  color_emotions, stress_levels = color_emotion_analysis(dominant_colors)
187
 
188
  # Analyze patterns
 
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