AMontiB commited on
Commit
ee73b8f
Β·
1 Parent(s): 0b6865a

fix: replace gr.JSON with gr.Code to avoid schema parsing bug

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -19,7 +19,7 @@ DETECTORS = ['R50_TF', 'R50_nodown', 'CLIP-D', 'P2G', 'NPR']
19
 
20
  def predict(image_path, detector_name):
21
  if not image_path:
22
- return {"error": "Please upload an image."}
23
 
24
  # Create a temporary output file path
25
  output_path = "temp_result.json"
@@ -52,18 +52,22 @@ def predict(image_path, detector_name):
52
  confidence = result.get('confidence', 0.0)
53
  elapsed_time = result.get('elapsed_time', 0.0)
54
 
55
- return {
56
  "Prediction": prediction,
57
  "Confidence": f"{confidence:.4f}",
58
  "Elapsed Time": f"{elapsed_time:.3f}s"
59
  }
 
60
  else:
61
- return {"error": "No result file generated. Check console logs for details."}
62
 
63
  except FileNotFoundError as e:
64
- return {"error": str(e), "message": f"Please ensure you have downloaded the weights for {detector_name}."}
 
 
 
65
  except Exception as e:
66
- return {"error": str(e)}
67
  finally:
68
  # Cleanup
69
  if os.path.exists(output_path):
@@ -95,7 +99,7 @@ with gr.Blocks(title="Deepfake Detection", theme=gr.themes.Soft()) as demo:
95
  submit_btn = gr.Button("πŸ” Detect", variant="primary")
96
 
97
  with gr.Column():
98
- output_json = gr.JSON(label="Detection Results")
99
 
100
  gr.Markdown("""
101
  ---
@@ -109,7 +113,7 @@ with gr.Blocks(title="Deepfake Detection", theme=gr.themes.Soft()) as demo:
109
  submit_btn.click(
110
  fn=predict,
111
  inputs=[image_input, detector_input],
112
- outputs=output_json
113
  )
114
 
115
  if __name__ == "__main__":
 
19
 
20
  def predict(image_path, detector_name):
21
  if not image_path:
22
+ return json.dumps({"error": "Please upload an image."}, indent=2)
23
 
24
  # Create a temporary output file path
25
  output_path = "temp_result.json"
 
52
  confidence = result.get('confidence', 0.0)
53
  elapsed_time = result.get('elapsed_time', 0.0)
54
 
55
+ output = {
56
  "Prediction": prediction,
57
  "Confidence": f"{confidence:.4f}",
58
  "Elapsed Time": f"{elapsed_time:.3f}s"
59
  }
60
+ return json.dumps(output, indent=2)
61
  else:
62
+ return json.dumps({"error": "No result file generated. Check console logs for details."}, indent=2)
63
 
64
  except FileNotFoundError as e:
65
+ return json.dumps({
66
+ "error": str(e),
67
+ "message": f"Please ensure you have downloaded the weights for {detector_name}."
68
+ }, indent=2)
69
  except Exception as e:
70
+ return json.dumps({"error": str(e)}, indent=2)
71
  finally:
72
  # Cleanup
73
  if os.path.exists(output_path):
 
99
  submit_btn = gr.Button("πŸ” Detect", variant="primary")
100
 
101
  with gr.Column():
102
+ output_display = gr.Code(label="Detection Results", language="json", lines=10)
103
 
104
  gr.Markdown("""
105
  ---
 
113
  submit_btn.click(
114
  fn=predict,
115
  inputs=[image_input, detector_input],
116
+ outputs=output_display
117
  )
118
 
119
  if __name__ == "__main__":