File size: 722 Bytes
b02261d
 
 
04a150f
 
b02261d
04a150f
b02261d
04a150f
 
91a2209
b02261d
04a150f
b02261d
04a150f
 
 
 
 
b02261d
 
04a150f
b02261d
445540d
 
987e96a
91a2209
04a150f
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
import gradio as gr

# Load a lightweight pre-trained model without specifying cache_dir
model = pipeline("image-classification", model="facebook/deit-tiny-patch16-224")

# Function to classify an image
def classify_image(image):
    predictions = model(image)
    # Format predictions as {label: confidence}
    return {pred["label"]: round(pred["score"], 4) for pred in predictions}

# Gradio interface
interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(),
    title="Image Classifier Test",
    description="Upload an image to classify."
)

# Launch the app
if __name__ == "__main__":
    interface.launch(server_name="0.0.0.0")