brunhild217 commited on
Commit
fa1ff63
·
1 Parent(s): 423d2e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -10,13 +10,12 @@ def add_user_message(user_message, chat_tutor):
10
  return chat_tutor.conversation_memory, chat_tutor
11
 
12
  def get_tutor_reply(chat_tutor):
13
- chat_tutor.get_tutor_reply(input_kwargs={'question':''})
14
  return gr.update(value="", interactive=True), chat_tutor.conversation_memory, chat_tutor
15
 
16
  def get_conversation_history(chat_tutor):
17
  return chat_tutor.conversation_memory, chat_tutor
18
 
19
-
20
  ### Instructor Interface Helper Functions ###
21
  def get_instructor_prompt(fileobj):
22
  file_path = fileobj.name
@@ -50,18 +49,15 @@ with gr.Blocks() as demo:
50
  user_chat_input = gr.Textbox(label="User input", scale=9)
51
  user_chat_submit = gr.Button("Ask/answer model", scale=1)
52
 
 
 
53
  user_chat_submit.click(
54
- add_user_message,
55
- [user_chat_input, study_tutor],
56
- [chatbot, study_tutor],
57
- queue=False
58
  ).then(
59
- get_tutor_reply,
60
- [study_tutor],
61
- [user_chat_input, chatbot, study_tutor],
62
- queue=True)
63
 
64
- # Testing purpose
65
  test_btn = gr.Button("View your chat history")
66
  chat_history = gr.JSON(label = "conversation history")
67
  test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
@@ -87,7 +83,6 @@ with gr.Blocks() as demo:
87
  with gr.Tab("Instructor Only"):
88
  # API Authentication functionality
89
  # Instead of ask students to provide key, the key is now provided by the instructor
90
-
91
  """
92
  To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
93
  then replace OPENAI_API_KEY value with whatever openai key of the instructor.
@@ -98,7 +93,7 @@ with gr.Blocks() as demo:
98
  # The instructor will provide a secret prompt/persona to the tutor
99
  with gr.Blocks():
100
  # testing purpose, change visible to False at deployment
101
- test_secret = gr.Textbox(label="Current secret prompt", value=os.environ.get("SECRET_PROMPT"), visible=True)
102
 
103
  # Prompt instructor to upload the secret file
104
  file_input = gr.File(label="Load a .txt or .py file", file_types=['.py', '.txt'], type="file", elem_classes="short-height")
@@ -115,12 +110,11 @@ with gr.Blocks() as demo:
115
  # Set the secret prompt in this session and embed it to the study tutor
116
  prompt_submit_btn = gr.Button("Submit")
117
  prompt_submit_btn.click(
118
- fn=embed_prompt, inputs=[instructor_prompt], outputs=[test_secret]
119
  ).then(
120
  fn=create_reference_store,
121
  inputs=[study_tutor, prompt_submit_btn, instructor_prompt, file_input_none, instructor_input_none, api_input, learning_objectives_none],
122
  outputs=[study_tutor, prompt_submit_btn]
123
  )
124
- # TODO: may need a way to set the secret prompt permanently in settings/secret
125
 
126
  demo.queue().launch(server_name='0.0.0.0', server_port=7860)
 
10
  return chat_tutor.conversation_memory, chat_tutor
11
 
12
  def get_tutor_reply(chat_tutor):
13
+ chat_tutor.get_tutor_reply()
14
  return gr.update(value="", interactive=True), chat_tutor.conversation_memory, chat_tutor
15
 
16
  def get_conversation_history(chat_tutor):
17
  return chat_tutor.conversation_memory, chat_tutor
18
 
 
19
  ### Instructor Interface Helper Functions ###
20
  def get_instructor_prompt(fileobj):
21
  file_path = fileobj.name
 
49
  user_chat_input = gr.Textbox(label="User input", scale=9)
50
  user_chat_submit = gr.Button("Ask/answer model", scale=1)
51
 
52
+ # First add user's message to the conversation history
53
+ # Then get reply from the tutor and add that to the conversation history
54
  user_chat_submit.click(
55
+ fn = add_user_message, inputs = [user_chat_input, study_tutor], outputs = [chatbot, study_tutor], queue=False
 
 
 
56
  ).then(
57
+ fn = get_tutor_reply, inputs = [study_tutor], outputs = [user_chat_input, chatbot, study_tutor], queue=True
58
+ )
 
 
59
 
60
+ # Testing the chat history storage, can be deleted at deployment
61
  test_btn = gr.Button("View your chat history")
62
  chat_history = gr.JSON(label = "conversation history")
63
  test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
 
83
  with gr.Tab("Instructor Only"):
84
  # API Authentication functionality
85
  # Instead of ask students to provide key, the key is now provided by the instructor
 
86
  """
87
  To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
88
  then replace OPENAI_API_KEY value with whatever openai key of the instructor.
 
93
  # The instructor will provide a secret prompt/persona to the tutor
94
  with gr.Blocks():
95
  # testing purpose, change visible to False at deployment
96
+ view_secret = gr.Textbox(label="Current secret prompt", value=os.environ.get("SECRET_PROMPT"), visible=False)
97
 
98
  # Prompt instructor to upload the secret file
99
  file_input = gr.File(label="Load a .txt or .py file", file_types=['.py', '.txt'], type="file", elem_classes="short-height")
 
110
  # Set the secret prompt in this session and embed it to the study tutor
111
  prompt_submit_btn = gr.Button("Submit")
112
  prompt_submit_btn.click(
113
+ fn=embed_prompt, inputs=[instructor_prompt], outputs=[view_secret]
114
  ).then(
115
  fn=create_reference_store,
116
  inputs=[study_tutor, prompt_submit_btn, instructor_prompt, file_input_none, instructor_input_none, api_input, learning_objectives_none],
117
  outputs=[study_tutor, prompt_submit_btn]
118
  )
 
119
 
120
  demo.queue().launch(server_name='0.0.0.0', server_port=7860)