mariamhsein16's picture
Create app.py
fc5e76c verified
import gradio as gr
from transformers import pipeline
from PIL import Image
# Load the pipeline
pipe = pipeline(
"image-classification",
model="mariamhsein16/FacialExpressionDetection"
)
# Prediction function
def predict_expression(image):
if image is None:
return "Please upload an image."
results = pipe(image)
# Format results nicely
formatted_results = []
for r in results:
label = r["label"]
score = round(r["score"] * 100, 2)
formatted_results.append(f"{label}: {score}%")
return "\n".join(formatted_results)
# Gradio UI
with gr.Blocks(title="Facial Expression Detection") as demo:
gr.Markdown("## ๐Ÿ˜Š Facial Expression Detection")
gr.Markdown("Upload a face image to detect the facial expression.")
with gr.Row():
image_input = gr.Image(type="pil", label="Upload Image")
output_text = gr.Textbox(label="Predictions")
submit_btn = gr.Button("Detect Expression")
submit_btn.click(
fn=predict_expression,
inputs=image_input,
outputs=output_text
)
# Launch app
demo.launch()