DGurgurov's picture
Update app.py
ae3733a verified
raw
history blame
828 Bytes
from transformers import pipeline
# Define the pipeline for image classification
pipe = pipeline("image-classification", model="DGurgurov/clip-vit-base-patch32-oxford-pets")
# Define the predict function using the pipeline
def predict(image):
# Perform inference using the pipeline
results = pipe(image)
return {f"Class {i}": result['label'] for i, result in enumerate(results)}
# Now you can use this predict function in your Gradio interface
import gradio as gr
# Define Gradio interface
image = gr.components.Image()
label = gr.components.Label(num_top_classes=5)
interface = gr.Interface(
fn=predict,
inputs=image,
outputs=label,
title="CLIP Model - Oxford Pets",
description="Upload an image and get the top 5 class predictions."
)
# Launch the Gradio app
interface.launch(share=True)