-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
123 lines (99 loc) · 3.93 KB
/
app.py
1
2
3
4
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
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
import streamlit as st
from src.graph_utils import Graph
from src.types import GraphType
def form_callback():
"""
Handle form validation logic
"""
if st.session_state["uploaded_file"] is None:
st.warning("Please upload a file.")
return
if st.session_state["graph_type"] is None:
st.warning("Please select a graph type.")
return
# create graph from file
G = Graph(
graph_type=st.session_state["graph_type"],
input=st.session_state["uploaded_file"],
motif_size=st.session_state["motif_size"],
)
# display graph properties
graph_properties = G.get_graph_properties()
st.write(f"Number of nodes: {graph_properties['Number of nodes']}")
# st.write(f"Edges: {graph_properties['Edges']}")
st.write(f"Number of edges: {graph_properties['Number of edges']}")
st.write(f"Weight: {graph_properties['Weight']}")
# write labels
G.print_labelg()
# visualize the full graph if selected
if st.session_state["is_visualize_graph"]:
st.markdown("### Full Graph Visualization")
G.draw_graph()
# Visualize subgraphs if selected
if st.session_state["is_visualize_subgraph"]:
st.markdown("### Subgraph Visualization")
G.draw_subgraph(st.session_state["motif_size"])
G.generate_random_graphs(2)
def main():
# Initialize global session state for user form submission
if "graph_type" not in st.session_state:
st.session_state["graph_type"] = None
if "uploaded_file" not in st.session_state:
st.session_state["uploaded_file"] = None
if "prev_uploaded_file" not in st.session_state:
st.session_state["prev_uploaded_file"] = None
uploaded_file = st.file_uploader("Upload a file")
if uploaded_file:
if uploaded_file != st.session_state["prev_uploaded_file"]:
st.session_state["uploaded_file"] = uploaded_file
st.session_state["prev_uploaded_file"] = uploaded_file
st.toast("Succesfully uploaded file", icon="✅")
with st.form(key="form"):
col1, col2 = st.columns([1, 3])
with col1:
graph_type = st.radio(
"Set Graph type:",
key="graph",
index=None,
options=[GraphType.DIRECTED, GraphType.UNDIRECTED],
format_func=lambda x: x.value,
)
motif_size = st.number_input(
"Size of motif",
value=3,
placeholder="Input motif size...",
min_value=1,
max_value=5,
)
nemo_count_type = st.radio(
"Nemo Data Options",
key="nemo_option",
index=None,
options=["NemoCount", "NemoProfile", "NemoCollect"],
)
with col2:
st.write(
"NOTE: Uploading more than 1000 nodes might consume more processing time."
)
st.write("Visualize Options:")
is_visualize_graph = st.checkbox("Visualize graph")
is_visualize_subgraph = st.checkbox("Visualize subgraph")
submitted = st.form_submit_button(label="Submit")
if submitted:
st.session_state["is_visualize_graph"] = False
st.session_state["is_visualize_subgraph"] = False
if is_visualize_graph:
st.session_state["is_visualize_graph"] = True
if is_visualize_subgraph:
st.session_state["is_visualize_subgraph"] = True
st.session_state["graph_type"] = graph_type
st.session_state["uploaded_file"] = uploaded_file
st.session_state["motif_size"] = motif_size
st.session_state["nemo_count_option"] = nemo_count_type
form_callback()
"""
[![Repo](https://badgen.net/badge/icon/GitHub?icon=github&label)](https://github.com/hanpham32/NetMotif)
"""
st.markdown("<br>", unsafe_allow_html=True)
if __name__ == "__main__":
main()