Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import spaces
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
@spaces.GPU
|
8 |
def respond(message, history):
|
9 |
-
|
|
|
|
|
10 |
for user, bot in history:
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
output =
|
15 |
-
|
16 |
-
max_new_tokens=200,
|
17 |
-
do_sample=True,
|
18 |
-
temperature=0.7,
|
19 |
-
top_p=0.95,
|
20 |
-
pad_token_id=50256,
|
21 |
-
)[0]["generated_text"]
|
22 |
|
23 |
-
response = output.split("Бот:")[-1].strip().split("Пользователь:")[0].strip()
|
24 |
history.append((message, response))
|
25 |
return history
|
26 |
|
27 |
demo = gr.ChatInterface(
|
28 |
fn=respond,
|
29 |
-
|
30 |
-
|
31 |
-
examples=["Когда основан Университет Иннополис?", "
|
32 |
-
cache_examples=False #
|
33 |
)
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
demo.launch()
|
37 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Используем готовую модель — можно заменить на свою
|
5 |
+
pipe = pipeline("text-generation", model="tiiuae/falcon-rw-1b")
|
6 |
|
|
|
7 |
def respond(message, history):
|
8 |
+
history = history or []
|
9 |
+
full_prompt = "Ты — дружелюбный бот, знающий всё об Университете Иннополис.\n"
|
10 |
+
|
11 |
for user, bot in history:
|
12 |
+
full_prompt += f"Пользователь: {user}\nБот: {bot}\n"
|
13 |
+
full_prompt += f"Пользователь: {message}\nБот:"
|
14 |
|
15 |
+
output = pipe(full_prompt, max_new_tokens=200, pad_token_id=50256)[0]["generated_text"]
|
16 |
+
response = output.split("Бот:")[-1].split("Пользователь:")[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
18 |
history.append((message, response))
|
19 |
return history
|
20 |
|
21 |
demo = gr.ChatInterface(
|
22 |
fn=respond,
|
23 |
+
chatbot=gr.Chatbot(label="Innopolis Bot"),
|
24 |
+
title="Innopolis Chatbot",
|
25 |
+
examples=["Когда основан Университет Иннополис?", "Какие программы есть в магистратуре?"],
|
26 |
+
cache_examples=False # 💥 Ключевая строка, чтобы избежать ошибки
|
27 |
)
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
demo.launch()
|
|