Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"image-classification",
|
| 6 |
+
model="google/vit-base-patch16-224"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
def classify_image(image):
|
| 10 |
+
results = classifier(image)
|
| 11 |
+
|
| 12 |
+
output = ""
|
| 13 |
+
for item in results[:5]:
|
| 14 |
+
output += f"{item['label']} : {item['score']:.2%}\n"
|
| 15 |
+
|
| 16 |
+
return output
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=classify_image,
|
| 20 |
+
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs=gr.Textbox(label="Classification Results"),
|
| 22 |
+
title="Image Classification App",
|
| 23 |
+
description="Upload an image and let AI identify what it contains."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|