Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
from collections import Counter
|
| 4 |
+
|
| 5 |
+
# Set up the Streamlit app
|
| 6 |
+
st.set_page_config(page_title="Bầu Cua Tôm Cá", layout="centered")
|
| 7 |
+
st.title("Bầu Cua Tôm Cá")
|
| 8 |
+
|
| 9 |
+
# Add a header image
|
| 10 |
+
st.image("https://example.com/header_image.jpg", use_column_width=True)
|
| 11 |
+
|
| 12 |
+
# Set font and colors
|
| 13 |
+
st.markdown(
|
| 14 |
+
"""
|
| 15 |
+
<style>
|
| 16 |
+
.stButton>button {
|
| 17 |
+
font-size: 18px;
|
| 18 |
+
background-color: #FF5733;
|
| 19 |
+
color: #FFFFFF;
|
| 20 |
+
border-radius: 10px;
|
| 21 |
+
padding: 10px 20px;
|
| 22 |
+
}
|
| 23 |
+
.stSelectbox, .stRadio {
|
| 24 |
+
font-size: 18px;
|
| 25 |
+
color: #333333;
|
| 26 |
+
}
|
| 27 |
+
.stText {
|
| 28 |
+
font-size: 18px;
|
| 29 |
+
color: #333333;
|
| 30 |
+
}
|
| 31 |
+
.stApp {
|
| 32 |
+
background-color: #F5F5F5;
|
| 33 |
+
}
|
| 34 |
+
</style>
|
| 35 |
+
""",
|
| 36 |
+
unsafe_allow_html=True
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# UI elements
|
| 40 |
+
shake_count = st.selectbox("Số lần lắc", ["1000", "50", "100", "500"])
|
| 41 |
+
shake_info = st.empty()
|
| 42 |
+
result_label = st.empty()
|
| 43 |
+
|
| 44 |
+
dice_faces = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
|
| 45 |
+
default_faces = ["Cá", "Gà", "Nai"]
|
| 46 |
+
selected_faces = []
|
| 47 |
+
|
| 48 |
+
# Use columns for a more responsive layout
|
| 49 |
+
cols = st.beta_columns(3)
|
| 50 |
+
for i in range(3):
|
| 51 |
+
selected_faces.append(cols[i].radio(f"Chọn mặt {i+1}", dice_faces, index=dice_faces.index(default_faces[i])))
|
| 52 |
+
|
| 53 |
+
# Opposite and adjacent faces (not used in Streamlit version)
|
| 54 |
+
opposite_faces = {
|
| 55 |
+
"Bầu": "Cua",
|
| 56 |
+
"Cua": "Bầu",
|
| 57 |
+
"Nai": "Tôm",
|
| 58 |
+
"Tôm": "Nai",
|
| 59 |
+
"Gà": "Cá",
|
| 60 |
+
"Cá": "Gà"
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
adjacent_faces = {
|
| 64 |
+
"Bầu": ["Tôm", "Gà", "Nai", "Cá"],
|
| 65 |
+
"Cá": ["Bầu", "Nai", "Cua", "Tôm"],
|
| 66 |
+
"Gà": ["Bầu", "Tôm", "Cua", "Nai"],
|
| 67 |
+
"Tôm": ["Bầu", "Cá", "Cua", "Gà"],
|
| 68 |
+
"Nai": ["Bầu", "Gà", "Cua", "Cá"],
|
| 69 |
+
"Cua": ["Tôm", "Cá", "Nai", "Gà"]
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
def predict_result():
|
| 73 |
+
outcomes = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
|
| 74 |
+
shake_count_int = int(shake_count)
|
| 75 |
+
|
| 76 |
+
if len(selected_faces) == 3:
|
| 77 |
+
results = [random.choice(outcomes) for _ in range(shake_count_int)]
|
| 78 |
+
result_counts = Counter(results)
|
| 79 |
+
sorted_results = sorted(result_counts.items(), key=lambda x: x[1], reverse=True)
|
| 80 |
+
|
| 81 |
+
result_text = "Kết quả:\n"
|
| 82 |
+
for outcome, count in sorted_results:
|
| 83 |
+
result_text += f"{outcome}: {count} ({count/shake_count_int:.2%})\n"
|
| 84 |
+
|
| 85 |
+
result_label.text(result_text)
|
| 86 |
+
shake_info.text(f"Số lần lắc: {shake_count}")
|
| 87 |
+
else:
|
| 88 |
+
result_label.text("Vui lòng chọn 3 mặt đầu tiên.")
|
| 89 |
+
|
| 90 |
+
def reset_results():
|
| 91 |
+
result_label.text("Kết quả: ")
|
| 92 |
+
shake_info.text("Số lần lắc: 0")
|
| 93 |
+
|
| 94 |
+
# Buttons
|
| 95 |
+
if st.button("Lắc"):
|
| 96 |
+
predict_result()
|
| 97 |
+
|
| 98 |
+
if st.button("Reset"):
|
| 99 |
+
reset_results()
|