Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model - HF Spaces handles the caching automatically
|
| 5 |
+
print("Loading MobileNet...")
|
| 6 |
+
classifier = pipeline(
|
| 7 |
+
"image-classification",
|
| 8 |
+
model="google/mobilenet_v2_1.0_224"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def classify_image(img):
|
| 12 |
+
try:
|
| 13 |
+
results = classifier(img)
|
| 14 |
+
return {result['label']: float(result['score']) for result in results}
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return {"Error": str(e)}
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=classify_image,
|
| 20 |
+
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs=gr.Label(num_top_classes=5),
|
| 22 |
+
title="📱 MobileNet Classifier",
|
| 23 |
+
description="Fast, lightweight image classification running on Hugging Face Spaces."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|