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