RamaManna's picture
Create app.py
dd2d15b verified
raw
history blame contribute delete
657 Bytes
import gradio as gr
from transformers import pipeline
# Load a pre-trained image classification model from Hugging Face
model = pipeline("image-classification", model="google/vit-base-patch16-224")
# Define the prediction function
def classify_image(image):
predictions = model(image)
return {pred["label"]: pred["score"] for pred in predictions}
# Gradio Interface
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=5),
title="Image Recognition AI",
description="Upload an image to classify it using a pre-trained model from Hugging Face."
)
# Launch the app
demo.launch()