Spaces:
Sleeping
Sleeping
File size: 886 Bytes
f0d3c3f 6bf59e6 21508c7 20d3cc5 f0d3c3f c85436f b628b61 6bf59e6 b628b61 6bf59e6 | 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 30 31 |
# Install required packages
# !pip install transformers
# !pip install streamlit
!pip install torch
!pip install datasets gradio
import gradio as gr
from transformers import pipeline
# Load a pre-trained image classification pipeline 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}
# Set up the Gradio interface
interface = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil"),
outputs=gr.JSON(), # Updated to JSON for dictionary-like output
title="Image Classification App",
description="Upload an image, and the app will classify it using a Vision Transformer (ViT) model."
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|