Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ user_dictionary = {} #A dictionary that we can save mutible server side informat
|
|
| 14 |
|
| 15 |
with gr.Blocks(theme=gr.themes.Monochrome(),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]) # 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.
|
|
@@ -37,8 +38,18 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
|
|
| 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=gr.themes.Monochrome(),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]) # 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.
|
|
|
|
| 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 |
+
// send the user_id to the parent window
|
| 45 |
+
window.parent.postMessage(
|
| 46 |
+
{{ user_id: "{new_id}" }},
|
| 47 |
+
"*" // ideally replace "*" with your Qualtrics domain
|
| 48 |
+
);
|
| 49 |
+
</script>
|
| 50 |
+
"""
|
| 51 |
|
| 52 |
+
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.
|
| 53 |
|
| 54 |
def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
|
| 55 |
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.
|