Spaces:
Build error
Build error
Commit
·
ea9eea4
1
Parent(s):
b30a1c0
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,13 +13,29 @@ def predict(image):
|
|
| 13 |
description = """
|
| 14 |
"""
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
fn=predict,
|
| 18 |
inputs=[
|
| 19 |
-
gr.
|
| 20 |
-
# gr.inputs.Textbox(lines=1, label="Comma separated candidate labels", placeholder="Enter labels separated by ', '",)
|
| 21 |
],
|
| 22 |
outputs=gr.outputs.JSON(),
|
| 23 |
-
title="
|
| 24 |
description=description
|
| 25 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
description = """
|
| 14 |
"""
|
| 15 |
|
| 16 |
+
def format_output(output):
|
| 17 |
+
# Format the JSON output for better display
|
| 18 |
+
formatted_output = ""
|
| 19 |
+
for i, pred in enumerate(output):
|
| 20 |
+
formatted_output += f"{i}: {{\n"
|
| 21 |
+
formatted_output += f" score: {pred['score']},\n"
|
| 22 |
+
formatted_output += f" label: {pred['label']}\n"
|
| 23 |
+
formatted_output += "}\n"
|
| 24 |
+
return formatted_output
|
| 25 |
+
|
| 26 |
+
# Create the Gradio interface
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
fn=predict,
|
| 29 |
inputs=[
|
| 30 |
+
gr.inputs.Image(label="Image to classify", type="pil"),
|
|
|
|
| 31 |
],
|
| 32 |
outputs=gr.outputs.JSON(),
|
| 33 |
+
title="Image Classifier",
|
| 34 |
description=description
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Set the post-processing hook to format the output
|
| 38 |
+
iface.interface_output_postprocessing = format_output
|
| 39 |
+
|
| 40 |
+
# Launch the interface
|
| 41 |
+
iface.launch()
|