Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -121,5 +121,56 @@ for url, name, emoji in zip(urls, url_names, url_emojis):
|
|
121 |
# Display the number of times the URL was opened below its corresponding button
|
122 |
st.write(f"Clicked: {history[url]} times")
|
123 |
|
|
|
|
|
|
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
|
|
121 |
# Display the number of times the URL was opened below its corresponding button
|
122 |
st.write(f"Clicked: {history[url]} times")
|
123 |
|
124 |
+
import time
|
125 |
+
from bokeh.plotting import figure
|
126 |
+
from bokeh.models import ColumnDataSource
|
127 |
|
128 |
+
# ... [rest of the initial code remains unchanged] ...
|
129 |
+
|
130 |
+
# Streamlit app
|
131 |
+
def main():
|
132 |
+
|
133 |
+
# Session state to hold the value of AutoRepeat button across reruns
|
134 |
+
if "auto_repeat" not in st.session_state:
|
135 |
+
st.session_state.auto_repeat = "On"
|
136 |
+
if "current_index" not in st.session_state:
|
137 |
+
st.session_state.current_index = 0 # Use 0 as a default index
|
138 |
+
|
139 |
+
# Load the history of clicks
|
140 |
+
history = load_history()
|
141 |
+
|
142 |
+
# Display the buttons for each URL
|
143 |
+
for url, name, emoji in zip(urls, url_names, url_emojis):
|
144 |
+
if st.button(f"{emoji} {name}"):
|
145 |
+
# Open the URL in a new browser tab using JavaScript
|
146 |
+
st.write('<script>window.open("'+url+'", "_blank");</script>', unsafe_allow_html=True)
|
147 |
+
# Update the history of clicks
|
148 |
+
history[url] += 1
|
149 |
+
save_history(history)
|
150 |
+
# Display the number of times the URL was opened below its corresponding button
|
151 |
+
st.write(f"Clicked: {history[url]} times")
|
152 |
+
|
153 |
+
# Timer logic
|
154 |
+
if st.session_state.auto_repeat == "On":
|
155 |
+
timer_placeholder = st.empty()
|
156 |
+
for i in range(10, 0, -1):
|
157 |
+
timer_placeholder.text(f"Reloading in {i} seconds...")
|
158 |
+
time.sleep(1)
|
159 |
+
history = load_history() # Reload the history after the countdown
|
160 |
+
|
161 |
+
# Display the Bokeh graph showing the click counts
|
162 |
+
non_zero_urls = [name for url, name in zip(urls, url_names) if history[url] > 0]
|
163 |
+
non_zero_counts = [history[url] for url in urls if history[url] > 0]
|
164 |
+
|
165 |
+
source = ColumnDataSource(data=dict(urls=non_zero_urls, counts=non_zero_counts))
|
166 |
+
|
167 |
+
p = figure(x_range=non_zero_urls, plot_height=350, title="Click Counts per URL",
|
168 |
+
toolbar_location=None, tools="")
|
169 |
+
p.vbar(x='urls', top='counts', width=0.9, source=source)
|
170 |
+
p.xaxis.major_label_orientation = 1.2
|
171 |
+
|
172 |
+
st.bokeh_chart(p)
|
173 |
+
|
174 |
+
if __name__ == "__main__":
|
175 |
+
main()
|
176 |
|