Ahmadkhan12 commited on
Commit
93e10cb
·
verified ·
1 Parent(s): 4bec973

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -44,4 +44,32 @@ def predict_emotion_onnx(model, image_input):
44
  input_name = model.get_inputs()[0].name
45
  output_name = model.get_outputs()[0].name
46
  # Run the model
47
- prediction = model.run([out
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  input_name = model.get_inputs()[0].name
45
  output_name = model.get_outputs()[0].name
46
  # Run the model
47
+ prediction = model.run([output_name], {input_name: image_input})
48
+ return prediction[0]
49
+
50
+ # Streamlit UI
51
+ st.title("Emotion Detection")
52
+
53
+ # Upload an image
54
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
55
+
56
+ if uploaded_file is not None:
57
+ # Open and display the uploaded image
58
+ image = Image.open(uploaded_file)
59
+ st.image(image, caption="Uploaded Image", use_column_width=True)
60
+
61
+ # Load model
62
+ onnx_model = load_model()
63
+
64
+ # Preprocess the image
65
+ image_input = preprocess_image(image)
66
+
67
+ # Get emotion prediction
68
+ emotion_prediction = predict_emotion_onnx(onnx_model, image_input)
69
+
70
+ # Get the emotion label and confidence
71
+ emotion_label, confidence = get_emotion_from_output(emotion_prediction)
72
+
73
+ # Display the predicted emotion and confidence
74
+ st.write(f"Predicted Emotion: {emotion_label}")
75
+ st.write(f"Confidence: {confidence:.2f}")