Spaces:
Sleeping
Sleeping
Commit
·
329e771
1
Parent(s):
88b429a
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
import json
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -9,9 +8,7 @@ def predict(image):
|
|
| 9 |
classifier = pipeline(task="image-classification")
|
| 10 |
preds = classifier(image)
|
| 11 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
| 12 |
-
|
| 13 |
-
prediction_dict = json.loads(prediction_json)
|
| 14 |
-
return prediction_dict
|
| 15 |
|
| 16 |
description = """
|
| 17 |
"""
|
|
@@ -21,7 +18,7 @@ gr.Interface(
|
|
| 21 |
inputs=[
|
| 22 |
gr.inputs.Image(label="Image to classify", type="pil"),
|
| 23 |
],
|
| 24 |
-
outputs=
|
| 25 |
-
title="
|
| 26 |
description=description
|
| 27 |
).launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 8 |
classifier = pipeline(task="image-classification")
|
| 9 |
preds = classifier(image)
|
| 10 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
| 11 |
+
return [pred["label"] for pred in preds] # Return a list of labels only
|
|
|
|
|
|
|
| 12 |
|
| 13 |
description = """
|
| 14 |
"""
|
|
|
|
| 18 |
inputs=[
|
| 19 |
gr.inputs.Image(label="Image to classify", type="pil"),
|
| 20 |
],
|
| 21 |
+
outputs=gr.outputs.Label(), # Use Label output instead of JSON
|
| 22 |
+
title="Image Classifier",
|
| 23 |
description=description
|
| 24 |
).launch()
|