Experiment - Combine Voting and Reward System with Links

#5
by awacke1 - opened

You missed a bunch of my program. Dont loose lines and rewrite with below as example: import streamlit as st
import os
import json
from PIL import Image

score_dir = "scores"
os.makedirs(score_dir, exist_ok=True)

def generate_key(label, header, idx):
return f"{header}{label}{idx}"
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"]

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

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)
                st.experimental_rerun()

if name == "main":
st.markdown('# Remixable!')
display_buttons_with_scores()

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
image/png
image/png
image/png
image/png
image/png
''') Also, add these functions and call the wikipedia and google search for each in output links next to count buttons: table_md = f"""
| ๐Ÿ“šWikipedia | ๐ŸŽฅYouTube
| ๐ŸŽธChords | ๐ŸŽถLyrics |
"""
st.markdown(table_md)
def create_search_url_wikipedia(artist_song):
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')

def create_search_url_youtube(artist_song):
base_url = "https://www.youtube.com/results?search_query="
return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')

def create_search_url_chords(artist_song):
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')

def create_search_url_lyrics(artist_song):
base_url = "https://www.google.com/search?q="
return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and') + '+lyrics'

Sign up or log in to comment