Spaces:
Runtime error
Runtime error
Delete app.py
#2
by beshaksha - opened
app.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import tensorflow as tf
|
| 4 |
-
import numpy as np
|
| 5 |
-
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 6 |
-
|
| 7 |
-
# Load the trained model
|
| 8 |
-
model = tf.keras.models.load_model("my_model.h5")
|
| 9 |
-
|
| 10 |
-
# Class labels (modify according to your dataset)
|
| 11 |
-
class_labels = ["Angry", "Disgust", "Fear", "Happy", "Neutral", "Sad", "Surprise"]
|
| 12 |
-
|
| 13 |
-
# Function to make predictions
|
| 14 |
-
def predict_emotion(image):
|
| 15 |
-
# Resize image to match model's expected input
|
| 16 |
-
image = image.resize((224, 224))
|
| 17 |
-
img_array = img_to_array(image) / 255.0 # Normalize
|
| 18 |
-
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 19 |
-
|
| 20 |
-
# Make prediction
|
| 21 |
-
prediction = model.predict(img_array)
|
| 22 |
-
predicted_class = class_labels[np.argmax(prediction)]
|
| 23 |
-
confidence = np.max(prediction)
|
| 24 |
-
|
| 25 |
-
return f"Emotion: {predicted_class} (Confidence: {confidence:.2f})"
|
| 26 |
-
|
| 27 |
-
# Create Gradio interface
|
| 28 |
-
interface = gr.Interface(
|
| 29 |
-
fn=predict_emotion,
|
| 30 |
-
inputs=gr.Image(type="pil"),
|
| 31 |
-
outputs=gr.Textbox(label="Prediction"),
|
| 32 |
-
title="Facial Emotion Detection",
|
| 33 |
-
description="Upload an image, and the model will predict the emotion.",
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
# Run the app
|
| 37 |
-
if __name__ == "__main__":
|
| 38 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|