Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,76 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Placeholder function for Wikipedia content fetching
|
6 |
# You'll need to replace this with actual fetching logic
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
from PIL import Image
|
4 |
+
import json
|
5 |
+
from datetime import datetime, timedelta
|
6 |
+
|
7 |
+
# File to store click history and last update timestamp
|
8 |
+
HISTORY_FILE = 'click_history.json'
|
9 |
+
|
10 |
+
# Initialize or load click history and last update time
|
11 |
+
def init_click_history():
|
12 |
+
if os.path.exists(HISTORY_FILE):
|
13 |
+
with open(HISTORY_FILE, 'r') as file:
|
14 |
+
return json.load(file)
|
15 |
+
else:
|
16 |
+
# Initialize with all buttons set to zero clicks and current time
|
17 |
+
return {"click_counts": {button: 0 for button in all_buttons}, "last_update": datetime.now().isoformat()}
|
18 |
+
|
19 |
+
# Save click history and last update time
|
20 |
+
def save_click_history(history):
|
21 |
+
with open(HISTORY_FILE, 'w') as file:
|
22 |
+
json.dump(history, file)
|
23 |
+
|
24 |
+
# Update click count for a button and save history
|
25 |
+
def update_click_count(button_name):
|
26 |
+
history = init_click_history()
|
27 |
+
history["click_counts"][button_name] += 1
|
28 |
+
history["last_update"] = datetime.now().isoformat()
|
29 |
+
save_click_history(history)
|
30 |
+
st.experimental_rerun()
|
31 |
+
|
32 |
+
# Display buttons and handle clicks
|
33 |
+
def display_buttons():
|
34 |
+
columns = st.columns(3)
|
35 |
+
for i, category in enumerate(categories):
|
36 |
+
with columns[i % 3]:
|
37 |
+
st.markdown(f"### {category['name']}")
|
38 |
+
for button in category['buttons']:
|
39 |
+
if st.button(button["text"]):
|
40 |
+
update_click_count(button["text"])
|
41 |
+
|
42 |
+
# Calculate time since last update
|
43 |
+
def time_since_last_update():
|
44 |
+
history = init_click_history()
|
45 |
+
last_update = datetime.fromisoformat(history["last_update"])
|
46 |
+
now = datetime.now()
|
47 |
+
return int((now - last_update).total_seconds())
|
48 |
+
|
49 |
+
# Main categories and buttons
|
50 |
+
categories = [
|
51 |
+
{"name": "Inputs", "buttons": [{"text": "๐ Text"}, {"text": "๐ Read"}, {"text": "๐ท Photo"}, {"text": "๐ผ๏ธ View"}, {"text": "๐๏ธ Record"}, {"text": "๐ง Listen"}, {"text": "๐ฅ Video"}, {"text": "๐น Capture"}]},
|
52 |
+
{"name": "Outputs", "buttons": [{"text": "๐ฌ Chat"}, {"text": "โ๏ธ Write"}, {"text": "๐จ Art"}, {"text": "๐ Create"}, {"text": "๐ต Music"}, {"text": "๐ถ Compose"}, {"text": "๐ผ Watch"}, {"text": "๐ฟ Movies"}]},
|
53 |
+
{"name": "Health", "buttons": [{"text": "๐ Vaccinate"}, {"text": "๐ฉบ Diagnose"}, {"text": "๐ฅ Hospital"}, {"text": "๐ Emergency"}, {"text": "๐ Meds"}, {"text": "๐ฉน Bandage"}, {"text": "๐งฌ DNA"}, {"text": "๐ฌ Research"}, {"text": "๐ก๏ธ Temperature"}, {"text": "๐ Nutrition"}]},
|
54 |
+
{"name": "Learning", "buttons": [{"text": "๐ Study"}, {"text": "๐ง Brain"}, {"text": "๐ฉโ๐ Graduate"}, {"text": "๐ Measure"}, {"text": "๐ Search"}, {"text": "๐ Analyze"}, {"text": "๐ Plan"}, {"text": "๐๏ธ Write"}, {"text": "๐จโ๐ซ Teach"}, {"text": "๐งฉ Puzzle"}]},
|
55 |
+
{"name": "AI", "buttons": [{"text": "๐ค Robot"}, {"text": "๐พ Game"}, {"text": "๐ป Code"}, {"text": "๐งฎ Calculate"}, {"text": "๐ก Connect"}, {"text": "๐ Power"}, {"text": "๐น๏ธ Play"}, {"text": "๐ฅ๏ธ Display"}, {"text": "๐งโ๐ป Develop"}, {"text": "๐จโ๐ฌ Experiment"}]},
|
56 |
+
{"name": "Writing", "buttons": [{"text": "โ๏ธ Author"}, {"text": "๐ Note"}, {"text": "๐๏ธ Pen"}, {"text": "๐๏ธ Sign"}, {"text": "๐ Library"}, {"text": "๐ Bookmark"}, {"text": "๐ Journal"}, {"text": "โ๏ธ Ink"}, {"text": "๐ Scroll"}]},
|
57 |
+
]
|
58 |
+
|
59 |
+
all_buttons = [button["text"] for category in categories for button in category["buttons"]]
|
60 |
+
|
61 |
+
# App title
|
62 |
+
st.markdown("# Remixable!!\n## Classifications")
|
63 |
+
|
64 |
+
# Display all buttons
|
65 |
+
display_buttons()
|
66 |
+
|
67 |
+
# Show time since last update
|
68 |
+
seconds_since_update = time_since_last_update()
|
69 |
+
st.write(f"๐ Time since last update: {seconds_since_update} seconds")
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
|
75 |
# Placeholder function for Wikipedia content fetching
|
76 |
# You'll need to replace this with actual fetching logic
|