Spaces:
Runtime error
Runtime error
Download app.py from loomy18/emotiondetection: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/spaces/loomy18/emotiondetection/resolve/main/app.py
- Command line
-
hf download hf://spaces/loomy18/emotiondetection/app.py
-
curl -L -o app.py https://huggingface.co/spaces/loomy18/emotiondetection/resolve/main/app.py
922 Bytes
| from fastai.vision.all import * | |
| import gradio as gr | |
| def is_cat(x): | |
| return x[0].isupper() | |
| # Error handling for model loading | |
| try: | |
| learn = load_learner('emotion.pkl') | |
| except FileNotFoundError: | |
| print("Error: Model file 'emotion.pkl' not found.") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"Error loading the model: {e}") | |
| sys.exit(1) | |
| categories = ('angry person', 'happy person', 'neutral emotion person') | |
| def classify_image(img): | |
| # Error handling for prediction | |
| try: | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| except Exception as e: | |
| return {"error": f"Prediction error: {e}"} | |
| image = gr.Image(height=192, width=192) | |
| label = gr.Label() | |
| examples = ['angry.jpg', 'happy.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch(inline=False) |