File size: 886 Bytes
a233a7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import pipeline
from PIL import Image

# Load the pipeline for age classification
pipe = pipeline("image-classification", model="prithivMLmods/Age-Classification-SigLIP2")

# Define the prediction function
def predict(input_img):
    # Get the predictions
    predictions = pipe(input_img)
    # Format the predictions into a human-readable string
    result_str = "\n".join([f"{p['label']}: {p['score']:.4f}" for p in predictions])
    return result_str

# Create a Gradio interface
iface = gr.Interface(fn=predict,
                     inputs=gr.Image(type="pil"),  # Define input type as an image
                     outputs=gr.Textbox(label="Class Confidence Scores", interactive=False),  # Output as plain text
                     )  # Set live=True to update results as soon as the image is uploaded

# Launch the Gradio app
iface.launch()