feministmystique commited on
Commit
6d20b45
Β·
verified Β·
1 Parent(s): b4cf5e3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +53 -33
src/streamlit_app.py CHANGED
@@ -56,6 +56,11 @@ p_application = """
56
  6. Do not include any explanation or examples in your response.
57
  """
58
 
 
 
 
 
 
59
  # Initialize session state
60
  if "help_clicks" not in st.session_state:
61
  st.session_state.help_clicks = 0
@@ -102,48 +107,63 @@ with st.container():
102
 
103
  with col1:
104
  if st.button("πŸ“ Explain the question"):
105
- prompt = (
106
- "[INST]<<SYS>>\n"
107
- f"{prompt + p_explanation}\n"
108
- "<</SYS>>\n\n"
109
- f"{QUESTION}\n"
110
- "[/INST]"
111
- )
112
- st.session_state.response = llm.invoke(prompt)
113
-
114
- st.session_state.button_clicked = "Explain the question"
 
 
 
115
  with col2:
116
- if st.button("πŸ’‘ Give an example"):
117
- prompt = (
118
- "[INST]<<SYS>>\n"
119
- f"{prompt + p_example}\n"
120
- "<</SYS>>\n\n"
121
- f"{QUESTION}\n"
122
- "[/INST]"
123
- )
124
- st.session_state.response = llm.invoke(prompt)
125
-
126
- st.session_state.button_clicked = "Give an example"
 
 
 
127
  with col3:
128
  if st.button("πŸ€” Who cares?"):
129
- prompt = (
130
- "[INST]<<SYS>>\n"
131
- f"{prompt + p_application}\n"
132
- "<</SYS>>\n\n"
133
- f"{QUESTION}\n"
134
- "[/INST]"
135
- )
136
- st.session_state.response = llm.invoke(prompt)
137
-
138
- st.session_state.button_clicked = "Who cares?"
139
-
 
 
140
  st.markdown("---")
141
 
142
  # Display response text if a sub-button is clicked
143
  if st.session_state.button_clicked:
144
  with st.container():
145
  st.info(st.session_state.response)
146
-
 
 
 
 
 
 
 
147
  # Optional: Add footer or spacing
148
  st.markdown("<br><br>", unsafe_allow_html=True)
149
 
 
56
  6. Do not include any explanation or examples in your response.
57
  """
58
 
59
+ # count the number of times "I don't know is clicked"
60
+ if "retry_count" not in st.session_state:
61
+ st.session_state.retry_count = 0
62
+
63
+
64
  # Initialize session state
65
  if "help_clicks" not in st.session_state:
66
  st.session_state.help_clicks = 0
 
107
 
108
  with col1:
109
  if st.button("πŸ“ Explain the question"):
110
+ if st.session_state.button_clicked != "Explain the question":
111
+ # First time clicked
112
+ full_prompt = (
113
+ "[INST]<<SYS>>\n"
114
+ f"{prompt + p_explanation}\n"
115
+ "<</SYS>>\n\n"
116
+ f"{QUESTION}\n"
117
+ "[/INST]"
118
+ )
119
+ st.session_state.response = llm.invoke(full_prompt)
120
+ st.session_state.retry_count = 0
121
+ st.session_state.full_prompt = full_prompt # Save prompt for retry
122
+ st.session_state.button_clicked = "Explain the question"
123
  with col2:
124
+ if st.button("πŸ’‘ Give an example"):
125
+ if st.session_state.button_clicked != "Give an example":
126
+ # First time clicked
127
+ full_prompt = (
128
+ "[INST]<<SYS>>\n"
129
+ f"{prompt + p_example}\n"
130
+ "<</SYS>>\n\n"
131
+ f"{QUESTION}\n"
132
+ "[/INST]"
133
+ )
134
+ st.session_state.response = llm.invoke(full_prompt)
135
+ st.session_state.retry_count = 0
136
+ st.session_state.full_prompt = full_prompt # Save prompt for retry
137
+ st.session_state.button_clicked = "Give an example"
138
  with col3:
139
  if st.button("πŸ€” Who cares?"):
140
+ if st.session_state.button_clicked != "Who cares?":
141
+ # First time clicked
142
+ full_prompt = (
143
+ "[INST]<<SYS>>\n"
144
+ f"{prompt + p_application}\n"
145
+ "<</SYS>>\n\n"
146
+ f"{QUESTION}\n"
147
+ "[/INST]"
148
+ )
149
+ st.session_state.response = llm.invoke(full_prompt)
150
+ st.session_state.retry_count = 0
151
+ st.session_state.full_prompt = full_prompt # Save prompt for retry
152
+ st.session_state.button_clicked = "Who cares?"
153
  st.markdown("---")
154
 
155
  # Display response text if a sub-button is clicked
156
  if st.session_state.button_clicked:
157
  with st.container():
158
  st.info(st.session_state.response)
159
+
160
+ if st.session_state.button_clicked == "Explain the question":
161
+ if st.button("I don't understand. Try again."):
162
+ st.session_state.retry_count += 1
163
+ alt_llm = get_llm(temperature=0.9)
164
+ st.session_state.response = alt_llm.invoke(
165
+ st.session_state.full_prompt
166
+ )
167
  # Optional: Add footer or spacing
168
  st.markdown("<br><br>", unsafe_allow_html=True)
169