jonathantiedchen commited on
Commit
432c4f6
Β·
verified Β·
1 Parent(s): 4cc9747

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -87,11 +87,22 @@ st.sidebar.write("πŸ“₯ Load GSM8K")
87
  gsm8k_data = load_gsm8k_dataset()
88
  st.sidebar.write("πŸ“Š GSM8K loaded:", len(gsm8k_data), "samples")
89
 
90
- question_index = st.selectbox("πŸ”’ Select GSM8K question index", range(len(gsm8k_data)))
 
 
 
 
 
 
 
 
 
 
91
 
92
  if st.button("🎲 Pick Random Question"):
93
- question_index = random.randint(0, len(gsm8k_data) - 1)
94
- st.query_params.update(question_index=question_index)
 
95
 
96
  default_prompt = "Jasper has 5 apples and eats 2 of them. How many apples does he have left?"
97
  selected_question = gsm8k_data[question_index]["question"] if question_index is not None else default_prompt
@@ -111,6 +122,9 @@ prompt = st.text_area("Enter your math prompt:", selected_question)
111
 
112
  # Generation
113
  if st.button("Generate Response", key="manual"):
 
 
 
114
  with st.sidebar:
115
  with st.spinner("πŸ”„ Generating..."):
116
 
@@ -143,5 +157,8 @@ if st.button("Generate Response", key="manual"):
143
  st.write(input_text)
144
  st.subheader("🧠 Model Output")
145
  st.success(response_only)
146
- st.subheader("βœ… Correct Answer (GSM8K)")
147
- st.info(correct_answer)
 
 
 
 
87
  gsm8k_data = load_gsm8k_dataset()
88
  st.sidebar.write("πŸ“Š GSM8K loaded:", len(gsm8k_data), "samples")
89
 
90
+ # Check for random question index in query params
91
+ random_index = st.query_params.get("question_index")
92
+ if random_index is not None:
93
+ try:
94
+ default_index = int(random_index)
95
+ except (ValueError, TypeError):
96
+ default_index = 0
97
+ else:
98
+ default_index = 0
99
+
100
+ question_index = st.selectbox("πŸ”’ Select GSM8K question index", range(len(gsm8k_data)), index=default_index)
101
 
102
  if st.button("🎲 Pick Random Question"):
103
+ new_random_index = random.randint(0, len(gsm8k_data) - 1)
104
+ st.query_params.update(question_index=new_random_index)
105
+ st.rerun() # Force app to rerun to update the selectbox
106
 
107
  default_prompt = "Jasper has 5 apples and eats 2 of them. How many apples does he have left?"
108
  selected_question = gsm8k_data[question_index]["question"] if question_index is not None else default_prompt
 
122
 
123
  # Generation
124
  if st.button("Generate Response", key="manual"):
125
+ # Check if the current prompt is from GSM8K dataset
126
+ is_gsm8k_question = prompt == selected_question
127
+
128
  with st.sidebar:
129
  with st.spinner("πŸ”„ Generating..."):
130
 
 
157
  st.write(input_text)
158
  st.subheader("🧠 Model Output")
159
  st.success(response_only)
160
+
161
+ # Only show correct answer if using actual GSM8K question
162
+ if is_gsm8k_question:
163
+ st.subheader("βœ… Correct Answer (GSM8K)")
164
+ st.info(correct_answer)