File size: 828 Bytes
ae3733a 4ef606f ae3733a f690417 ae3733a f690417 ae3733a f690417 ae3733a ea824f4 f690417 a9bf139 |
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 26 27 28 29 |
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)
|