Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def image_classifier(image):
|
5 |
+
classifier = pipeline("image-classification", model="dupthotshering/bhutanese-textile-model")
|
6 |
+
results = classifier(image)
|
7 |
+
|
8 |
+
# Convert results into a dictionary with class names as keys
|
9 |
+
formatted_results = {result['label']: result['score'] for result in results}
|
10 |
+
return formatted_results
|
11 |
+
|
12 |
+
# Define Gradio interface
|
13 |
+
demo = gr.Interface(
|
14 |
+
fn=image_classifier,
|
15 |
+
inputs=gr.Image(type="pil"), # Ensure input is an image
|
16 |
+
outputs=gr.Label(num_top_classes=7), # Display all class scores
|
17 |
+
title="Bhutanese Textile Classifier",
|
18 |
+
description="Upload an image to classify it into one of the Bhutanese textile categories."
|
19 |
+
)
|
20 |
+
|
21 |
+
demo.launch()
|