Spaces:
Runtime error
Runtime error
Update backup1.app.py
Browse files- backup1.app.py +72 -4
backup1.app.py
CHANGED
@@ -1,10 +1,78 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
|
|
3 |
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
col1, col2, col3 = st.columns(3)
|
10 |
|
@@ -115,4 +183,4 @@ https://github.com/AaronCWacker/ThreeDragons
|
|
115 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/WLRKWqB6dKlMH6saVV9cX.png)
|
116 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/Lyazf6FuX4nH__4illVki.png)
|
117 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/ZemsxlT3b5idB0W5IjL1o.png)
|
118 |
-
''')
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
+
import json
|
4 |
from PIL import Image
|
5 |
|
6 |
+
|
7 |
+
# Directory to store scores
|
8 |
+
score_dir = "scores"
|
9 |
+
os.makedirs(score_dir, exist_ok=True)
|
10 |
+
|
11 |
+
# Function to generate a unique key for each button
|
12 |
+
def generate_key(label, header, idx):
|
13 |
+
return f"{header}_{label}_{idx}"
|
14 |
+
|
15 |
+
# Function to increment score and save it
|
16 |
+
def update_score(key, increment=1):
|
17 |
+
score_file = os.path.join(score_dir, f"{key}.json")
|
18 |
+
if os.path.exists(score_file):
|
19 |
+
with open(score_file, "r") as file:
|
20 |
+
score_data = json.load(file)
|
21 |
+
else:
|
22 |
+
score_data = {"clicks": 0, "score": 0}
|
23 |
+
|
24 |
+
score_data["clicks"] += 1
|
25 |
+
score_data["score"] += increment
|
26 |
+
|
27 |
+
with open(score_file, "w") as file:
|
28 |
+
json.dump(score_data, file)
|
29 |
+
|
30 |
+
return score_data["score"]
|
31 |
+
|
32 |
+
# Function to load score
|
33 |
+
def load_score(key):
|
34 |
+
score_file = os.path.join(score_dir, f"{key}.json")
|
35 |
+
if os.path.exists(score_file):
|
36 |
+
with open(score_file, "r") as file:
|
37 |
+
score_data = json.load(file)
|
38 |
+
return score_data["score"]
|
39 |
+
return 0
|
40 |
+
|
41 |
+
# Display headers and buttons with scores
|
42 |
+
def display_buttons_with_scores():
|
43 |
+
headers = ["Inputs", "Outputs", "Health", "Learning", "AI", "Writing"]
|
44 |
+
buttons = [
|
45 |
+
["๐ Text", "๐ Read", "๐ท Photo", "๐ผ๏ธ View", "๐๏ธ Record", "๐ง Listen", "๐ฅ Video", "๐น Capture"],
|
46 |
+
["๐ฌ Chat", "โ๏ธ Write", "๐จ Art", "๐ Create", "๐ต Music", "๐ถ Compose", "๐ผ Watch", "๐ฟ Movies"],
|
47 |
+
["๐ Vaccinate", "๐ฉบ Diagnose", "๐ฅ Hospital", "๐ Emergency", "๐ Meds", "๐ฉน Bandage", "๐งฌ DNA", "๐ฌ Research", "๐ก๏ธ Temperature", "๐ Nutrition"],
|
48 |
+
["๐ Study", "๐ง Brain", "๐ฉโ๐ Graduate", "๐ Measure", "๐ Search", "๐ Analyze", "๐ Plan", "๐๏ธ Write", "๐จโ๐ซ Teach", "๐งฉ Puzzle"],
|
49 |
+
["๐ค Robot", "๐พ Game", "๐ป Code", "๐งฎ Calculate", "๐ก Connect", "๐ Power", "๐น๏ธ Play", "๐ฅ๏ธ Display", "๐งโ๐ป Develop", "๐จโ๐ฌ Experiment"],
|
50 |
+
["โ๏ธ Author", "๐ Note", "๐๏ธ Pen", "๐๏ธ Sign", "๐ Library", "๐ Bookmark", "๐ Journal", "โ๏ธ Ink", "๐ Scroll"]
|
51 |
+
]
|
52 |
+
|
53 |
+
cols = st.columns(len(headers))
|
54 |
+
for idx, (col, header, buttons_list) in enumerate(zip(cols, headers, buttons)):
|
55 |
+
with col:
|
56 |
+
st.markdown(f"### {header}")
|
57 |
+
for button_idx, button_label in enumerate(buttons_list, start=1):
|
58 |
+
key = generate_key(button_label, header, button_idx)
|
59 |
+
score = load_score(key)
|
60 |
+
if st.button(f"{button_label} {score}", key=key):
|
61 |
+
new_score = update_score(key)
|
62 |
+
# Reload the page to reflect the updated score
|
63 |
+
st.experimental_rerun()
|
64 |
+
|
65 |
+
# Main application logic
|
66 |
+
if __name__ == "__main__":
|
67 |
+
st.markdown('# Remixable!')
|
68 |
+
display_buttons_with_scores()
|
69 |
+
|
70 |
+
# Additional content and functionality can go here
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
|
77 |
col1, col2, col3 = st.columns(3)
|
78 |
|
|
|
183 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/WLRKWqB6dKlMH6saVV9cX.png)
|
184 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/Lyazf6FuX4nH__4illVki.png)
|
185 |
![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/ZemsxlT3b5idB0W5IjL1o.png)
|
186 |
+
''')
|