Spaces:
Build error
Build error
Commit ·
0c5d83d
1
Parent(s): 20372b6
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,28 +8,20 @@ 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 |
-
def format_output(output):
|
| 14 |
-
formatted_output = ""
|
| 15 |
-
for idx, pred in enumerate(output):
|
| 16 |
-
formatted_output += f"{idx}: Score: {pred['score']}, Label: {pred['label']}\n"
|
| 17 |
-
return formatted_output
|
| 18 |
|
| 19 |
description = """
|
| 20 |
"""
|
| 21 |
|
| 22 |
-
|
| 23 |
fn=predict,
|
| 24 |
inputs=[
|
| 25 |
-
gr.
|
|
|
|
| 26 |
],
|
| 27 |
-
outputs=
|
| 28 |
-
title="
|
| 29 |
description=description
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# Apply custom formatting to the JSON output
|
| 33 |
-
iface.output_formatter = format_output
|
| 34 |
|
| 35 |
-
iface.launch()
|
|
|
|
| 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 |
+
label = gr.Label(output_format="json", default_value=preds)
|
| 12 |
+
return label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
description = """
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
gr.Interface(
|
| 18 |
fn=predict,
|
| 19 |
inputs=[
|
| 20 |
+
gr.components.Image(label="Image to classify", type="pil"),
|
| 21 |
+
# gr.inputs.Textbox(lines=1, label="Comma separated candidate labels", placeholder="Enter labels separated by ', '",)
|
| 22 |
],
|
| 23 |
+
outputs="label",
|
| 24 |
+
title="Comparateur d'image",
|
| 25 |
description=description
|
| 26 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
| 27 |
|
|
|