Mazhar Mohsin
Initial commit
851fba8
import gradio as gr
from transformers import pipeline
# Initialize the image classification pipeline
classifier = pipeline("image-classification")
# Alternatively you can define what model should the pipeline use, sometimes it requires that you login with your token
#classifier = pipeline("image-classification", model="microsoft/resnet-50")
#print(classifier.model)
def classify_image(image):
results = classifier(image)
# Get the top prediction
top_result = results[0]
label = top_result['label']
score = top_result['score']
return f"Label: {label}, Confidence: {score:.2f}"
iface = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil", label="Upload an Image"),
outputs=gr.Textbox(label="Prediction"),
title="Image Classifier"
)
iface.launch()