-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
111 lines (92 loc) · 3.31 KB
/
app.py
File metadata and controls
111 lines (92 loc) · 3.31 KB
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
import time
import streamlit as st
from diff2gif import Diff2GIF
from helpers import (
handle_topology_parameters,
handle_model_parameters,
generate_synth_graph,
)
def slow_type(text, placeholder, slp=0.01):
"""type a string slowly in a placeholder"""
for i in range(len(text) + 1):
placeholder.write(text[:i])
time.sleep(slp)
st.title("Diff2GIF")
st.markdown(
"##### Create your own animated network visualization by exploiting a diffusion model!"
)
towrite = """Diff2GIF is a tool that allows you to create animated network visualizations by exploiting a diffusion
model. Here you can choose a network topology and a diffusion model, and then generate a GIF animation of the
resulting diffusion process. \n This tool is based on the *NDLIB* Python library, which provides a high-level
abstraction layer for modeling, simulating, and analyzing diffusion processes on complex networks. \n For more
information on the diffusion models, please refer to the [official documentation](
https://ndlib.readthedocs.io/en/latest/index.html)"""
st.markdown(towrite)
col1, col2 = st.columns(2, gap="large")
with col1:
st.subheader("Topology")
graph_model, num_nodes, graph_parameters = handle_topology_parameters()
with col2:
st.subheader("Model")
model_method, model_config = handle_model_parameters()
col3, col4 = st.columns(2, gap="large")
with col3:
n_iters = st.slider(
"Number of iterations", min_value=10, max_value=100, value=30, step=10
)
with col4:
ms = st.slider(
"Animation speed (ms)", min_value=50, max_value=1000, value=100, step=50
)
if st.button("Run"):
placeholder = st.empty()
slow_type("Generating Network... :hourglass:", placeholder)
graph, pos = generate_synth_graph(graph_model, num_nodes, **graph_parameters)
slow_type("Running Model... :hourglass:", placeholder)
model = model_method(graph)
model.set_initial_status(model_config)
class Params:
model = model
n_iters = n_iters
pos = pos
d2g = Diff2GIF(graph, Params)
slow_type(
"Generating GIF (this may take a while :face_with_rolling_eyes:)...",
placeholder,
)
d2g.make("generated.gif", ms)
# display
slow_type("Displaying GIF...:sunglasses:", placeholder)
st.image("generated.gif")
slow_type("Done! :tada: download your GIF below :point_down:", placeholder)
# download
with open("generated.gif", "rb") as file:
btn = st.download_button(label="Download GIF", data=file, mime="image/gif")
footer = """<style>
a:link , a:visited{
color: blue;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color: red;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: white;
color: black;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with ❤ by <a href="https://linktr.ee/andreafailla" target="_blank">Andrea Failla</a>.
<br>Powered by <img src="https://user-images.githubusercontent.com/7164864/217935870-c0bc60a3-6fc0-4047-b011-7b4c59488c91.png" style="width:40px;height:18px;">
and <img src="https://raw.githubusercontent.com/GiulioRossetti/ndlib/master/docs/ndlogo2.png" style="width:40px;height:18px;"></p>
</div>
"""
st.markdown(footer, unsafe_allow_html=True)