File size: 1,882 Bytes
967a22b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85358ed
 
 
 
 
 
967a22b
 
85358ed
967a22b
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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()

import gradio as gr
from PIL import Image

# Prediction function
def predict(input_img):
    # Get the predictions from the pipeline
    predictions = classifier(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",
)

gradio_app.launch()