Added parallelism workaround
Browse files
app.py
CHANGED
@@ -813,13 +813,16 @@ for param in model.parameters():
|
|
813 |
|
814 |
eot_token = "<|endoftext|>"
|
815 |
|
816 |
-
def get_reply(response,
|
|
|
817 |
stepsize = in_stepsize
|
818 |
horizon_length = int(in_horizon_length)
|
819 |
num_iterations = int(in_num_iterations)
|
820 |
top_k = int(in_top_k)
|
821 |
if response.endswith(("bye", "Bye", "bye.", "Bye.", "bye!", "Bye!")):
|
822 |
-
|
|
|
|
|
823 |
convo_hist = (history if history != None else "How are you?<|endoftext|>") + response + eot_token
|
824 |
# figure out conditioning text
|
825 |
tokenized_cond_text = tokenizer.encode(
|
@@ -874,9 +877,10 @@ def get_reply(response, history = None, in_stepsize = 2.56, in_horizon_length =
|
|
874 |
convo_hist = eot_token.join(convo_hist_split)
|
875 |
|
876 |
except:
|
877 |
-
|
878 |
-
|
879 |
-
|
|
|
880 |
|
881 |
css = """
|
882 |
.chatbox {display:flex;flex-direction:column}
|
@@ -889,6 +893,7 @@ css = """
|
|
889 |
gr.Interface(fn=get_reply,
|
890 |
theme="default",
|
891 |
inputs=[gr.inputs.Textbox(placeholder="How are you?"),
|
|
|
892 |
"state"],
|
893 |
outputs=["html", "state"],
|
894 |
css=css).launch(debug=True, enable_queue=True)
|
|
|
813 |
|
814 |
eot_token = "<|endoftext|>"
|
815 |
|
816 |
+
def get_reply(response, username = None, histories = {}, in_stepsize = 2.56, in_horizon_length = 5, in_num_iterations = 10, in_top_k = 2):
|
817 |
+
if username == None or username == "": return "<div class='chatbot'>Enter a username</div>", histories
|
818 |
stepsize = in_stepsize
|
819 |
horizon_length = int(in_horizon_length)
|
820 |
num_iterations = int(in_num_iterations)
|
821 |
top_k = int(in_top_k)
|
822 |
if response.endswith(("bye", "Bye", "bye.", "Bye.", "bye!", "Bye!")):
|
823 |
+
del histories[username]
|
824 |
+
return "<div class='chatbot'>Chatbot restarted</div>", histories
|
825 |
+
history = histories.get(username, None)
|
826 |
convo_hist = (history if history != None else "How are you?<|endoftext|>") + response + eot_token
|
827 |
# figure out conditioning text
|
828 |
tokenized_cond_text = tokenizer.encode(
|
|
|
877 |
convo_hist = eot_token.join(convo_hist_split)
|
878 |
|
879 |
except:
|
880 |
+
del histories[username]
|
881 |
+
return "<div class='chatbot'>Error occured, chatbot restarted</div>", histories
|
882 |
+
histories[username] = convo_hist
|
883 |
+
return html, histories
|
884 |
|
885 |
css = """
|
886 |
.chatbox {display:flex;flex-direction:column}
|
|
|
893 |
gr.Interface(fn=get_reply,
|
894 |
theme="default",
|
895 |
inputs=[gr.inputs.Textbox(placeholder="How are you?"),
|
896 |
+
gr.inputs.Textbox(label="Username"),
|
897 |
"state"],
|
898 |
outputs=["html", "state"],
|
899 |
css=css).launch(debug=True, enable_queue=True)
|