# 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() from transformers import pipeline import gradio as gr from PIL import Image # Load the pretrained model pipeline classifier = pipeline("image-classification", model="sherab65/age-classification") # Prediction function def predict(input_img): predictions = classifier(input_img) # Format predictions result = {p["label"]: p["score"] for p in predictions} top_labels = [f"{label}: {score:.2f}" for label, score in result.items()] return input_img, "\n".join(top_labels) # Create Gradio interface gradio_app = gr.Interface( fn=predict, inputs=gr.Image(label="Select Image", sources=["upload", "webcam"], type="pil"), outputs=[ gr.Image(label="Uploaded Image"), gr.Textbox(label="Predicted Age Group(s)") ], title="Age Classification using Hugging Face Model", description="Upload or capture an image to classify the person's age group." ) # Launch the app gradio_app.launch()