Spaces:
Running
Running
File size: 903 Bytes
cf64e05 0de6eb2 cf64e05 0de6eb2 cf64e05 0de6eb2 cf64e05 0de6eb2 cf64e05 0de6eb2 |
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 |
import gradio as gr
from transformers import pipeline
# Function for image classification
def classify(image, model_name):
try:
pipe = pipeline("image-classification", model=model_name)
results = pipe(image)
return {result["label"]: round(result["score"], 2) for result in results}
except Exception as e:
# Handle errors gracefully, e.g., invalid model names
return {"Error": str(e)}
# Gradio Interface
demo = gr.Interface(
fn=classify,
inputs=[
gr.Image(type="pil", label="Upload an Image"),
gr.Textbox(label="Enter timm Model Name", placeholder="e.g., timm/mobilenetv3_large_100.ra_in1k"),
],
outputs=gr.Label(num_top_classes=3, label="Top Predictions"),
title="Custom timm Model Image Classifier",
description="Enter a timm model name from Hugging Face, upload an image, and get predictions.",
)
demo.launch() |