Spaces:
Runtime error
Runtime error
File size: 3,707 Bytes
c11db43 49a4692 c11db43 6ea294a c11db43 6ea294a c11db43 6ea294a c11db43 6ea294a c11db43 6ea294a c11db43 6ea294a 39bd597 88bab31 |
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 |
import os
import pandas as pd
import streamlit as st
st.set_page_config(page_title="Dice Roller", page_icon="๐ฒ")
st.title("๐ฒ Dice Roller")
if 'username' not in st.session_state: st.session_state.username = st.text_input("๐ค Username", max_chars=50)
dice_types = {"๐ฒ Six-sided dice": {"sides": 6, "name": "d6", "emoji": "๐ฒ"},
"๐ฒ Thirty-sided dice": {"sides": 30, "name": "d30", "emoji": "๐ฒ"},
"๐ฒ Twenty-sided dice": {"sides": 20, "name": "d20", "emoji": "๐ฒ"},
"๐ฒ One hundred-sided dice": {"sides": 100, "name": "d100", "emoji": "๐ฏ"}}
dice_type = st.selectbox("๐ฒ Select a dice type", options=list(dice_types.keys()), format_func=lambda x: x.split(' ')[-2])
num_rolls = st.slider("๐ฒ How many times do you want to roll the dice?", 1, 1000000, 100)
rolls = [str(pd.Series([dice_types[dice_type]["sides"]] * num_rolls).apply(pd.Series.sample, replace=True))]
rolls = rolls[0].strip('[]').split('\n')
if st.button("๐ฒ Roll Dice"):
display_roll = [int(i) for i in rolls]
st.write(f"{dice_types[dice_type]['emoji']} You rolled {len(display_roll)} {dice_types[dice_type]['name']} dice: {', '.join(map(str, display_roll))}.")
bonus_match, count = (None, sum(display_roll))
if count % dice_types[dice_type]['sides'] == 0:
bonus_match = dice_types[dice_type]['name']
st.write(f"๐ Bonus match! You rolled a multiple of {dice_types[dice_type]['sides']}.")
df = pd.DataFrame({'Roll': rolls, 'Count': count, 'DiceNumberOfSides': dice_types[dice_type]['sides']})
file_exists = os.path.exists("SharedState.csv")
if file_exists: df.to_csv("SharedState.csv", mode='a', header=False, index=False)
else: df.to_csv("SharedState.csv", mode='w', header=True, index=False)
download_roll_history = st.checkbox("๐ฅ Download Roll History", value=True)
if os.path.exists("SharedState.csv"):
if download_roll_history:
with open("SharedState.csv", "rb") as f:
st.download_button(label="๐ฅ Download Roll History", data=f, file_name="SharedState.csv", mime="text/csv")
else: st.warning("No roll history found.")
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")
""")
|