Age-Detection / app.py
Shanmukhcr7's picture
Upload folder using huggingface_hub
7bc725d verified
Raw
History Blame Contribute Delete
995 Bytes
import gradio as gr
from age_service import AgeService
import numpy as np
# Initialize the AgeService
service = AgeService()
def predict_age(image):
if image is None:
return "Please upload an image."
# Perform prediction
result = service.detect_and_predict(image)
if result and result.get("error"):
return f"Error: {result['error']}"
elif result:
return f"Predicted Age: {result['age']}\nAge Group: {result['age_group']}\nConfidence: {result['confidence']}"
else:
return "An unknown error occurred."
# Create the Gradio interface
iface = gr.Interface(
fn=predict_age,
inputs=gr.Image(label="Upload Image"),
outputs=gr.Text(label="Prediction Result"),
title="Age Prediction Model",
description="Upload an image containing a face to predict the person's age. This model uses a custom-trained ResNet18 and an OpenCV face detector.",
allow_flagging="never"
)
if __name__ == "__main__":
iface.launch()