Spaces:
Runtime error
Runtime error
Create backup_app.py
Browse files- backup_app.py +82 -0
backup_app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import plotly.graph_objects as go
|
5 |
+
from datetime import datetime
|
6 |
+
from base64 import b64encode
|
7 |
+
import time
|
8 |
+
|
9 |
+
FOOD_LIST = {4: "๐", 6: "๐", 8: "๐ฎ", 10: "๐", 12: "๐ฉ", 20: "๐ฅ", 50: "๐ฃ", 100: "๐พ"}
|
10 |
+
|
11 |
+
def roll_dice(num_rolls, dice_type):
|
12 |
+
rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
|
13 |
+
return rolls
|
14 |
+
|
15 |
+
def plot_tokens(health_tokens, coin_tokens):
|
16 |
+
fig = go.Figure()
|
17 |
+
fig.add_trace(go.Sankey(
|
18 |
+
node = {
|
19 |
+
"label": ["Health", "Coins"] + [FOOD_LIST[i] for i in DICE_TYPES],
|
20 |
+
"pad": 15
|
21 |
+
},
|
22 |
+
link = {
|
23 |
+
"source": [0, 1] + list(range(2, len(DICE_TYPES) + 2)),
|
24 |
+
"target": [2] * len(DICE_TYPES) + [3 + i for i in range(len(DICE_TYPES))],
|
25 |
+
"value": health_tokens + coin_tokens
|
26 |
+
},
|
27 |
+
))
|
28 |
+
return fig
|
29 |
+
|
30 |
+
st.set_page_config(page_title="๐๐ Emojitrition ๐ฎ๐", page_icon=":game_die:")
|
31 |
+
st.title("๐๐ Emojitrition ๐ฎ๐")
|
32 |
+
|
33 |
+
username = st.sidebar.text_input("๐ค Enter your username:")
|
34 |
+
num_rolls = st.sidebar.slider("๐ข Choose the number of rolls:", 1, 100, 3)
|
35 |
+
|
36 |
+
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
|
37 |
+
history = {"health_tokens": [0], "coin_tokens": [0]}
|
38 |
+
fig_element = st.empty()
|
39 |
+
|
40 |
+
for i in range(10):
|
41 |
+
for dice_type in DICE_TYPES:
|
42 |
+
rolls = roll_dice(num_rolls, dice_type)
|
43 |
+
highest_rolls = sum(roll == dice_type for roll in rolls)
|
44 |
+
coin_tokens_added = 0
|
45 |
+
|
46 |
+
dice_results = [f"{FOOD_LIST[dice_type]} {roll}" for roll in rolls]
|
47 |
+
st.write(f"๐ฐ Results for {dice_type}-sided slot machine: {' | '.join(dice_results)}")
|
48 |
+
|
49 |
+
for roll in rolls:
|
50 |
+
if roll == dice_type:
|
51 |
+
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} jackpot! ๐ฐ Adding 3 coins.")
|
52 |
+
coin_tokens_added += 3
|
53 |
+
if roll == max(rolls):
|
54 |
+
st.write(f"๐ Congratulations! You got the {FOOD_LIST[dice_type]} maximum value! ๐ Adding 10 health tokens.")
|
55 |
+
if dice_type == 100:
|
56 |
+
history["health_tokens"].append(history["health_tokens"][-1] + 10)
|
57 |
+
|
58 |
+
history[f"{dice_type}-sided slot machine jackpots"] = highest_rolls
|
59 |
+
history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
|
60 |
+
history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
|
61 |
+
|
62 |
+
fig = plot_tokens(history["health_tokens"], history["coin_tokens"])
|
63 |
+
fig_element.plotly_chart(fig)
|
64 |
+
time.sleep(1)
|
65 |
+
|
66 |
+
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)
|
67 |
+
|
68 |
+
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
|
69 |
+
filename = f"{username}_{timestamp}.csv"
|
70 |
+
df.to_csv(filename, index=False)
|
71 |
+
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)
|
72 |
+
|
73 |
+
st.markdown("""
|
74 |
+
|
75 |
+
๐ฃ Introducing Emojitrition - the fun and easy way to track your nutrition! ๐๐๐ฎ๐๐ฉ๐ฅ๐ฃ๐พ
|
76 |
+
๐ Sick of boring nutrition tracking apps? Emojitrition is here to spice things up! ๐ถ๏ธ
|
77 |
+
๐ Our app uses food nutrition emojis to make tracking your meals easy and fun. ๐ด
|
78 |
+
๐ Whether you're making healthy choices with ๐ฅ or indulging in some ๐ฉ, Emojitrition makes it easy to see how your meals add up.
|
79 |
+
๐ Download Emojitrition today and start making more informed choices for your health and well-being! ๐ฒ
|
80 |
+
๐ It's time to ditch the boring old numbers and words and embrace the world of nutrition emojis! ๐
|
81 |
+
|
82 |
+
""")
|