import streamlit as st import random from collections import Counter # Set up the Streamlit app st.set_page_config(page_title="Bầu Cua Tôm Cá", layout="centered") st.title("Bầu Cua Tôm Cá") # Set font and colors st.markdown( """ """, unsafe_allow_html=True ) # UI elements shake_count = st.selectbox("Số lần lắc", ["1000", "50", "100", "500"]) shake_info = st.empty() result_label = st.empty() dice_faces = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"] default_faces = ["Cá", "Gà", "Nai"] selected_faces = [] for i in range(3): selected_faces.append(st.radio(f"Chọn mặt {i+1}", dice_faces, index=dice_faces.index(default_faces[i]))) # Opposite and adjacent faces (not used in Streamlit version) opposite_faces = { "Bầu": "Cua", "Cua": "Bầu", "Nai": "Tôm", "Tôm": "Nai", "Gà": "Cá", "Cá": "Gà" } adjacent_faces = { "Bầu": ["Tôm", "Gà", "Nai", "Cá"], "Cá": ["Bầu", "Nai", "Cua", "Tôm"], "Gà": ["Bầu", "Tôm", "Cua", "Nai"], "Tôm": ["Bầu", "Cá", "Cua", "Gà"], "Nai": ["Bầu", "Gà", "Cua", "Cá"], "Cua": ["Tôm", "Cá", "Nai", "Gà"] } def predict_result(): outcomes = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"] shake_count_int = int(shake_count) if len(selected_faces) == 3: results = [random.choice(outcomes) for _ in range(shake_count_int)] result_counts = Counter(results) sorted_results = sorted(result_counts.items(), key=lambda x: x[1], reverse=True) result_text = "Kết quả:\n" for outcome, count in sorted_results: result_text += f"{outcome}: {count} ({count/shake_count_int:.2%})\n" result_label.text(result_text) shake_info.text(f"Số lần lắc: {shake_count}") else: result_label.text("Vui lòng chọn 3 mặt đầu tiên.") def reset_results(): result_label.text("Kết quả: ") shake_info.text("Số lần lắc: 0") # Buttons if st.button("Lắc"): predict_result() if st.button("Reset"): reset_results()