Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,8 @@ model = model.to(device)
|
|
| 14 |
|
| 15 |
def respond(message, history):
|
| 16 |
history = history or []
|
| 17 |
-
|
|
|
|
| 18 |
full_input = ""
|
| 19 |
for user, bot in history:
|
| 20 |
full_input += f"User: {user}\nAssistant: {bot}\n"
|
|
@@ -29,16 +30,18 @@ def respond(message, history):
|
|
| 29 |
top_p=0.95,
|
| 30 |
pad_token_id=tokenizer.eos_token_id
|
| 31 |
)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# Извлекаем только ответ ассистента
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
history.append((message, response))
|
|
|
|
| 39 |
return response, history
|
| 40 |
|
|
|
|
| 41 |
chat = gr.ChatInterface(fn=respond, title="Innopolis Chatbot")
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
chat.launch()
|
|
|
|
| 14 |
|
| 15 |
def respond(message, history):
|
| 16 |
history = history or []
|
| 17 |
+
|
| 18 |
+
# Собираем всю историю в виде текста
|
| 19 |
full_input = ""
|
| 20 |
for user, bot in history:
|
| 21 |
full_input += f"User: {user}\nAssistant: {bot}\n"
|
|
|
|
| 30 |
top_p=0.95,
|
| 31 |
pad_token_id=tokenizer.eos_token_id
|
| 32 |
)
|
| 33 |
+
output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 34 |
+
|
| 35 |
+
# Извлекаем только ответ ассистента
|
| 36 |
+
response = output_text.split("Assistant:")[-1].strip()
|
| 37 |
+
|
| 38 |
+
# Добавляем в историю в виде (вопрос, ответ)
|
| 39 |
history.append((message, response))
|
| 40 |
+
|
| 41 |
return response, history
|
| 42 |
|
| 43 |
+
|
| 44 |
chat = gr.ChatInterface(fn=respond, title="Innopolis Chatbot")
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
+
chat.launch(share=True)
|