Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,53 +101,63 @@ def save_votes(votes):
|
|
101 |
def main():
|
102 |
st.set_page_config(layout="wide")
|
103 |
|
104 |
-
if
|
105 |
-
st.session_state.
|
106 |
|
107 |
votes = load_votes()
|
108 |
|
109 |
col1, col2 = st.columns([1, 2])
|
110 |
|
111 |
with col1:
|
112 |
-
items = [
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
items.sort(key=lambda x: (-x["votes"], x["name"]))
|
116 |
|
117 |
button_cols = st.columns(2)
|
118 |
for i, item in enumerate(items):
|
119 |
with button_cols[i % 2]:
|
120 |
-
if st.button(f"{item['emoji']} {item['name']}", key=item[
|
121 |
-
votes[item[
|
122 |
save_votes(votes)
|
123 |
-
st.session_state.
|
124 |
-
st.
|
125 |
st.write(f"Votes: {item['votes']}")
|
126 |
|
127 |
with col2:
|
128 |
-
if st.session_state.
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
141 |
else:
|
142 |
-
st.info("Select
|
143 |
|
144 |
if any(votes.values()):
|
145 |
with col1:
|
146 |
-
df = pd.DataFrame(
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
151 |
|
152 |
if __name__ == "__main__":
|
153 |
-
main()
|
|
|
101 |
def main():
|
102 |
st.set_page_config(layout="wide")
|
103 |
|
104 |
+
if "selected_url" not in st.session_state:
|
105 |
+
st.session_state.selected_url = None
|
106 |
|
107 |
votes = load_votes()
|
108 |
|
109 |
col1, col2 = st.columns([1, 2])
|
110 |
|
111 |
with col1:
|
112 |
+
items = [
|
113 |
+
{
|
114 |
+
"url": url,
|
115 |
+
"name": url.split("/")[-1],
|
116 |
+
"emoji": get_emoji(url.split("/")[-1]),
|
117 |
+
"votes": votes[url],
|
118 |
+
}
|
119 |
+
for url in urls
|
120 |
+
]
|
121 |
items.sort(key=lambda x: (-x["votes"], x["name"]))
|
122 |
|
123 |
button_cols = st.columns(2)
|
124 |
for i, item in enumerate(items):
|
125 |
with button_cols[i % 2]:
|
126 |
+
if st.button(f"{item['emoji']} {item['name']}", key=item["url"]):
|
127 |
+
votes[item["url"]] += 1
|
128 |
save_votes(votes)
|
129 |
+
st.session_state.selected_url = item["url"]
|
130 |
+
st.experimental_rerun()
|
131 |
st.write(f"Votes: {item['votes']}")
|
132 |
|
133 |
with col2:
|
134 |
+
if "selected_url" in st.session_state and st.session_state.selected_url:
|
135 |
+
selected_url = st.session_state.selected_url
|
136 |
+
st.info(f"You selected: {selected_url}")
|
137 |
+
|
138 |
+
# Open the selected URL in a new browser tab or window
|
139 |
+
st.markdown(
|
140 |
+
f"""
|
141 |
+
<a href="{selected_url}" target="_blank" style="text-decoration: none;">
|
142 |
+
<button style="padding: 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer;">
|
143 |
+
Open in New Tab
|
144 |
+
</button>
|
145 |
+
</a>
|
146 |
+
""",
|
147 |
+
unsafe_allow_html=True,
|
148 |
+
)
|
149 |
else:
|
150 |
+
st.info("Select a space from the list on the left to view details.")
|
151 |
|
152 |
if any(votes.values()):
|
153 |
with col1:
|
154 |
+
df = pd.DataFrame(
|
155 |
+
[
|
156 |
+
{"name": i["name"], "votes": i["votes"]}
|
157 |
+
for i in items if votes[i["url"]] > 0
|
158 |
+
]
|
159 |
+
)
|
160 |
+
st.bar_chart(df.set_index("name"))
|
161 |
|
162 |
if __name__ == "__main__":
|
163 |
+
main()
|