S1-1IVAM commited on
Commit
676453d
·
verified ·
1 Parent(s): 2470c24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -1,10 +1,11 @@
1
- # Updated app.py for Gradio Space with text output
2
  import gradio as gr
3
  import subprocess
4
  from pathlib import Path
5
  import os
6
  from PIL import Image
7
  import json
 
8
 
9
  # ROOT directory (root of your space)
10
  ROOT_DIR = Path(__file__).parent
@@ -27,8 +28,12 @@ def detect_image(image):
27
  input_path = ROOT_DIR / "temp_input.jpg"
28
  image.save(input_path)
29
 
 
 
 
 
 
30
  # Run YOLOv5 detect.py via subprocess
31
- # Add --save-txt to save detection results
32
  cmd = [
33
  "python", str(YOLO_DETECT),
34
  "--weights", str(WEIGHTS),
 
1
+ # Updated app.py for Gradio Space with text output (fixed stale detection issue)
2
  import gradio as gr
3
  import subprocess
4
  from pathlib import Path
5
  import os
6
  from PIL import Image
7
  import json
8
+ import shutil
9
 
10
  # ROOT directory (root of your space)
11
  ROOT_DIR = Path(__file__).parent
 
28
  input_path = ROOT_DIR / "temp_input.jpg"
29
  image.save(input_path)
30
 
31
+ # Clean old detection results before running new detection
32
+ output_dir = OUTPUT_PROJECT / OUTPUT_NAME
33
+ if output_dir.exists():
34
+ shutil.rmtree(output_dir)
35
+
36
  # Run YOLOv5 detect.py via subprocess
 
37
  cmd = [
38
  "python", str(YOLO_DETECT),
39
  "--weights", str(WEIGHTS),