Spaces:
Sleeping
Sleeping
Download app.py from YanagiKp/midetector: direct link, hf CLI and curl.
- Browser
- Download file 625 Bytes
-
https://huggingface.co/spaces/YanagiKp/midetector/resolve/main/app.py
- Command line
-
hf download hf://spaces/YanagiKp/midetector/app.py
-
curl -L -o app.py https://huggingface.co/spaces/YanagiKp/midetector/resolve/main/app.py
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() | |