File size: 699 Bytes
c331809 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Use a pipeline as a high-level helper
from transformers import pipeline
import gradio as gr
image_processor = pipeline("image-classification", model="google/vit-base-patch16-224")
# Define a Gradio function for classification
def classify_image(image):
# Use the image_classification pipeline to classify the image
result = image_processor(image)
# Return the class label and confidence score
return result[0]["label"], round(result[0]["score"], 4)
# Create a Gradio interface
interface = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil"),
outputs="text",
live=True,
title="Image Classification",
)
# Start the Gradio interface
interface.launch() |