kavansaun commited on
Commit
b5be76e
·
verified ·
1 Parent(s): 332b671

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -14,8 +14,9 @@ user_dictionary = {} #A dictionary that we can save mutible server side informat
14
 
15
  with gr.Blocks(theme='davehornik/Tealy',css="footer{display:none !important}") as chatblock: # Creating UI using gradio Blocks. This line sets the block as a variable called "chatblock", the theme as monochrome, and removes the footer of the page.
16
  user_id = gr.TextArea(visible=False) # Displaying the user id, it is made not-visible because the id hasnt been created yet and we dont want the user seeing it anyway.
 
17
 
18
- @chatblock.load(outputs=[user_id],show_progress='Hidden',show_api=False) # When the chatblock loads we send the information from the following function "load_user" to "user_id".
19
  def load_user(): # When the chatblock loads, the message history is initialized, the instructions are initialized, and the users id is created, sent, and made visible to the ui variable above.
20
  global message_history # Made global variables so we can use them in the "predict_prompt" function.
21
  global instructions
@@ -37,8 +38,17 @@ with gr.Blocks(theme='davehornik/Tealy',css="footer{display:none !important}") a
37
  file_type = '.txt'
38
  filename = str(new_id) + file_type
39
  repo.create_file(filename, "Saving" + filename, "")
 
 
 
 
 
 
 
 
 
40
 
41
- return gr.TextArea(new_id,visible=False) # Returning the "TextArea" object with what we want. Set visible to True if you want the id to appear when its made.
42
 
43
  def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
44
  user_dictionary[user_id].append({"role": "user", "content": inputs}) # This adds the input from the user and saves it to the history before we do anything else.
 
14
 
15
  with gr.Blocks(theme='davehornik/Tealy',css="footer{display:none !important}") as chatblock: # Creating UI using gradio Blocks. This line sets the block as a variable called "chatblock", the theme as monochrome, and removes the footer of the page.
16
  user_id = gr.TextArea(visible=False) # Displaying the user id, it is made not-visible because the id hasnt been created yet and we dont want the user seeing it anyway.
17
+ notifier = gr.HTML(visible=False)
18
 
19
+ @chatblock.load(outputs=[user_id,notifier],show_progress='Hidden',show_api=False) # When the chatblock loads we send the information from the following function "load_user" to "user_id".
20
  def load_user(): # When the chatblock loads, the message history is initialized, the instructions are initialized, and the users id is created, sent, and made visible to the ui variable above.
21
  global message_history # Made global variables so we can use them in the "predict_prompt" function.
22
  global instructions
 
38
  file_type = '.txt'
39
  filename = str(new_id) + file_type
40
  repo.create_file(filename, "Saving" + filename, "")
41
+
42
+ script = f"""
43
+ <script>
44
+ window.parent.postMessage(
45
+ {{ user_id: "{new_id}" }},
46
+ "*" // you can lock this down to your Qualtrics domain
47
+ );
48
+ </script>
49
+ """
50
 
51
+ return gr.TextArea(new_id,visible=False),gr.HTML(script,visible=False) # Returning the "TextArea" object with what we want. Set visible to True if you want the id to appear when its made.
52
 
53
  def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
54
  user_dictionary[user_id].append({"role": "user", "content": inputs}) # This adds the input from the user and saves it to the history before we do anything else.