kooldark commited on
Commit
6fc92ce
·
verified ·
1 Parent(s): 2ee692c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Set font and colors
10
+ st.markdown(
11
+ """
12
+ <style>
13
+ .stButton>button {
14
+ font-size: 16px;
15
+ background-color: #FF0000;
16
+ color: #FFFFFF;
17
+ }
18
+ .stSelectbox, .stRadio {
19
+ font-size: 16px;
20
+ }
21
+ .stText {
22
+ font-size: 16px;
23
+ color: #000000;
24
+ }
25
+ </style>
26
+ """,
27
+ unsafe_allow_html=True
28
+ )
29
+
30
+ # UI elements
31
+ shake_count = st.selectbox("Số lần lắc", ["1000", "50", "100", "500"])
32
+ shake_info = st.empty()
33
+ result_label = st.empty()
34
+
35
+ dice_faces = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
36
+ default_faces = ["Cá", "Gà", "Nai"]
37
+ selected_faces = []
38
+
39
+ cols = st.columns(3)
40
+ for i, col in enumerate(cols):
41
+ with col:
42
+ selected_faces.append(st.radio(f"Chọn mặt {i+1}", dice_faces, index=dice_faces.index(default_faces[i])))
43
+
44
+ # Opposite and adjacent faces (not used in Streamlit version)
45
+ opposite_faces = {
46
+ "Bầu": "Cua",
47
+ "Cua": "Bầu",
48
+ "Nai": "Tôm",
49
+ "Tôm": "Nai",
50
+ "Gà": "Cá",
51
+ "Cá": "Gà"
52
+ }
53
+
54
+ adjacent_faces = {
55
+ "Bầu": ["Tôm", "Gà", "Nai", "Cá"],
56
+ "Cá": ["Bầu", "Nai", "Cua", "Tôm"],
57
+ "Gà": ["Bầu", "Tôm", "Cua", "Nai"],
58
+ "Tôm": ["Bầu", "Cá", "Cua", "Gà"],
59
+ "Nai": ["Bầu", "Gà", "Cua", "Cá"],
60
+ "Cua": ["Tôm", "Cá", "Nai", "Gà"]
61
+ }
62
+
63
+ def predict_result():
64
+ outcomes = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
65
+ shake_count_int = int(shake_count)
66
+
67
+ if len(selected_faces) == 3:
68
+ results = [random.choice(outcomes) for _ in range(shake_count_int)]
69
+ result_counts = Counter(results)
70
+ sorted_results = sorted(result_counts.items(), key=lambda x: x[1], reverse=True)
71
+
72
+ result_text = "Kết quả:\n"
73
+ for outcome, count in sorted_results:
74
+ result_text += f"{outcome}: {count} ({count/shake_count_int:.2%})\n"
75
+
76
+ result_label.text(result_text)
77
+ shake_info.text(f"Số lần lắc: {shake_count}")
78
+ else:
79
+ result_label.text("Vui lòng chọn 3 mặt đầu tiên.")
80
+
81
+ def reset_results():
82
+ result_label.text("Kết quả: ")
83
+ shake_info.text("Số lần lắc: 0")
84
+
85
+ # Buttons
86
+ if st.button("Lắc"):
87
+ predict_result()
88
+
89
+ if st.button("Reset"):
90
+ reset_results()