Spaces:
Runtime error
Runtime error
Commit
·
f21ebd0
1
Parent(s):
3aae5df
Adds userId to each query (#11)
Browse files- Adds userId to each query (3f6bcdf91306acd434d3f7d83a9a07157b917773)
Co-authored-by: Samay gandhi <samayg@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -97,6 +97,7 @@ with gr.Blocks(theme='samayg/StriimTheme', css=CSS) as demo:
|
|
| 97 |
# image = gr.Image('striim-logo-light.png', height=68, width=200, show_label=False, show_download_button=False, show_share_button=False)
|
| 98 |
chatbot = gr.Chatbot(show_label=False, elem_id="chatbot")
|
| 99 |
msg = gr.Textbox(label="Question:")
|
|
|
|
| 100 |
examples = gr.Examples(examples=[['What\'s new in Striim version 4.2.0?'], ['My Striim application keeps crashing. What should I do?'], ['How can I improve Striim performance?'], ['It says could not connect to source or target. What should I do?']], inputs=msg, label="Examples")
|
| 101 |
submit = gr.Button("Submit", elem_id="submit-button")
|
| 102 |
|
|
@@ -105,7 +106,7 @@ with gr.Blocks(theme='samayg/StriimTheme', css=CSS) as demo:
|
|
| 105 |
#internet_access = gr.Checkbox(value=False, label="Allow Internet Access?", info="If the chatbot cannot answer your question, this setting allows for internet access. Warning: this may take longer and produce inaccurate results.")
|
| 106 |
|
| 107 |
chat_history = []
|
| 108 |
-
def
|
| 109 |
global chat_history
|
| 110 |
#if allow_internet:
|
| 111 |
# Get response from internet-based query function
|
|
@@ -120,11 +121,11 @@ with gr.Blocks(theme='samayg/StriimTheme', css=CSS) as demo:
|
|
| 120 |
chat_history.append((query, answer))
|
| 121 |
# Only keeps last 5 messages to not exceed tokens
|
| 122 |
chat_history = chat_history[-5:]
|
| 123 |
-
return gr.update(value=""), chat_history
|
| 124 |
|
| 125 |
# The msg.submit() now also depends on the status of the internet_access checkbox
|
| 126 |
-
msg.submit(
|
| 127 |
-
submit.click(
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
# demo.launch(debug=True)
|
|
|
|
| 97 |
# image = gr.Image('striim-logo-light.png', height=68, width=200, show_label=False, show_download_button=False, show_share_button=False)
|
| 98 |
chatbot = gr.Chatbot(show_label=False, elem_id="chatbot")
|
| 99 |
msg = gr.Textbox(label="Question:")
|
| 100 |
+
user = gr.State("gradio")
|
| 101 |
examples = gr.Examples(examples=[['What\'s new in Striim version 4.2.0?'], ['My Striim application keeps crashing. What should I do?'], ['How can I improve Striim performance?'], ['It says could not connect to source or target. What should I do?']], inputs=msg, label="Examples")
|
| 102 |
submit = gr.Button("Submit", elem_id="submit-button")
|
| 103 |
|
|
|
|
| 106 |
#internet_access = gr.Checkbox(value=False, label="Allow Internet Access?", info="If the chatbot cannot answer your question, this setting allows for internet access. Warning: this may take longer and produce inaccurate results.")
|
| 107 |
|
| 108 |
chat_history = []
|
| 109 |
+
def getResponse(query, history, userId):
|
| 110 |
global chat_history
|
| 111 |
#if allow_internet:
|
| 112 |
# Get response from internet-based query function
|
|
|
|
| 121 |
chat_history.append((query, answer))
|
| 122 |
# Only keeps last 5 messages to not exceed tokens
|
| 123 |
chat_history = chat_history[-5:]
|
| 124 |
+
return gr.update(value=""), chat_history, userId
|
| 125 |
|
| 126 |
# The msg.submit() now also depends on the status of the internet_access checkbox
|
| 127 |
+
msg.submit(getResponse, [msg, chatbot, user], [msg, chatbot, user], queue=False)
|
| 128 |
+
submit.click(getResponse, [msg, chatbot, user], [msg, chatbot, user], queue=False)
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
# demo.launch(debug=True)
|