Spaces:
Build error
Build error
Commit ·
d156a39
1
Parent(s): 22bc2c2
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,11 @@ import torch
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 6 |
-
|
| 7 |
def predict(image):
|
| 8 |
classifier = pipeline(task="image-classification")
|
| 9 |
preds = classifier(image)
|
| 10 |
return {pred["label"]: round(float(pred["score"]), 4) for pred in preds}
|
| 11 |
|
| 12 |
-
def clear_interface():
|
| 13 |
-
interface.inputs[0].clear()
|
| 14 |
-
interface.outputs[0].clear()
|
| 15 |
|
| 16 |
description = """
|
| 17 |
"""
|
|
@@ -23,10 +18,7 @@ interface = gr.Interface(
|
|
| 23 |
],
|
| 24 |
outputs=gr.outputs.Label(),
|
| 25 |
title="Image Classifier",
|
| 26 |
-
description=description
|
| 27 |
-
buttons=[
|
| 28 |
-
gr.Button(label="Clear", callback=clear_interface)
|
| 29 |
-
]
|
| 30 |
)
|
| 31 |
|
| 32 |
interface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
|
|
|
| 5 |
def predict(image):
|
| 6 |
classifier = pipeline(task="image-classification")
|
| 7 |
preds = classifier(image)
|
| 8 |
return {pred["label"]: round(float(pred["score"]), 4) for pred in preds}
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
description = """
|
| 12 |
"""
|
|
|
|
| 18 |
],
|
| 19 |
outputs=gr.outputs.Label(),
|
| 20 |
title="Image Classifier",
|
| 21 |
+
description=description
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
interface.launch()
|