Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,23 +9,8 @@ def predict(input, history=[]):
|
|
| 9 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 10 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
| 11 |
history = model.generate(bot_input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id).tolist()
|
| 12 |
-
response = tokenizer.decode(history[0]).
|
| 13 |
-
response.remove("")
|
| 14 |
-
|
| 15 |
-
html = "<div class='chatbot'>"
|
| 16 |
-
for m, msg in enumerate(response):
|
| 17 |
-
cls = "user" if m%2 == 0 else "bot"
|
| 18 |
-
html += "<div class='msg {}'> {}</div>".format(cls, msg)
|
| 19 |
-
html += "</div>"
|
| 20 |
|
| 21 |
return response, history
|
| 22 |
|
| 23 |
-
|
| 24 |
-
.chatbox {display:flex;flex-direction:column}
|
| 25 |
-
.msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
| 26 |
-
.msg.user {background-color:cornflowerblue;color:white}
|
| 27 |
-
.msg.bot {background-color:darkgray;align-self:self-end}
|
| 28 |
-
.footer {display:none !important}
|
| 29 |
-
"""
|
| 30 |
-
|
| 31 |
-
gr.Interface(fn=predict, theme="grass", title="Chatbot Two", inputs=[gr.inputs.Textbox(placeholder="Write a text message as if writing a text message to a human."), "state"], outputs=["html", "state"], css=css).launch()
|
|
|
|
| 9 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 10 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
| 11 |
history = model.generate(bot_input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id).tolist()
|
| 12 |
+
response = tokenizer.decode(history[0]).replace("<|endoftext|>", "\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
return response, history
|
| 15 |
|
| 16 |
+
gr.Interface(fn=predict, theme="grass", title="Chatbot Two", inputs=[gr.inputs.Textbox(placeholder="Write a text message as if writing a text message to a human."), "state"], outputs=["text", "state"], css=".footer {display:none !important}").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|