brunhild217 commited on
Commit
ae32d37
·
1 Parent(s): 164bf10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -29,7 +29,7 @@ save_txt = partial(save_chatbot_dialogue, save_type='txt')
29
  # history is a list of list
30
  # [[user_input_str, bot_response_str], ...]
31
 
32
- class BasicTutor:
33
  # create basic initialization function
34
  def __init__(self):
35
  self.conversation_memory = []
@@ -61,10 +61,12 @@ def get_tutor_reply(user_message, chat_tutor):
61
  chat_tutor.get_tutor_reply(user_message)
62
  return gr.update(value="", interactive=True), chat_tutor.conversation_memory, chat_tutor
63
 
 
 
64
 
65
  with gr.Blocks() as demo:
66
  #initialize tutor (with state)
67
- study_tutor = gr.State(BasicTutor())
68
 
69
  # Chatbot interface
70
  gr.Markdown("""
@@ -78,11 +80,16 @@ with gr.Blocks() as demo:
78
  with gr.Row():
79
  user_chat_input = gr.Textbox(label="User input", scale=9)
80
  user_chat_submit = gr.Button("Ask/answer model", scale=1)
 
 
81
 
82
  user_chat_submit.click(add_user_message,
83
  [user_chat_input, study_tutor],
84
  [chatbot, study_tutor], queue=False).then(
85
  get_tutor_reply, [user_chat_input, study_tutor], [user_chat_input, chatbot, study_tutor], queue=True)
 
 
 
86
 
87
  with gr.Blocks():
88
  gr.Markdown("""
 
29
  # history is a list of list
30
  # [[user_input_str, bot_response_str], ...]
31
 
32
+ class EchoingTutor:
33
  # create basic initialization function
34
  def __init__(self):
35
  self.conversation_memory = []
 
61
  chat_tutor.get_tutor_reply(user_message)
62
  return gr.update(value="", interactive=True), chat_tutor.conversation_memory, chat_tutor
63
 
64
+ def get_conversation_history(chat_tutor):
65
+ return chat_tutor.conversation_memory
66
 
67
  with gr.Blocks() as demo:
68
  #initialize tutor (with state)
69
+ study_tutor = gr.State(EchoingTutorTutor())
70
 
71
  # Chatbot interface
72
  gr.Markdown("""
 
80
  with gr.Row():
81
  user_chat_input = gr.Textbox(label="User input", scale=9)
82
  user_chat_submit = gr.Button("Ask/answer model", scale=1)
83
+
84
+ clear_btn = gr.Button("Start a new conversation")
85
 
86
  user_chat_submit.click(add_user_message,
87
  [user_chat_input, study_tutor],
88
  [chatbot, study_tutor], queue=False).then(
89
  get_tutor_reply, [user_chat_input, study_tutor], [user_chat_input, chatbot, study_tutor], queue=True)
90
+
91
+ # Testing purpose
92
+ gr.Interface(fn=get_conversation_history, inputs=None, outputs="text")
93
 
94
  with gr.Blocks():
95
  gr.Markdown("""