import gradio as gr from transformers import pipeline from PIL import Image # Load image classification pipeline classifier = pipeline( task="image-classification", model="google/vit-base-patch16-224" ) def classify_image(image): if image is None: return "No image provided." # Convert to PIL Image if needed if not isinstance(image, Image.Image): image = Image.fromarray(image) results = classifier(image) return {r["label"]: r["score"] for r in results} # Gradio interface app = gr.Interface( fn=classify_image, inputs=gr.Image(type="pil", label="Upload an Animal Image"), outputs=gr.Label(label="Prediction"), title="Animal Image Classification", description="Upload an image of an animal and the model will predict what it is." ) if __name__ == "__main__": app.launch()