Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
from PIL import Image | |
# Initialize the image classification pipeline with the specific model | |
pipe = pipeline("image-classification", model="prithivMLmods/Age-Classification-SigLIP2") | |
# Prediction function | |
def predict(input_img): | |
# Get the predictions from the pipeline | |
predictions = pipe(input_img) | |
result = {p["label"]: p["score"] for p in predictions} | |
# Return the image and the top predictions as a string | |
top_labels = [f"{label}: {score:.2f}" for label, score in result.items()] | |
return input_img, "\n".join(top_labels) | |
# Create the Gradio interface | |
gradio_app = gr.Interface( | |
fn=predict, | |
inputs=gr.Image(label="Select Image", sources=['upload', 'webcam'], type="pil"), | |
outputs=[ | |
gr.Image(label="Processed Image"), | |
gr.Textbox(label="Result", placeholder="Top predictions here") | |
], | |
title="Age Classification", | |
description="Upload or capture an image to classify age using the SigLIP2 model." | |
) | |
# Launch the app | |
gradio_app.launch() | |