FDSRashid commited on
Commit
aa7a63c
·
1 Parent(s): e5ef6f4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #need to remove ' from HTML
27
+ html = html.replace("'", "\"")
28
+
29
+ return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
30
+ display-capture; encrypted-media;" sandbox="allow-modals allow-forms
31
+ allow-scripts allow-same-origin allow-popups
32
+ allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
33
+ allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>"""
34
+
35
+
36
+ demo = gr.Interface(
37
+ needs_analysis,
38
+ inputs=None,
39
+ outputs=gr.outputs.HTML(),
40
+ title="pyvis_in_gradio",
41
+ allow_flagging='never'
42
+ )
43
+
44
+ demo.launch()