Schrodingers commited on
Commit
3977c7b
1 Parent(s): 0a08c3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -1,7 +1,35 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import watershed # Your Python bindings module
5
 
6
+ def segment_image(input_image):
7
+ # Convert the image received from Gradio into a format suitable for our C++ function
8
+ is_success, im_buf_arr = cv2.imencode(".jpg", input_image)
9
+ byte_im = im_buf_arr.tobytes()
10
 
11
+ # You can save this to a file or directly pass it if your C++ function can handle byte streams
12
+ with open("temp_input.jpg", "wb") as f:
13
+ f.write(byte_im)
14
+
15
+ # Call the C++ watershed_segmentation function
16
+ watershed.watershed_segmentation("temp_input.jpg", "output.jpg")
17
+
18
+ # Read the output image to display in Gradio
19
+ output_img = cv2.imread("output.jpg")
20
+
21
+ # Convert from BGR (OpenCV format) to RGB (for displaying in Gradio)
22
+ output_img = cv2.cvtColor(output_img, cv2.COLOR_BGR2RGB)
23
+ return output_img
24
+
25
+ # Define Gradio interface
26
+ interface = gr.Interface(
27
+ fn=segment_image,
28
+ inputs=gr.inputs.Image(type="numpy", label="Input Image"),
29
+ outputs=gr.outputs.Image(type="numpy", label="Segmented Image"),
30
+ live=True,
31
+ title="Watershed Image Segmentation",
32
+ description="Upload an image for watershed segmentation."
33
+ )
34
+
35
+ interface.launch()