Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,163 +3,6 @@
|
|
3 |
#st.Markdown("TODO: A code density slider bar shows and adjusts the size of lines. ')
|
4 |
#st.Markdown('Any ๐ฒDice๐ฒ way to compress the lines yet make it readable as optimal list of sets will do. Match language from good math books.')
|
5 |
|
6 |
-
import os
|
7 |
-
import streamlit as st
|
8 |
-
import numpy as np
|
9 |
-
import pandas as pd
|
10 |
-
import plotly.express as px
|
11 |
-
st.set_page_config(layout='wide')
|
12 |
-
st.title('Any ๐ฒDice๐ฒ Way - STEM Math and Data Science Numerical Potluck')
|
13 |
-
dice_types = [{'name': 'Six-sided Dice', 'sides': 6, 'emoji': '๐ฒ'},
|
14 |
-
{'name': 'Twenty-sided Dice', 'sides': 20, 'emoji': '๐ฟ'},
|
15 |
-
{'name': 'Thirty-sided Dice', 'sides': 30, 'emoji': '๐ฅ'},
|
16 |
-
{'name': 'One Hundred-sided Dice', 'sides': 100, 'emoji': '๐'}]
|
17 |
-
if 'username' not in st.session_state:
|
18 |
-
st.session_state.username = ''
|
19 |
-
if 'dice_roll_history' not in st.session_state:
|
20 |
-
st.session_state.dice_roll_history = pd.DataFrame()
|
21 |
-
dice_type = st.selectbox('Choose a type of dice', dice_types, format_func=lambda d: f"{d['name']} {d['emoji']}")
|
22 |
-
num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
|
23 |
-
rolls = np.random.randint(1, dice_type['sides'] + 1, num_rolls, dtype=np.uint64)
|
24 |
-
roll_counts = pd.Series(rolls).value_counts().sort_index()
|
25 |
-
fig = px.sunburst(names=[f'Roll {i}' for i in roll_counts.index],
|
26 |
-
parents=['Dice Rolls'] * dice_type['sides'],
|
27 |
-
values=roll_counts.values,
|
28 |
-
color=[f'Roll {i}' for i in roll_counts.index],
|
29 |
-
color_discrete_sequence=px.colors.qualitative.Dark24,
|
30 |
-
maxdepth=2)
|
31 |
-
fig.update_layout(title='Dice Roll Distribution', margin=dict(l=20, r=20, t=40, b=20), width=800, height=600)
|
32 |
-
show_labels = st.checkbox('Show Labels', value=True)
|
33 |
-
if not show_labels:
|
34 |
-
fig.update_traces(textinfo='none')
|
35 |
-
fig.show()
|
36 |
-
bonus_match = False
|
37 |
-
for dice in dice_types:
|
38 |
-
if rolls[0] == dice['sides']:
|
39 |
-
bonus_match = True
|
40 |
-
bonus_dice_type = dice['name']
|
41 |
-
bonus_dice_emoji = dice['emoji']
|
42 |
-
break
|
43 |
-
dice_roll_history = st.session_state.dice_roll_history
|
44 |
-
new_roll_data = pd.DataFrame({'Roll': rolls,
|
45 |
-
'Count': np.ones(num_rolls, dtype=np.uint64),
|
46 |
-
'DiceNumberOfSides': [dice_type['sides']] * num_rolls,
|
47 |
-
'Username': [st.session_state.username] * num_rolls})
|
48 |
-
if bonus_match:
|
49 |
-
new_roll_data['BonusMatchToDiceName'] = [bonus_dice_type] * num_rolls
|
50 |
-
new_roll_data['BonusMatchToDiceEmoji'] = [bonus_dice_emoji] * num_rolls
|
51 |
-
dice_roll_history = dice_roll_history.append(new_roll_data, ignore_index=True)
|
52 |
-
st.session_state.dice_roll_history = dice_roll_history
|
53 |
-
include_name_column = st.checkbox('Include Username Column in Downloaded CSV', value=True)
|
54 |
-
if st.button('Download Results'):
|
55 |
-
filename = f'dice_roll_history_{st.session_state.username}{dice_type["emoji"]}.csv'
|
56 |
-
if not include_name_column:
|
57 |
-
dice_roll_history = dice_roll_history.drop(columns=['Username'])
|
58 |
-
filename = f'dice_roll_history{dice_type["emoji"]}.csv'
|
59 |
-
st.download_button(label='Download CSV', data=dice_roll_history.to_csv(index=False), file_name=filename, mime='text/csv')
|
60 |
-
csv_files = [f for f in os.listdir('.') if os.path.isfile
|
61 |
-
f.endswith('.csv') and 'dice_roll_history' in f]
|
62 |
-
if csv_files:
|
63 |
-
st.write('Downloaded files:')
|
64 |
-
for csv_file in csv_files:
|
65 |
-
st.markdown(f'[Download {csv_file}]({csv_file})')
|
66 |
-
st.write('---')
|
67 |
-
st.subheader('Settings')
|
68 |
-
st.session_state.username = st.text_input('Username', st.session_state.username)
|
69 |
-
st.write('---')
|
70 |
-
st.subheader('Dice Roll History')
|
71 |
-
st.write(dice_roll_history)
|
72 |
|
73 |
-
|
74 |
-
๐ Bread
|
75 |
-
๐ฅ Croissant
|
76 |
-
๐ฅ Baguette Bread
|
77 |
-
๐ซ Flatbread
|
78 |
-
๐ฅจ Pretzel
|
79 |
-
๐ฅฏ Bagel
|
80 |
-
๐ฅ Pancakes
|
81 |
-
๐ง Waffle
|
82 |
-
๐ง Cheese Wedge
|
83 |
-
๐ Meat on Bone
|
84 |
-
๐ Poultry Leg
|
85 |
-
๐ฅฉ Cut of Meat
|
86 |
-
๐ฅ Bacon
|
87 |
-
๐ Hamburger
|
88 |
-
๐ French Fries
|
89 |
-
๐ Pizza
|
90 |
-
๐ญ Hot Dog
|
91 |
-
๐ฅช Sandwich
|
92 |
-
๐ฎ Taco
|
93 |
-
๐ฏ Burrito
|
94 |
-
๐ซ Tamale
|
95 |
-
๐ฅ Stuffed Flatbread
|
96 |
-
๐ง Falafel
|
97 |
-
๐ฅ Egg
|
98 |
-
๐ณ Cooking
|
99 |
-
๐ฅ Shallow Pan of Food
|
100 |
-
๐ฒ Pot of Food
|
101 |
-
๐ซ Fondue
|
102 |
-
๐ฅฃ Bowl with Spoon
|
103 |
-
๐ฅ Green Salad
|
104 |
-
๐ฟ Popcorn
|
105 |
-
๐ง Butter
|
106 |
-
๐ง Salt
|
107 |
-
๐ฅซ Canned Food
|
108 |
-
๐ฑ Bento Box
|
109 |
-
๐ Rice Cracker
|
110 |
-
๐ Rice Ball
|
111 |
-
๐ Cooked Rice
|
112 |
-
๐ Curry Rice
|
113 |
-
๐ Steaming Bowl
|
114 |
-
๐ Spaghetti
|
115 |
-
๐ Roasted Sweet Potato
|
116 |
-
๐ข Oden
|
117 |
-
๐ฃ Sushi
|
118 |
-
๐ค Fried Shrimp
|
119 |
-
๐ฅ Fish Cake with Swirl
|
120 |
-
๐ฅฎ Moon Cake
|
121 |
-
๐ก Dango
|
122 |
-
๐ฅ Dumpling
|
123 |
-
๐ฅ Fortune Cookie
|
124 |
-
๐ฅก Takeout Box
|
125 |
-
๐ฆช Oyster
|
126 |
-
๐ฆ Soft Ice Cream
|
127 |
-
๐ง Shaved Ice
|
128 |
-
๐จ Ice Cream
|
129 |
-
๐ฉ Doughnut
|
130 |
-
๐ช Cookie
|
131 |
-
๐ Birthday Cake
|
132 |
-
๐ฐ Shortcake
|
133 |
-
๐ง Cupcake
|
134 |
-
๐ฅง Pie
|
135 |
-
๐ซ Chocolate Bar
|
136 |
-
๐ฌ Candy
|
137 |
-
๐ญ Lollipop
|
138 |
-
๐ฎ Custard
|
139 |
-
๐ฏ Honey Pot
|
140 |
-
๐ผ Baby Bottle
|
141 |
-
๐ฅ Glass of Milk
|
142 |
-
โ Hot Beverage
|
143 |
-
๐ซ Teapot
|
144 |
-
๐ต Teacup Without Handle
|
145 |
-
๐ถ Sake
|
146 |
-
๐พ Bottle with Popping Cork
|
147 |
-
๐ท Wine Glass
|
148 |
-
๐ธ Cocktail Glass
|
149 |
-
๐น Tropical Drink
|
150 |
-
๐บ Beer Mug
|
151 |
-
๐ป Clinking Beer Mugs
|
152 |
-
๐ฅ Clinking Glasses
|
153 |
-
๐ฅ Tumbler Glass
|
154 |
-
๐ซ Pouring Liquid
|
155 |
-
๐ฅค Cup with Straw
|
156 |
-
๐ง Bubble Tea
|
157 |
-
๐ง Beverage Box
|
158 |
-
๐ง Mate
|
159 |
-
๐ง Ice
|
160 |
-
๐ฅข Chopsticks
|
161 |
-
๐ฝ๏ธ Fork and Knife with Plate
|
162 |
-
๐ด Fork and Knife
|
163 |
-
๐ฅ Spoon
|
164 |
-
๐ซ Jar
|
165 |
-
""")
|
|
|
3 |
#st.Markdown("TODO: A code density slider bar shows and adjusts the size of lines. ')
|
4 |
#st.Markdown('Any ๐ฒDice๐ฒ way to compress the lines yet make it readable as optimal list of sets will do. Match language from good math books.')
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
|
8 |
+
st.write("๐ Bread, ๐ฅ Croissant, ๐ฅ Baguette Bread, ๐ซ Flatbread, ๐ฅจ Pretzel, ๐ฅฏ Bagel, ๐ฅ Pancakes, ๐ง Waffle, ๐ง Cheese Wedge, ๐ Meat on Bone, ๐ Poultry Leg, ๐ฅฉ Cut of Meat, ๐ฅ Bacon, ๐ Hamburger, ๐ French Fries, ๐ Pizza, ๐ญ Hot Dog, ๐ฅช Sandwich, ๐ฎ Taco, ๐ฏ Burrito, ๐ซ Tamale, ๐ฅ Stuffed Flatbread, ๐ง Falafel, ๐ฅ Egg, ๐ณ Cooking, ๐ฅ Shallow Pan of Food, ๐ฒ Pot of Food, ๐ซ Fondue, ๐ฅฃ Bowl with Spoon, ๐ฅ Green Salad, ๐ฟ Popcorn, ๐ง Butter, ๐ง Salt, ๐ฅซ Canned Food, ๐ฑ Bento Box, ๐ Rice Cracker, ๐ Rice Ball, ๐ Cooked Rice, ๐ Curry Rice, ๐ Steaming Bowl, ๐ Spaghetti, ๐ Roasted Sweet Potato, ๐ข Oden, ๐ฃ Sushi, ๐ค Fried Shrimp, ๐ฅ Fish Cake with Swirl, ๐ฅฎ Moon Cake, ๐ก Dango, ๐ฅ Dumpling, ๐ฅ Fortune Cookie, ๐ฅก Takeout Box, ๐ฆช Oyster, ๐ฆ Soft Ice Cream, ๐ง Shaved Ice, ๐จ Ice Cream, ๐ฉ Doughnut, ๐ช Cookie, ๐ Birthday Cake, ๐ฐ Shortcake, ๐ง Cupcake, ๐ฅง Pie, ๐ซ Chocolate Bar, ๐ฌ Candy, ๐ญ Lollipop, ๐ฎ Custard, ๐ฏ Honey Pot, ๐ผ Baby Bottle, ๐ฅ Glass of Milk, โ Hot Beverage, ๐ซ Teapot, ๐ต Teacup Without Handle, ๐ถ Sake, ๐พ Bottle with Popping Cork, ๐ท Wine Glass, ๐ธ Cocktail Glass, ๐น Tropical Drink, ๐บ Beer Mug, ๐ป Clinking Beer Mugs, ๐ฅ Clinking Glasses, ๐ฅ Tumbler Glass, ๐ซ Pouring Liquid, ๐ฅค Cup with Straw, ๐ง Bubble Tea, ๐ง Beverage Box, ๐ง Mate, ๐ง Ice, ๐ฅข Chopsticks, ๐ฝ๏ธ Fork and Knife with Plate, ๐ด Fork and Knife, ๐ฅ Spoon, ๐ซ Jar")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|