Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -59,17 +59,22 @@ def emo_preprocess(image):
|
|
59 |
|
60 |
# Inference function
|
61 |
def predict_emotion(image):
|
62 |
-
image
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
with torch.no_grad():
|
66 |
-
outputs = model(
|
67 |
predicted = outputs.argmax(1).item()
|
68 |
|
69 |
emotion = idx2label[predicted]
|
70 |
emoji = emotion_emoji.get(emotion, "❓") # Default to "?" if no emoji found
|
71 |
return f"{emotion} {emoji}"
|
72 |
-
|
73 |
# Create Gradio interface
|
74 |
iface = gr.Interface(
|
75 |
fn=predict_emotion,
|
|
|
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 |
|
70 |
with torch.no_grad():
|
71 |
+
outputs = model(img)
|
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 |
# Create Gradio interface
|
79 |
iface = gr.Interface(
|
80 |
fn=predict_emotion,
|