Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load the pipeline for age classification
|
| 6 |
+
pipe = pipeline("image-classification", model="prithivMLmods/Age-Classification-SigLIP2")
|
| 7 |
+
|
| 8 |
+
# Define the prediction function
|
| 9 |
+
def predict(input_img):
|
| 10 |
+
# Get the predictions
|
| 11 |
+
predictions = pipe(input_img)
|
| 12 |
+
# Format the predictions into a human-readable string
|
| 13 |
+
result_str = "\n".join([f"{p['label']}: {p['score']:.4f}" for p in predictions])
|
| 14 |
+
return result_str
|
| 15 |
+
|
| 16 |
+
# Create a Gradio interface
|
| 17 |
+
iface = gr.Interface(fn=predict,
|
| 18 |
+
inputs=gr.Image(type="pil"), # Define input type as an image
|
| 19 |
+
outputs=gr.Textbox(label="Class Confidence Scores", interactive=False), # Output as plain text
|
| 20 |
+
) # Set live=True to update results as soon as the image is uploaded
|
| 21 |
+
|
| 22 |
+
# Launch the Gradio app
|
| 23 |
+
iface.launch()
|