MBase / app.py
MNGames's picture
Update app.py
99f44fe verified
raw
history blame
814 Bytes
import gradio as gr
from transformers import pipeline
# Replace with a suitable image classification model ID
model_id = "sayakpaul/resnet-50-finetuned-imagenet"
def analyze_image(image):
classifier = pipeline("image-classification", model=model_id)
predictions = classifier(images=image) # Assuming the model outputs probabilities
# Extract the most likely class and its probability
top_class = predictions[0]["label"]
top_prob = predictions[0]["score"]
return f"Top Class: {top_class} (Probability: {top_prob:.2f})"
# Gradio interface
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()