awacke1's picture
Update app.py
5a5d4d3
raw
history blame
2.36 kB
import streamlit as st
import time
import random
# Define the list of themes and nodes
themes = {
"Theme 1": ["Node 1.1", "Node 1.2", "Node 1.3", "Node 1.4", "Node 1.5", "Node 1.6", "Node 1.7", "Node 1.8", "Node 1.9", "Node 1.10"],
"Theme 2": ["Node 2.1", "Node 2.2", "Node 2.3", "Node 2.4", "Node 2.5", "Node 2.6", "Node 2.7", "Node 2.8", "Node 2.9", "Node 2.10"],
"Theme 3": ["Node 3.1", "Node 3.2", "Node 3.3", "Node 3.4", "Node 3.5", "Node 3.6", "Node 3.7", "Node 3.8", "Node 3.9", "Node 3.10"],
"Theme 4": ["Node 4.1", "Node 4.2", "Node 4.3", "Node 4.4", "Node 4.5", "Node 4.6", "Node 4.7", "Node 4.8", "Node 4.9", "Node 4.10"],
"Theme 5": ["Node 5.1", "Node 5.2", "Node 5.3", "Node 5.4", "Node 5.5", "Node 5.6", "Node 5.7", "Node 5.8", "Node 5.9", "Node 5.10"],
}
# Define emojis for top 1 through 10
emojis = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]
def spinning_model(theme, nodes, emojis):
output = ""
for i, node in enumerate(nodes):
output += f"{emojis[i]} {node} "
st.markdown(f"### {theme}\n{output}")
st.write("---")
def random_timer(countdown):
while countdown > 0:
st.write(f"Next refresh in {countdown} seconds.")
time.sleep(1)
countdown -= 1
return random.sample(range(1, 11), 10)
st.title("Spinning Model Visualization")
st.write("Select themes to display the spinning model and adjust the number of seconds before the next refresh.")
# Add input widgets for the five themes and refresh interval
theme_1 = st.text_input("Theme 1:", "Theme 1")
theme_2 = st.text_input("Theme 2:", "Theme 2")
theme_3 = st.text_input("Theme 3:", "Theme 3")
theme_4 = st.text_input("Theme 4:", "Theme 4")
theme_5 = st.text_input("Theme 5:", "Theme 5")
refresh_interval = st.slider("Refresh interval (in seconds):",1, 10, 5)
selected_themes = [themes.get(theme, []) for theme in [theme_1, theme_2, theme_3, theme_4, theme_5]]
i = 0
while True:
# Get the selected theme and shuffle the nodes
selected_theme = selected_themes[i]
random.shuffle(selected_theme)
spinning_model(f"Theme {i+1}", selected_theme, emojis)
selected_theme = random_timer(refresh_interval)
# Increment the index and loop back to the first theme if all themes have been shown
i = (i + 1) % 5
if i == 0:
st.write("---")