Spaces:
Runtime error
Runtime error
simonduerr
commited on
Commit
·
01918bc
1
Parent(s):
d07b01c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pyvis.network import Network
|
3 |
+
import networkx as nx
|
4 |
+
nx_graph = nx.cycle_graph(10)
|
5 |
+
nx_graph.nodes[1]['title'] = 'Number 1'
|
6 |
+
nx_graph.nodes[1]['group'] = 1
|
7 |
+
nx_graph.nodes[3]['title'] = 'I belong to a different group!'
|
8 |
+
nx_graph.nodes[3]['group'] = 10
|
9 |
+
nx_graph.add_node(20, size=20, title='couple', group=2)
|
10 |
+
nx_graph.add_node(21, size=15, title='couple', group=2)
|
11 |
+
nx_graph.add_edge(20, 21, weight=5)
|
12 |
+
nx_graph.add_node(25, size=25, label='lonely', title='lonely node', group=3)
|
13 |
+
|
14 |
+
# graph above refer to: https://pyvis.readthedocs.io/en/latest/tutorial.html#networkx-integration
|
15 |
+
|
16 |
+
# nt_notebook = Network('500px', '500px', notebook=True, cdn_resources='remote')
|
17 |
+
# populates the nodes and edges data structures
|
18 |
+
# nt_notebook.from_nx(nx_graph)
|
19 |
+
# nt_notebook.show('nx.html')
|
20 |
+
|
21 |
+
|
22 |
+
def needs_analysis():
|
23 |
+
nt = Network()
|
24 |
+
nt.from_nx(nx_graph)
|
25 |
+
html = nt.generate_html()
|
26 |
+
print(html)
|
27 |
+
return html
|
28 |
+
|
29 |
+
|
30 |
+
demo = gr.Interface(
|
31 |
+
needs_analysis,
|
32 |
+
inputs=None,
|
33 |
+
outputs=gr.outputs.HTML(),
|
34 |
+
title="pyvis_in_gradio",
|
35 |
+
allow_flagging='never'
|
36 |
+
)
|
37 |
+
|
38 |
+
demo.launch()
|