Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import plotly.graph_objects as go | |
| from datetime import datetime | |
| from base64 import b64encode | |
| import time | |
| FOOD_LIST = {4: "๐ฅฆ", 6: "๐", 8: "๐ฅ", 10: "๐ ", 12: "๐", 20: "๐ฅ", 50: "๐", 100: "๐ฅฅ"} | |
| def roll_dice(num_rolls, dice_type): | |
| rolls = np.random.randint(1, dice_type + 1, size=num_rolls) | |
| return rolls | |
| def plot_tokens(health_tokens, coin_tokens): | |
| fig = go.Figure() | |
| fig.add_trace(go.Sankey( | |
| node = { | |
| "label": ["Health", "Coins"] + [FOOD_LIST[i] for i in DICE_TYPES], | |
| "pad": 15 | |
| }, | |
| link = { | |
| "source": [0, 1] + list(range(2, len(DICE_TYPES) + 2)), | |
| "target": [2] * len(DICE_TYPES) + [3 + i for i in range(len(DICE_TYPES))], | |
| "value": health_tokens + coin_tokens | |
| }, | |
| )) | |
| return fig | |
| st.set_page_config(page_title="๐๐ฅSankey Snacks๐ฝ๐ฅ", page_icon=":game_die:") | |
| st.title("๐๐ฅSankey Snacks๐ฝ๐ฅ") | |
| username = st.sidebar.text_input("๐ค Enter your username:") | |
| num_rolls = st.sidebar.slider("๐ข Choose the number of rolls:", 1, 100, 3) | |
| DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100] | |
| history = {"health_tokens": [0], "coin_tokens": [0]} | |
| fig_element = st.empty() | |
| for i in range(10): | |
| for dice_type in DICE_TYPES: | |
| rolls = roll_dice(num_rolls, dice_type) | |
| highest_rolls = sum(roll == dice_type for roll in rolls) | |
| coin_tokens_added = 0 | |
| dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls] | |
| st.write(f"๐ฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}") | |
| for roll in rolls: | |
| if roll == dice_type: | |
| st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐ฐ Adding 3 coins.") | |
| coin_tokens_added += 3 | |
| if roll == max(rolls): | |
| st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐ Adding 10 health tokens. ๐Sankey Snacks!๐ฝ") | |
| if dice_type == 100: | |
| history["health_tokens"].append(history["health_tokens"][-1] + 10) | |
| history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls | |
| history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls} | |
| history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added) | |
| fig = plot_tokens(history["health_tokens"], history["coin_tokens"]) | |
| fig_element.plotly_chart(fig) | |
| time.sleep(1) | |
| df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1) | |
| timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S") | |
| filename = f"{username}_{timestamp}.csv" | |
| df.to_csv(filename, index=False) | |
| st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| ๐ฃ Introducing ๐๐ฅSankey Snacks๐ฝ๐ฅ - the game that makes healthy eating fun and interactive! | |
| ๐ Are you tired of the same old boring STEM activities? Sankey Snacks is here to add some excitement to your learning experience! ๐คฉ | |
| ๐ Our game uses ๐๐ฅSankey๐ฝ๐ฅ diagrams to show you the flow of nutrients in the food you eat. ๐ก๏ธ | |
| ๐ From crispy ๐ to crunchy ๐ฅ, Sankey Snacks makes it easy to see how the food you eat affects your body. And don't worry, we didn't forget about the occasional ๐ or ๐ treat! ๐คค | |
| ๐ Clone ๐๐ฅSankey Snacks๐ฝ๐ฅ today and start exploring the world of healthy eating in a fun and interactive way! ๐ฎ | |
| ๐ It's time to ditch the boring old textbooks and embrace the world of ๐๐ฅSankey๐ฝ๐ฅ diagrams and healthy snacks! ๐ฅฆ๐ฅค | |
| ๐ Get ready to snack and learn with Sankey Snacks! ๐๐ฝ๐๐๐ฅ๐๐ฅ๐ฅค | |
| """) | |