Spaces:
Runtime error
Runtime error
Commit
•
a6a05ca
1
Parent(s):
19e8bfb
Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
if 0 <= nx < w and 0 <= ny < h:
|
30 |
-
new_dist = curr_dist + edge_costs[ny, nx]
|
31 |
-
if new_dist < distances[ny, nx]:
|
32 |
-
distances[ny, nx] = new_dist
|
33 |
-
heapq.heappush(pq, (new_dist, (nx, ny)))
|
34 |
-
|
35 |
-
# Backtrack to find path from end to start
|
36 |
-
path = []
|
37 |
-
curr_point = end_point
|
38 |
-
while curr_point != start_point:
|
39 |
-
x, y = curr_point
|
40 |
-
path.append(curr_point)
|
41 |
-
min_dist = distances[y, x]
|
42 |
-
for dx in [-1, 0, 1]:
|
43 |
-
for dy in [-1, 0, 1]:
|
44 |
-
nx, ny = x + dx, y + dy
|
45 |
-
if 0 <= nx < w and 0 <= ny < h and distances[ny, nx] < min_dist:
|
46 |
-
min_dist = distances[ny, nx]
|
47 |
-
curr_point = (nx, ny)
|
48 |
-
path.append(start_point)
|
49 |
-
|
50 |
-
return path
|
51 |
-
|
52 |
-
def segment_image(image, points):
|
53 |
-
edge_costs = compute_edge_costs(image)
|
54 |
-
|
55 |
-
start_point = tuple(map(int, points[0]))
|
56 |
-
end_point = tuple(map(int, points[-1]))
|
57 |
-
|
58 |
-
path = dijkstra(edge_costs, start_point, end_point)
|
59 |
-
|
60 |
-
mask = np.zeros_like(image)
|
61 |
-
for x, y in path:
|
62 |
-
cv2.circle(mask, (x, y), 2, (0, 255, 0), -1)
|
63 |
-
return mask
|
64 |
-
|
65 |
-
interface = gr.Interface(
|
66 |
-
segment_image,
|
67 |
-
inputs=[gr.inputs.Image(shape=(200, 200)), gr.inputs.Drawing(label="Draw Seed Points or Paths")],
|
68 |
-
outputs=gr.outputs.Image(shape=(200, 200)),
|
69 |
-
live=True
|
70 |
-
)
|
71 |
-
|
72 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
+
from flask import Flask, render_template
|
5 |
+
|
6 |
+
# A placeholder function; Actual LiveWire code would be much more involved
|
7 |
+
def live_wire_segmentation(image, points):
|
8 |
+
# This is a placeholder. Implement actual live wire segmentation here.
|
9 |
+
return image
|
10 |
+
|
11 |
+
def main_app():
|
12 |
+
interface = gr.Interface(
|
13 |
+
fn=live_wire_segmentation,
|
14 |
+
inputs=["image", gr.inputs.Sketchpad()], # You may have to adjust this for latest version of Gradio
|
15 |
+
outputs="image",
|
16 |
+
live=True
|
17 |
+
)
|
18 |
+
interface.launch()
|
19 |
+
|
20 |
+
app = Flask(__name__)
|
21 |
+
|
22 |
+
@app.route('/')
|
23 |
+
def index():
|
24 |
+
main_app()
|
25 |
+
return "Gradio App Running!"
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|