Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Prediction function
|
6 |
+
def predict(input_img):
|
7 |
+
# Get the predictions from the pipeline
|
8 |
+
predictions = pipe(input_img)
|
9 |
+
|
10 |
+
result = {p["label"]: p["score"] for p in predictions}
|
11 |
+
|
12 |
+
# Return the image and the top predictions as a string
|
13 |
+
top_labels = [f"{label}: {score:.2f}" for label, score in result.items()]
|
14 |
+
return input_img, "\n".join(top_labels)
|
15 |
+
|
16 |
+
# Create the Gradio interface
|
17 |
+
gradio_app = gr.Interface(
|
18 |
+
fn=predict,
|
19 |
+
inputs=gr.Image(label="Select Image", sources=['upload', 'webcam'], type="pil"),
|
20 |
+
outputs=[
|
21 |
+
gr.Image(label="Processed Image"),
|
22 |
+
gr.Textbox(label="Result", placeholder="Top predictions here")
|
23 |
+
],
|
24 |
+
title="Age Classification",
|
25 |
+
description="Upload or capture an image to classify age using the SigLIP2 model."
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the app
|
29 |
+
gradio_app.launch()
|
30 |
+
|
31 |
+
|
32 |
+
if _name=="main_":
|
33 |
+
gradio_app.launch()
|