Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,26 @@
|
|
1 |
-
# Import necessary libraries
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Load a lightweight
|
6 |
-
model = pipeline("image-classification", model="facebook/deit-tiny-patch16-224"
|
7 |
|
8 |
-
# Function to classify an
|
9 |
def classify_image(image):
|
10 |
-
predictions = model(image)
|
11 |
-
# Format predictions as
|
12 |
return {pred["label"]: round(pred["score"], 4) for pred in predictions}
|
13 |
|
14 |
-
#
|
15 |
interface = gr.Interface(
|
16 |
-
fn=classify_image,
|
17 |
-
inputs=gr.Image(type="pil"),
|
18 |
-
outputs=gr.Label(),
|
19 |
-
title="Image
|
20 |
-
description="Upload an image
|
21 |
)
|
22 |
|
23 |
-
#
|
24 |
if __name__ == "__main__":
|
25 |
interface.launch()
|
26 |
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Load a lightweight pre-trained model without specifying cache_dir
|
5 |
+
model = pipeline("image-classification", model="facebook/deit-tiny-patch16-224")
|
6 |
|
7 |
+
# Function to classify an image
|
8 |
def classify_image(image):
|
9 |
+
predictions = model(image)
|
10 |
+
# Format predictions as {label: confidence}
|
11 |
return {pred["label"]: round(pred["score"], 4) for pred in predictions}
|
12 |
|
13 |
+
# Gradio interface
|
14 |
interface = gr.Interface(
|
15 |
+
fn=classify_image,
|
16 |
+
inputs=gr.Image(type="pil"),
|
17 |
+
outputs=gr.Label(),
|
18 |
+
title="Image Classifier Test",
|
19 |
+
description="Upload an image to classify."
|
20 |
)
|
21 |
|
22 |
+
# Launch the app
|
23 |
if __name__ == "__main__":
|
24 |
interface.launch()
|
25 |
|
26 |
+
|