Spaces:
Sleeping
Sleeping
File size: 1,065 Bytes
ba5fb94 85358ed ba5fb94 85358ed 7242fab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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()
|