Amitz244 commited on
Commit
950e2fc
·
verified ·
1 Parent(s): cb48075

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -59,11 +59,11 @@ def emo_preprocess(image):
59
 
60
  # Inference function
61
  def predict_emotion(image):
62
- # If the image is passed as a PIL Image, you can directly use it
63
  if isinstance(image, Image.Image):
64
  img = image.convert("RGB")
65
  else:
66
- img = Image.open(image).convert("RGB") # In case the input is a path or something else
67
 
68
  img = emo_preprocess(img)
69
 
@@ -72,10 +72,10 @@ def predict_emotion(image):
72
  predicted = outputs.argmax(1).item()
73
 
74
  emotion = idx2label[predicted]
75
- emoji = emotion_emoji.get(emotion, "❓") # Default to "?" if no emoji found
76
  return f"{emotion} {emoji}"
77
 
78
- # Example images (provide local file paths or URLs)
79
  example_images = [
80
  "https://img.freepik.com/free-photo/emotive-excited-female-with-dark-skin-crisp-hair-keeps-hands-clenched-fists-exclaims-with-positiveness-as-achieved-success-her-career-opens-mouth-widely-isolated-white-wall_273609-16443.jpg",
81
  "https://t4.ftcdn.net/jpg/01/18/44/59/360_F_118445958_NtP7tIsD0CBPyG7Uad7Z2KxVWrsfCPjP.jpg",
@@ -90,7 +90,7 @@ iface = gr.Interface(
90
  outputs=gr.Textbox(label="Emotion"),
91
  title="PerceptCLIP-Emotions",
92
  description="This model predicts the emotion evoked by an image and returns the corresponding emoji along with the emotion name.",
93
- examples=example_images # Add example images here
94
  )
95
 
96
  if __name__ == "__main__":
 
59
 
60
  # Inference function
61
  def predict_emotion(image):
62
+ # If the image is passed as a PIL Image
63
  if isinstance(image, Image.Image):
64
  img = image.convert("RGB")
65
  else:
66
+ img = Image.open(image).convert("RGB")
67
 
68
  img = emo_preprocess(img)
69
 
 
72
  predicted = outputs.argmax(1).item()
73
 
74
  emotion = idx2label[predicted]
75
+ emoji = emotion_emoji.get(emotion, "❓")
76
  return f"{emotion} {emoji}"
77
 
78
+ # Example images
79
  example_images = [
80
  "https://img.freepik.com/free-photo/emotive-excited-female-with-dark-skin-crisp-hair-keeps-hands-clenched-fists-exclaims-with-positiveness-as-achieved-success-her-career-opens-mouth-widely-isolated-white-wall_273609-16443.jpg",
81
  "https://t4.ftcdn.net/jpg/01/18/44/59/360_F_118445958_NtP7tIsD0CBPyG7Uad7Z2KxVWrsfCPjP.jpg",
 
90
  outputs=gr.Textbox(label="Emotion"),
91
  title="PerceptCLIP-Emotions",
92
  description="This model predicts the emotion evoked by an image and returns the corresponding emoji along with the emotion name.",
93
+ examples=example_images
94
  )
95
 
96
  if __name__ == "__main__":