Update app.py
Browse files
app.py
CHANGED
@@ -1,127 +1,63 @@
|
|
1 |
-
|
2 |
-
# import igraph as ig
|
3 |
-
# import plotly.graph_objects as go
|
4 |
-
|
5 |
-
# def create_plotly_tree():
|
6 |
-
# # Create an igraph tree
|
7 |
-
# g = ig.Graph.Tree(7, 2) # Example tree
|
8 |
-
# lay = g.layout('rt') # Reingold-Tilford layout
|
9 |
-
|
10 |
-
# # Plotly setup
|
11 |
-
# edge_x = []
|
12 |
-
# edge_y = []
|
13 |
-
# for edge in g.get_edgelist():
|
14 |
-
# x0, y0 = lay[edge[0]]
|
15 |
-
# x1, y1 = lay[edge[1]]
|
16 |
-
# edge_x.extend([x0, x1, None])
|
17 |
-
# edge_y.extend([y0, y1, None])
|
18 |
-
|
19 |
-
# edge_trace = go.Scatter(
|
20 |
-
# x=edge_x, y=edge_y,
|
21 |
-
# line=dict(width=0.5, color='#888'),
|
22 |
-
# hoverinfo='none',
|
23 |
-
# mode='lines')
|
24 |
-
|
25 |
-
# node_x = [lay[k][0] for k in range(len(lay))]
|
26 |
-
# node_y = [lay[k][1] for k in range(len(lay))]
|
27 |
-
|
28 |
-
# node_trace = go.Scatter(
|
29 |
-
# x=node_x, y=node_y,
|
30 |
-
# mode='markers',
|
31 |
-
# hoverinfo='text',
|
32 |
-
# marker=dict(showscale=False, size=10, color='#850', line_width=2))
|
33 |
-
|
34 |
-
# fig = go.Figure(data=[edge_trace, node_trace],
|
35 |
-
# layout=go.Layout(
|
36 |
-
# showlegend=False,
|
37 |
-
# hovermode='closest',
|
38 |
-
# margin=dict(b=0, l=0, t=0, r=0),
|
39 |
-
# xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
40 |
-
# yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
41 |
-
# )
|
42 |
-
|
43 |
-
# return fig
|
44 |
-
|
45 |
-
# def setup_interface():
|
46 |
-
# iface = gr.Interface(
|
47 |
-
# fn=create_plotly_tree,
|
48 |
-
# inputs=[],
|
49 |
-
# outputs=gr.Plot(),
|
50 |
-
# title="Interactive Tree Visualization"
|
51 |
-
# )
|
52 |
-
# return iface
|
53 |
-
|
54 |
-
# # Launch the interface
|
55 |
-
# if __name__ == "__main__":
|
56 |
-
# iface = setup_interface()
|
57 |
-
# iface.launch()
|
58 |
-
|
59 |
-
# Import necessary libraries
|
60 |
-
import dash
|
61 |
-
from dash import html, dcc, Input, Output
|
62 |
-
import plotly.graph_objects as go
|
63 |
import igraph as ig
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
size=10,
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
)
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
)
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
# Run the app
|
125 |
-
if __name__ == '__main__':
|
126 |
-
app.run_server(debug=True)
|
127 |
-
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import igraph as ig
|
3 |
+
import plotly.graph_objects as go
|
4 |
|
5 |
+
def create_plotly_tree():
|
6 |
+
# Create an igraph tree
|
7 |
+
g = ig.Graph.Tree(7, 2) # Example tree
|
8 |
+
lay = g.layout('rt') # Reingold-Tilford layout
|
9 |
+
|
10 |
+
# Plotly setup
|
11 |
+
edge_x = []
|
12 |
+
edge_y = []
|
13 |
+
for edge in g.get_edgelist():
|
14 |
+
x0, y0 = lay[edge[0]]
|
15 |
+
x1, y1 = lay[edge[1]]
|
16 |
+
edge_x.extend([x0, x1, None])
|
17 |
+
edge_y.extend([y0, y1, None])
|
18 |
+
|
19 |
+
edge_trace = go.Scatter(
|
20 |
+
x=edge_x, y=edge_y,
|
21 |
+
line=dict(width=0.5, color='#888'),
|
22 |
+
hoverinfo='none',
|
23 |
+
mode='lines')
|
24 |
+
|
25 |
+
node_x = [lay[k][0] for k in range(len(lay))]
|
26 |
+
node_y = [lay[k][1] for k in range(len(lay))]
|
27 |
+
|
28 |
+
node_trace = go.Scatter(
|
29 |
+
x=node_x, y=node_y,
|
30 |
+
mode='markers',
|
31 |
+
hoverinfo='text',
|
32 |
+
marker=dict(showscale=False, size=10, color='#850', line_width=2))
|
33 |
+
|
34 |
+
fig = go.Figure(data=[edge_trace, node_trace],
|
35 |
+
layout=go.Layout(
|
36 |
+
showlegend=False,
|
37 |
+
hovermode='closest',
|
38 |
+
margin=dict(b=0, l=0, t=0, r=0),
|
39 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
40 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
41 |
+
)
|
42 |
+
|
43 |
+
return fig
|
44 |
+
|
45 |
+
def setup_interface():
|
46 |
+
iface = gr.Interface(
|
47 |
+
fn=create_plotly_tree,
|
48 |
+
inputs=[],
|
49 |
+
outputs=gr.Plot(),
|
50 |
+
title="Interactive Tree Visualization"
|
51 |
+
)
|
52 |
+
return iface
|
53 |
+
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
with gr.Column():
|
56 |
+
tree_interface = setup_interface()
|
57 |
+
textbox = gr.Textbox()
|
58 |
+
|
59 |
+
# Launch the interface
|
60 |
+
if __name__ == "__main__":
|
61 |
+
# iface = setup_interface()
|
62 |
+
# iface.launch()
|
63 |
+
demo.launch()
|
|
|
|
|
|
|
|