midetector / app.py
YanagiKp's picture
Update app.py
2a5ebb4 verified
Raw History Blame Contribute Delete
625 Bytes
import gradio as gr
from transformers import pipeline
import base64
from PIL import Image
import io
model = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
def predict_emotion(image_b64: str):
image_data = base64.b64decode(image_b64.split(",")[1] if "," in image_b64 else image_b64)
image = Image.open(io.BytesIO(image_data)).convert("RGB")
predictions = model(image)
return [[{"label": p["label"], "score": p["score"]} for p in predictions]]
demo = gr.Interface(
fn=predict_emotion,
inputs=gr.Textbox(),
outputs="json",
api_name="predict"
)
demo.launch()