cxeep commited on
Commit
aeea734
·
verified ·
1 Parent(s): f84b5cd

Update gradio.app.py

Browse files
Files changed (1) hide show
  1. gradio.app.py +5 -28
gradio.app.py CHANGED
@@ -2,32 +2,9 @@ import gradio as gr
2
  import subprocess
3
  import os
4
 
5
- # Function to execute yolov5s-tt100k and return the output image path
6
- def run_yolov5s_tt100k(input_image_path):
7
- # Define the paths
8
- executable_path = "./build/yolov5s-tt100k"
9
- model_path = "./yolov5s_tt100k_opt_fp32.tmfile"
10
- output_image_path = "yolov5s-tt100k.out.jpg"
11
 
12
- # Run the yolov5s-tt100k executable with the input image
13
- subprocess.run([executable_path, "-m", model_path, "-i", input_image_path])
14
-
15
- # Check if the output image was created
16
- if os.path.exists(output_image_path):
17
- return output_image_path
18
- else:
19
- raise FileNotFoundError("The output image was not found.")
20
-
21
- # Create a Gradio interface
22
- iface = gr.Interface(
23
- fn=run_yolov5s_tt100k,
24
- inputs=gr.components.Image(),
25
- outputs=gr.components.Image(),
26
- title="YOLOv5s-TT100K Object Detection",
27
- description="Upload an image to run object detection using YOLOv5s-TT100K.",
28
- flagging_dir="/tmp/flagged" # Set a writable directory for flagging
29
- )
30
-
31
- # Run the Gradio app
32
- if __name__ == "__main__":
33
- iface.launch()
 
2
  import subprocess
3
  import os
4
 
5
+ def run_yolov5s(image_filepath):
6
+ result = subprocess.run(["./yolov5s-tt100k", "-m", "./yolov5s_tt100k_opt_fp32.tmfile", "-i", image_filepath], capture_output=True, text=True)
7
+ return "yolov5s-tt100k.out.jpg", result.stdout
 
 
 
8
 
9
+ iface = gr.Interface(fn=run_yolov5s, inputs=gr.Image(type="filepath"), outputs=[gr.Image(type="filepath"), gr.Textbox()])
10
+ iface.launch()