tonyhui2234 commited on
Commit
33c2b59
·
verified ·
1 Parent(s): 114e54c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -29,6 +29,8 @@ if "error_message" not in st.session_state:
29
  st.session_state.error_message = ""
30
  if "cfu_explain_text" not in st.session_state:
31
  st.session_state.cfu_explain_text = ""
 
 
32
 
33
  if "fortune_data" not in st.session_state:
34
  try:
@@ -37,9 +39,6 @@ if "fortune_data" not in st.session_state:
37
  st.error(f"Error loading CSV: {e}")
38
  st.session_state.fortune_data = None
39
 
40
- if "stick_clicked" not in st.session_state:
41
- st.session_state.stick_clicked = False
42
-
43
  def load_finetuned_classifier_model(question):
44
  label_list = ["Geomancy", "Lost Property", "Personal Well-Being", "Future Prospect", "Traveling"]
45
  # Create a mapping dictionary to convert the default "LABEL_x" output.
@@ -71,7 +70,6 @@ def analysis(row_detail, classifiy, question):
71
  result = match.group(1)
72
  # If you want to generate a custom answer, you can call generate_answer()
73
  return generate_answer(question, result)
74
- # return result
75
  else:
76
  return "Heaven's secret cannot be revealed."
77
 
@@ -99,7 +97,7 @@ def submit_text_callback():
99
  return
100
 
101
  if st.session_state.button_count_temp == 0:
102
- st.session_state.error_message = "Please take a moment to quietly reflect on your question in your mind, then click submit."
103
  st.session_state.button_count_temp = 1
104
  return
105
 
@@ -133,10 +131,6 @@ def submit_text_callback():
133
  "HeaderLink": None
134
  }
135
  print(row_detail)
136
- classifiy = load_finetuned_classifier_model(question)
137
- cfu_explain = analysis(row_detail, classifiy, question)
138
- # Save the returned value in session state for later display
139
- st.session_state.cfu_explain_text = cfu_explain
140
 
141
  def load_and_resize_image(path, max_size=MAX_SIZE):
142
  try:
@@ -160,6 +154,18 @@ def download_and_resize_image(url, max_size=MAX_SIZE):
160
  return None
161
 
162
  def stick_enquiry_callback():
 
 
 
 
 
 
 
 
 
 
 
 
163
  st.session_state.stick_clicked = True
164
 
165
  # Main layout: Left (input) and Right (fortune display)
 
29
  st.session_state.error_message = ""
30
  if "cfu_explain_text" not in st.session_state:
31
  st.session_state.cfu_explain_text = ""
32
+ if "stick_clicked" not in st.session_state:
33
+ st.session_state.stick_clicked = False
34
 
35
  if "fortune_data" not in st.session_state:
36
  try:
 
39
  st.error(f"Error loading CSV: {e}")
40
  st.session_state.fortune_data = None
41
 
 
 
 
42
  def load_finetuned_classifier_model(question):
43
  label_list = ["Geomancy", "Lost Property", "Personal Well-Being", "Future Prospect", "Traveling"]
44
  # Create a mapping dictionary to convert the default "LABEL_x" output.
 
70
  result = match.group(1)
71
  # If you want to generate a custom answer, you can call generate_answer()
72
  return generate_answer(question, result)
 
73
  else:
74
  return "Heaven's secret cannot be revealed."
75
 
 
97
  return
98
 
99
  if st.session_state.button_count_temp == 0:
100
+ st.session_state.error_message = "Please take a moment to quietly reflect on your question in your mind, then click submit again!"
101
  st.session_state.button_count_temp = 1
102
  return
103
 
 
131
  "HeaderLink": None
132
  }
133
  print(row_detail)
 
 
 
 
134
 
135
  def load_and_resize_image(path, max_size=MAX_SIZE):
136
  try:
 
154
  return None
155
 
156
  def stick_enquiry_callback():
157
+ # Retrieve the user's question and the fortune detail
158
+ question = st.session_state.get("user_sentence", "")
159
+ if not st.session_state.fortune_row:
160
+ st.error("Fortune data is not available. Please submit your question first.")
161
+ return
162
+ row_detail = st.session_state.fortune_row.get("Detail", "No detail available.")
163
+ # Run the classifier model after the image has loaded
164
+ classifiy = load_finetuned_classifier_model(question)
165
+ # Generate the explanation using the analysis function
166
+ cfu_explain = analysis(row_detail, classifiy, question)
167
+ # Save the returned value in session state for later display
168
+ st.session_state.cfu_explain_text = cfu_explain
169
  st.session_state.stick_clicked = True
170
 
171
  # Main layout: Left (input) and Right (fortune display)