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