Update app.py
Browse files
app.py
CHANGED
@@ -18,51 +18,51 @@ st.set_page_config(page_title="Fortuen Stick Enquiry", layout="wide")
|
|
18 |
|
19 |
st.title("Fortuen Stick Enquiry")
|
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 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
# # Function to load and resize local images using Pillow
|
68 |
# def load_and_resize_image(path, max_size=MAX_SIZE):
|
|
|
18 |
|
19 |
st.title("Fortuen Stick Enquiry")
|
20 |
|
21 |
+
# Initialize session state variables
|
22 |
+
if "submitted_text" not in st.session_state:
|
23 |
+
st.session_state.submitted_text = False
|
24 |
+
if "fortune_number" not in st.session_state:
|
25 |
+
st.session_state.fortune_number = None
|
26 |
+
if "fortune_row" not in st.session_state:
|
27 |
+
st.session_state.fortune_row = None
|
28 |
+
if "fortune_data" not in st.session_state:
|
29 |
+
try:
|
30 |
+
st.session_state.fortune_data = pd.read_csv(r"/home/user/app/detail.csv")
|
31 |
+
except Exception as e:
|
32 |
+
st.error(f"Error loading CSV: {e}")
|
33 |
+
st.session_state.fortune_data = None
|
34 |
|
35 |
+
if "stick_clicked" not in st.session_state:
|
36 |
+
st.session_state.stick_clicked = False
|
37 |
|
38 |
|
39 |
+
# Callback function for the submit button:
|
40 |
+
def submit_text_callback():
|
41 |
+
st.session_state.submitted_text = True
|
42 |
+
# Randomly generate a number from 1 to 100
|
43 |
+
st.session_state.fortune_number = random.randint(1, 100)
|
44 |
|
45 |
+
# Look up the row in the CSV where CNumber matches the generated fortune number.
|
46 |
+
df = st.session_state.fortune_data
|
47 |
+
if df is not None:
|
48 |
+
matching_row = df[df['CNumber'] == st.session_state.fortune_number]
|
49 |
+
if not matching_row.empty:
|
50 |
+
row = matching_row.iloc[0]
|
51 |
+
st.session_state.fortune_row = {
|
52 |
+
"Header": row.get("Header", "N/A"),
|
53 |
+
"Luck": row.get("Luck", "N/A"),
|
54 |
+
"Description": row.get("Description", "No description available."),
|
55 |
+
"Detail": row.get("Detail", "No detail available."),
|
56 |
+
"HeaderLink": row.get("link", None) # URL to the image
|
57 |
+
}
|
58 |
+
else:
|
59 |
+
st.session_state.fortune_row = {
|
60 |
+
"Header": "N/A",
|
61 |
+
"Luck": "N/A",
|
62 |
+
"Description": "No description available.",
|
63 |
+
"Detail": "No detail available.",
|
64 |
+
"HeaderLink": None
|
65 |
+
}
|
66 |
|
67 |
# # Function to load and resize local images using Pillow
|
68 |
# def load_and_resize_image(path, max_size=MAX_SIZE):
|