Antoine245 commited on
Commit
3ab5bd0
·
1 Parent(s): ea9eea4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -10,32 +10,26 @@ def predict(image):
10
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
11
  return preds
12
 
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()
 
10
  preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
11
  return preds
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
  iface = gr.Interface(
23
  fn=predict,
24
  inputs=[
25
+ gr.components.Image(label="Image to classify", type="pil"),
26
  ],
27
  outputs=gr.outputs.JSON(),
28
  title="Image Classifier",
29
  description=description
30
  )
31
 
32
+ # Apply custom formatting to the JSON output
33
+ iface.outputs[0].format = format_output
34
 
 
35
  iface.launch()