File size: 709 Bytes
8399b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load model - HF Spaces handles the caching automatically
print("Loading MobileNet...")
classifier = pipeline(
    "image-classification", 
    model="google/mobilenet_v2_1.0_224"
)

def classify_image(img):
    try:
        results = classifier(img)
        return {result['label']: float(result['score']) for result in results}
    except Exception as e:
        return {"Error": str(e)}

demo = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=5),
    title="📱 MobileNet Classifier",
    description="Fast, lightweight image classification running on Hugging Face Spaces."
)

demo.launch()