Alex Gonzalez commited on
Commit ·
4fb5c0d
1
Parent(s): 45d0b3b
Changed to use a Hugging Face Model
Browse files
app.py
CHANGED
|
@@ -1,14 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
|
|
|
| 3 |
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
learn_inf = load_learner("export.pkl")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def predict(value) -> str:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
with gr.Row():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 4 |
|
| 5 |
from PIL import Image
|
| 6 |
+
import requests
|
| 7 |
|
| 8 |
learn_inf = load_learner("export.pkl")
|
| 9 |
+
processor = AutoImageProcessor.from_pretrained("dima806/facial_emotions_image_detection")
|
| 10 |
+
model = AutoModelForImageClassification.from_pretrained("dima806/facial_emotions_image_detection")
|
| 11 |
|
| 12 |
def predict(value) -> str:
|
| 13 |
+
img = Image.fromarray(value).convert('L')
|
| 14 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
logits = outputs.logits
|
| 17 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 18 |
+
return model.config.id2label[predicted_class_idx]
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
with gr.Row():
|