cody82 commited on
Commit
aa7f14e
·
verified ·
1 Parent(s): 12a57f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -1,21 +1,14 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import spaces # обязательно для ZeroGPU
4
 
5
- # Модель (CPU-friendly)
6
  qa_pipeline = pipeline("text-generation", model="tiiuae/falcon-rw-1b")
7
 
8
- # Основной обработчик
9
- @spaces.GPU # 👈 обязательно для ZeroGPU, даже если модель на CPU
10
  def respond(message, history):
11
- system_prompt = (
12
- "Ты дружелюбный бот, который отлично знает Университет Иннополис. "
13
- "Отвечай чётко и по делу на вопросы про университет, город Иннополис, обучение и студенческую жизнь.\n"
14
- )
15
-
16
- prompt = system_prompt
17
- for user_msg, bot_msg in history:
18
- prompt += f"Пользователь: {user_msg}\nБот: {bot_msg}\n"
19
  prompt += f"Пользователь: {message}\nБот:"
20
 
21
  output = qa_pipeline(
@@ -31,13 +24,14 @@ def respond(message, history):
31
  history.append((message, response))
32
  return history
33
 
34
- # Интерфейс
35
  demo = gr.ChatInterface(
36
  fn=respond,
37
  title="Innopolis Bot",
38
  theme="soft",
39
  examples=["Когда основан Университет Иннополис?", "Как поступить в магистратуру?"],
 
40
  )
41
 
42
  if __name__ == "__main__":
43
  demo.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import spaces
4
 
 
5
  qa_pipeline = pipeline("text-generation", model="tiiuae/falcon-rw-1b")
6
 
7
+ @spaces.GPU
 
8
  def respond(message, history):
9
+ prompt = "Ты — дружелюбный бот, знающий всё об Университете Иннополис.\n"
10
+ for user, bot in history:
11
+ prompt += f"Пользователь: {user}\nБот: {bot}\n"
 
 
 
 
 
12
  prompt += f"Пользователь: {message}\nБот:"
13
 
14
  output = qa_pipeline(
 
24
  history.append((message, response))
25
  return history
26
 
 
27
  demo = gr.ChatInterface(
28
  fn=respond,
29
  title="Innopolis Bot",
30
  theme="soft",
31
  examples=["Когда основан Университет Иннополис?", "Как поступить в магистратуру?"],
32
+ cache_examples=False # 🛠 Отключаем сохранение длинной истории
33
  )
34
 
35
  if __name__ == "__main__":
36
  demo.launch()
37
+