|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
model_id = "sayakpaul/resnet-50-finetuned-imagenet" |
|
|
|
def analyze_image(image): |
|
classifier = pipeline("image-classification", model=model_id) |
|
predictions = classifier(images=image) |
|
|
|
top_class = predictions[0]["label"] |
|
top_prob = predictions[0]["score"] |
|
return f"Top Class: {top_class} (Probability: {top_prob:.2f})" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=analyze_image, |
|
inputs="image", |
|
outputs="text", |
|
title="Image Analyzer (Generic)", |
|
description="Upload an image and get the most likely classification based on the chosen model.", |
|
) |
|
|
|
interface.launch() |
|
|