Spaces:
Runtime error
Runtime error
File size: 3,579 Bytes
f360d45 9f66be1 f360d45 9f66be1 f360d45 d501fab 9f66be1 d501fab 9f66be1 599b1ed e72d043 f360d45 9f66be1 f360d45 9f66be1 f360d45 d501fab f360d45 d501fab f360d45 d501fab f360d45 d501fab f360d45 9f66be1 7741083 f360d45 d501fab 3559abd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
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
# Define general functions
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
},
))
st.plotly_chart(fig)
# Define Streamlit app
st.set_page_config(page_title="๐๐ Emojitrition ๐ฎ๐", page_icon=":game_die:")
st.title("๐๐ Emojitrition ๐ฎ๐")
# Sidebar
username = st.sidebar.text_input("๐ค Enter your username:")
num_rolls = st.sidebar.slider("๐ข Choose the number of rolls:", 1, 100, 3)
# Main content
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
history = {"health_tokens": [0], "coin_tokens": [0]}
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.")
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)
plot_tokens(history["health_tokens"], history["coin_tokens"])
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 Emojitrition - the fun and easy way to track your nutrition! ๐๐๐ฎ๐๐ฉ๐ฅ๐ฃ๐พ
๐ Sick of boring nutrition tracking apps? Emojitrition is here to spice things up! ๐ถ๏ธ
๐ Our app uses food nutrition emojis to make tracking your meals easy and fun. ๐ด
๐ Whether you're making healthy choices with ๐ฅ or indulging in some ๐ฉ, Emojitrition makes it easy to see how your meals add up.
๐ Download Emojitrition today and start making more informed choices for your health and well-being! ๐ฒ
๐ It's time to ditch the boring old numbers and words and embrace the world of nutrition emojis! ๐
""") |