File size: 814 Bytes
c592663
99f44fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()