psuserlas commited on
Commit
9dd927a
·
verified ·
1 Parent(s): 3eab6d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -176,17 +176,36 @@ def respond_strict(message, history):
176
 
177
 
178
  with gr.Blocks() as demo:
 
 
 
 
 
179
  with gr.Row():
180
  cool_button = gr.Button("Cool Mom")
181
  tutor_button = gr.Button("Tutor Mom")
182
  strict_button = gr.Button("Strict Mom")
183
- cool_button.click(fn=respond_cool, inputs=[], outputs=[])
184
- tutor_button.click(fn=respond_tutor, inputs=[], outputs=[])
185
- strict_button.click(fn=respond_strict, inputs=[], outputs=[])
186
- if cool_button.click():
187
- chatbot = gr.ChatInterface(respond_cool, type = 'messages')
188
- elif tutor_button.click():
189
- chatbot = gr.ChatInterface(respond_tutor, type = 'messages')
190
- else:
191
- chatbot = gr.ChatInterface(respond_strict, type = 'messages')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  demo.launch()
 
176
 
177
 
178
  with gr.Blocks() as demo:
179
+ mom_type = gr.State("Cool Mom") # default state
180
+ history = gr.State([])
181
+
182
+ with gr.Row():
183
+ gr.Markdown("### Choose your Mom Mode")
184
  with gr.Row():
185
  cool_button = gr.Button("Cool Mom")
186
  tutor_button = gr.Button("Tutor Mom")
187
  strict_button = gr.Button("Strict Mom")
188
+
189
+ def set_mom_cool(): return "Cool Mom"
190
+ def set_mom_tutor(): return "Tutor Mom"
191
+ def set_mom_strict(): return "Strict Mom"
192
+
193
+ cool_button.click(fn=set_mom_cool, inputs=[], outputs=mom_type)
194
+ tutor_button.click(fn=set_mom_tutor, inputs=[], outputs=mom_type)
195
+ strict_button.click(fn=set_mom_strict, inputs=[], outputs=mom_type)
196
+
197
+ def route_message(message, history, mom_type):
198
+ if mom_type == "Cool Mom":
199
+ return respond_cool(message, history)
200
+ elif mom_type == "Tutor Mom":
201
+ return respond_tutor(message, history)
202
+ else:
203
+ return respond_strict(message, history)
204
+
205
+ gr.ChatInterface(
206
+ fn=route_message,
207
+ additional_inputs=[history, mom_type],
208
+ title="StudyMama"
209
+ )
210
+
211
  demo.launch()