ReMixable-AI-AR / app.py
awacke1's picture
Update app.py
d8ff977 verified
raw
history blame
2.92 kB
import streamlit as st
import os
import json
# Directory to store scores
score_dir = "scores"
os.makedirs(score_dir, exist_ok=True)
# Function to generate a unique key for each button
def generate_key(label, header, idx):
return f"{header}_{label}_{idx}"
# Function to increment score and save it
def update_score(key, increment=1):
score_file = os.path.join(score_dir, f"{key}.json")
if os.path.exists(score_file):
with open(score_file, "r") as file:
score_data = json.load(file)
else:
score_data = {"clicks": 0, "score": 0}
score_data["clicks"] += 1
score_data["score"] += increment
with open(score_file, "w") as file:
json.dump(score_data, file)
return score_data["score"]
# Function to load score
def load_score(key):
score_file = os.path.join(score_dir, f"{key}.json")
if os.path.exists(score_file):
with open(score_file, "r") as file:
score_data = json.load(file)
return score_data["score"]
return 0
# Display headers and buttons with scores
def display_buttons_with_scores():
headers = ["Inputs", "Outputs", "Health", "Learning", "AI", "Writing"]
buttons = [
["๐Ÿ“ Text", "๐Ÿ“– Read", "๐Ÿ“ท Photo", "๐Ÿ–ผ๏ธ View", "๐ŸŽ™๏ธ Record", "๐ŸŽง Listen", "๐ŸŽฅ Video", "๐Ÿ“น Capture"],
["๐Ÿ’ฌ Chat", "โœ๏ธ Write", "๐ŸŽจ Art", "๐ŸŒ„ Create", "๐ŸŽต Music", "๐ŸŽถ Compose", "๐Ÿ“ผ Watch", "๐Ÿฟ Movies"],
["๐Ÿ’‰ Vaccinate", "๐Ÿฉบ Diagnose", "๐Ÿฅ Hospital", "๐Ÿš‘ Emergency", "๐Ÿ’Š Meds", "๐Ÿฉน Bandage", "๐Ÿงฌ DNA", "๐Ÿ”ฌ Research", "๐ŸŒก๏ธ Temperature", "๐Ÿ Nutrition"],
["๐Ÿ“š Study", "๐Ÿง  Brain", "๐Ÿ‘ฉโ€๐ŸŽ“ Graduate", "๐Ÿ“ Measure", "๐Ÿ” Search", "๐Ÿ“Š Analyze", "๐Ÿ“‹ Plan", "๐Ÿ–‹๏ธ Write", "๐Ÿ‘จโ€๐Ÿซ Teach", "๐Ÿงฉ Puzzle"],
["๐Ÿค– Robot", "๐Ÿ‘พ Game", "๐Ÿ’ป Code", "๐Ÿงฎ Calculate", "๐Ÿ“ก Connect", "๐Ÿ”‹ Power", "๐Ÿ•น๏ธ Play", "๐Ÿ–ฅ๏ธ Display", "๐Ÿง‘โ€๐Ÿ’ป Develop", "๐Ÿ‘จโ€๐Ÿ”ฌ Experiment"],
["โœ๏ธ Author", "๐Ÿ“ Note", "๐Ÿ–Š๏ธ Pen", "๐Ÿ–‹๏ธ Sign", "๐Ÿ“š Library", "๐Ÿ”– Bookmark", "๐Ÿ““ Journal", "โœ’๏ธ Ink", "๐Ÿ“œ Scroll"]
]
cols = st.columns(len(headers))
for idx, (col, header, buttons_list) in enumerate(zip(cols, headers, buttons)):
with col:
st.markdown(f"### {header}")
for button_idx, button_label in enumerate(buttons_list, start=1):
key = generate_key(button_label, header, button_idx)
score = load_score(key)
if st.button(f"{button_label} {score}", key=key):
new_score = update_score(key)
# Reload the page to reflect the updated score
st.experimental_rerun()
# Main application logic
if __name__ == "__main__":
st.markdown('# Remixable!')
display_buttons_with_scores()
# Additional content and functionality can go here