import streamlit as st import os import json from PIL import Image # 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 col1, col2, col3 = st.columns(3) with col1: st.markdown('''### Inputs''') st.button("đ Text") st.button("đ Read") st.button("đˇ Photo") st.button("đŧī¸ View") st.button("đī¸ Record") st.button("đ§ Listen") st.button("đĨ Video") st.button("đš Capture") with col2: st.markdown('''### Outputs''') st.button("đŦ Chat") st.button("âī¸ Write") st.button("đ¨ Art") st.button("đ Create") st.button("đĩ Music") st.button("đļ Compose") st.button("đŧ Watch") st.button("đŋ Movies") with col3: st.markdown('''### Health''') st.button("đ Vaccinate") st.button("đŠē Diagnose") st.button("đĨ Hospital") st.button("đ Emergency") st.button("đ Meds") st.button("𩹠Bandage") st.button("đ§Ŧ DNA") st.button("đŦ Research") st.button("đĄī¸ Temperature") st.button("đ Nutrition") col4, col5, col6 = st.columns(3) with col4: st.markdown('''### Learning''') st.button("đ Study") st.button("đ§ Brain") st.button("đŠâđ Graduate") st.button("đ Measure") st.button("đ Search") st.button("đ Analyze") st.button("đ Plan") st.button("đī¸ Write") st.button("đ¨âđĢ Teach") st.button("𧊠Puzzle") with col5: st.markdown('''### AI''') st.button("đ¤ Robot") st.button("đž Game") st.button("đģ Code") st.button("𧎠Calculate") st.button("đĄ Connect") st.button("đ Power") st.button("đšī¸ Play") st.button("đĨī¸ Display") st.button("đ§âđģ Develop") st.button("đ¨âđŦ Experiment") with col6: st.markdown('''### Writing''') st.button("âī¸ Author") st.button("đ Note") st.button("đī¸ Pen") st.button("đī¸ Sign") st.button("đ Library") st.button("đ Bookmark") st.button("đ Journal") st.button("âī¸ Ink") st.button("đ Scroll") def display_images_and_wikipedia_summaries(): st.title('Gallery with Related Stories') image_files = [f for f in os.listdir('.') if f.endswith('.png')] if not image_files: st.write("No PNG images found in the current directory.") return for image_file in image_files: image = Image.open(image_file) st.image(image, caption=image_file, use_column_width='always') keyword = image_file.split('.')[0] # Assumes keyword is the file name without extension wikipedia_summary = fetch_wikipedia_summary(keyword) st.write(wikipedia_summary) display_images_and_wikipedia_summaries() st.markdown('# Three Dragons đđ Mythical Dragons Around the World by Aaron Wacker') dragons = { '#Fafnir #Norse': '- **Story**: Fafnir originally a dwarf, transformed into a fierce dragon due to his greed for the treasure he guarded. He was later slain by the hero Sigurd. - **Significance**: deadly sin of greed and the corrupting power of wealth.', '#Quetzalcoatl #Aztec': '- **Story**: Quetzalcoatl, the Feathered Serpent, is not a dragon in the traditional sense but shares many similarities. He was a deity representing wind, air, and learning. - **Significance**: creator god and a symbol of death and rebirth.', '#Tiamat #Mesopotamian': '- **Story**: Tiamat, primordial goddess of ocean, turned into a dragon-like creature in a battle against her children who threatened her authority. - **Significance**: chaos of primordial creation and is often associated with the forces of nature.' } for dragon, story in dragons.items(): st.subheader(dragon) st.markdown(f"- {story}") st.markdown(''' https://github.com/AaronCWacker/ThreeDragons      ''')