Spaces:
Runtime error

loomy18's picture
test
177c0ef
Raw History Blame Contribute Delete
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)