VDNT11 commited on
Commit
564b428
·
verified ·
1 Parent(s): 1f1cbf5

Update angle_detection_app.py

Browse files
Files changed (1) hide show
  1. angle_detection_app.py +24 -32
angle_detection_app.py CHANGED
@@ -78,6 +78,9 @@ def process_image(
78
  """
79
  Process the image and return the visualization and angle measurements.
80
  """
 
 
 
81
  if isinstance(image, dict):
82
  image = image['image']
83
  if isinstance(image, str):
@@ -109,39 +112,28 @@ def process_image(
109
  return result_img, measurements
110
 
111
  def create_gradio_interface():
112
- with gr.Blocks(title="Angle Detection App", theme=gr.themes.Soft()) as interface:
113
- gr.Markdown("# Angle Detection App")
114
- gr.Markdown("Upload an image to detect bends and measure angles.")
115
-
116
- with gr.Row():
117
- with gr.Column():
118
- input_image = gr.Image(label="Input Image", type="numpy")
119
-
120
- with gr.Accordion("Algorithm Parameters", open=False):
121
- blur_kernel_size = gr.Slider(minimum=3, maximum=15, step=2, value=7, label="Blur Kernel Size")
122
- canny_threshold1 = gr.Slider(minimum=0, maximum=100, step=10, value=30, label="Canny Threshold 1")
123
- canny_threshold2 = gr.Slider(minimum=100, maximum=300, step=10, value=150, label="Canny Threshold 2")
124
- dilation_kernel_size = gr.Slider(minimum=1, maximum=5, step=1, value=2, label="Dilation Kernel Size")
125
- hough_threshold = gr.Slider(minimum=10, maximum=100, step=10, value=50, label="Hough Threshold")
126
- min_line_length = gr.Slider(minimum=5, maximum=50, step=5, value=10, label="Minimum Line Length")
127
- max_line_gap = gr.Slider(minimum=10, maximum=100, step=10, value=60, label="Maximum Line Gap")
128
- bend_threshold = gr.Slider(minimum=5, maximum=30, step=5, value=15, label="Bend Threshold")
129
-
130
- process_btn = gr.Button("Process Image", variant="primary")
131
-
132
- with gr.Column():
133
- output_image = gr.Image(label="Result")
134
- output_text = gr.Textbox(label="Measurements", lines=10)
135
-
136
- process_btn.click(
137
- fn=process_image,
138
- inputs=[input_image, blur_kernel_size, canny_threshold1, canny_threshold2, dilation_kernel_size,
139
- hough_threshold, min_line_length, max_line_gap, bend_threshold],
140
- outputs=[output_image, output_text]
141
- )
142
-
143
  return interface
144
 
145
  if __name__ == "__main__":
146
  interface = create_gradio_interface()
147
- interface.launch(share=False) # Set share=False to avoid issues when deploying
 
78
  """
79
  Process the image and return the visualization and angle measurements.
80
  """
81
+ if image is None:
82
+ return None, "Please upload an image."
83
+
84
  if isinstance(image, dict):
85
  image = image['image']
86
  if isinstance(image, str):
 
112
  return result_img, measurements
113
 
114
  def create_gradio_interface():
115
+ interface = gr.Interface(
116
+ fn=process_image,
117
+ inputs=[
118
+ gr.Image(label="Input Image", type="numpy"),
119
+ gr.Slider(minimum=3, maximum=15, step=2, value=7, label="Blur Kernel Size"),
120
+ gr.Slider(minimum=0, maximum=100, step=10, value=30, label="Canny Threshold 1"),
121
+ gr.Slider(minimum=100, maximum=300, step=10, value=150, label="Canny Threshold 2"),
122
+ gr.Slider(minimum=1, maximum=5, step=1, value=2, label="Dilation Kernel Size"),
123
+ gr.Slider(minimum=10, maximum=100, step=10, value=50, label="Hough Threshold"),
124
+ gr.Slider(minimum=5, maximum=50, step=5, value=10, label="Minimum Line Length"),
125
+ gr.Slider(minimum=10, maximum=100, step=10, value=60, label="Maximum Line Gap"),
126
+ gr.Slider(minimum=5, maximum=30, step=5, value=15, label="Bend Threshold")
127
+ ],
128
+ outputs=[
129
+ gr.Image(label="Result"),
130
+ gr.Textbox(label="Measurements", lines=10)
131
+ ],
132
+ title="Angle Detection App",
133
+ description="Upload an image to detect bends and measure angles. Adjust parameters as needed."
134
+ )
 
 
 
 
 
 
 
 
 
 
 
135
  return interface
136
 
137
  if __name__ == "__main__":
138
  interface = create_gradio_interface()
139
+ interface.launch(share=True)