elasko-aim commited on
Commit
fd22c23
·
verified ·
1 Parent(s): 7ffb666

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -43,26 +43,22 @@ def npc_chat():
43
  if not chat_history:
44
  chat_history.append(f"{npc_names[0]}: Welcome to Earth Web Space Networks!")
45
 
46
- while True:
47
- for i, npc in enumerate(npc_names):
48
- # Получаем последнее сообщение из истории
49
- last_message = chat_history[-1].split(": ", 1)[1]
50
-
51
- # Генерируем ответ
52
- response = generate_response(last_message)
53
- new_message = f"{npc}: {response}"
54
- chat_history.append(new_message)
55
-
56
- # Ограничение длины истории чата
57
- if len(chat_history) > 20:
58
- chat_history.pop(0)
59
-
60
- # Возвращаем текущую историю чата
61
- formatted_chat = "\n".join(chat_history)
62
- yield formatted_chat
63
-
64
- # Задержка для имитации реального времени
65
- time.sleep(2)
66
 
67
  # Gradio интерфейс
68
  with gr.Blocks() as demo:
@@ -71,7 +67,8 @@ with gr.Blocks() as demo:
71
  with gr.Row():
72
  chat_output = gr.Textbox(label="Chat History", lines=10, interactive=False)
73
 
74
- # Запуск бесконечного диалога между NPC
75
- demo.load(npc_chat, inputs=None, outputs=chat_output, every=2)
 
76
 
77
  demo.launch()
 
43
  if not chat_history:
44
  chat_history.append(f"{npc_names[0]}: Welcome to Earth Web Space Networks!")
45
 
46
+ for i, npc in enumerate(npc_names):
47
+ # Получаем последнее сообщение из истории
48
+ last_message = chat_history[-1].split(": ", 1)[1]
49
+
50
+ # Генерируем ответ
51
+ response = generate_response(last_message)
52
+ new_message = f"{npc}: {response}"
53
+ chat_history.append(new_message)
54
+
55
+ # Ограничение длины истории чата
56
+ if len(chat_history) > 20:
57
+ chat_history.pop(0)
58
+
59
+ # Возвращаем текущую историю чата
60
+ formatted_chat = "\n".join(chat_history)
61
+ return formatted_chat
 
 
 
 
62
 
63
  # Gradio интерфейс
64
  with gr.Blocks() as demo:
 
67
  with gr.Row():
68
  chat_output = gr.Textbox(label="Chat History", lines=10, interactive=False)
69
 
70
+ # Кнопка для обновления чата
71
+ update_button = gr.Button("Update Chat")
72
+ update_button.click(npc_chat, inputs=None, outputs=chat_output)
73
 
74
  demo.launch()