Spaces:
Sleeping
Sleeping
Commit
·
2c92669
1
Parent(s):
dfc2140
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
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,7 +9,9 @@ def predict(image):
|
|
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 |
-
|
|
|
|
|
12 |
|
13 |
description = """
|
14 |
"""
|
@@ -18,7 +21,7 @@ gr.Interface(
|
|
18 |
inputs=[
|
19 |
gr.inputs.Image(label="Image to classify", type="pil"),
|
20 |
],
|
21 |
-
outputs=
|
22 |
title="Comparateur d'image",
|
23 |
description=description
|
24 |
).launch()
|
|
|
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 |
classifier = pipeline(task="image-classification")
|
10 |
preds = classifier(image)
|
11 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
12 |
+
prediction_json = json.dumps(preds)
|
13 |
+
prediction_dict = json.loads(prediction_json)
|
14 |
+
return prediction_dict
|
15 |
|
16 |
description = """
|
17 |
"""
|
|
|
21 |
inputs=[
|
22 |
gr.inputs.Image(label="Image to classify", type="pil"),
|
23 |
],
|
24 |
+
outputs="label",
|
25 |
title="Comparateur d'image",
|
26 |
description=description
|
27 |
).launch()
|