Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,13 +15,20 @@ except requests.exceptions.RequestException as e:
|
|
15 |
css = " h1{text-align:center} /* Дополнительные стили, если нужны */" # Используем базовый стиль, если загрузка CSS не удалась
|
16 |
|
17 |
# Функция для отправки запроса к API searchgpt
|
18 |
-
def chat_with_searchgpt(
|
19 |
api_url = "https://text.pollinations.ai/searchgpt"
|
20 |
headers = {
|
21 |
"Content-Type": "application/json"
|
22 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
data = {
|
24 |
-
"
|
25 |
}
|
26 |
|
27 |
try:
|
@@ -32,8 +39,8 @@ def chat_with_searchgpt(prompt, history):
|
|
32 |
except requests.exceptions.RequestException as e:
|
33 |
bot_reply = f"Ошибка при запросе к API: {e}"
|
34 |
|
35 |
-
history.append((
|
36 |
-
return history,
|
37 |
|
38 |
# Определение интерфейса
|
39 |
with gr.Blocks(css=css) as demo:
|
@@ -44,11 +51,11 @@ with gr.Blocks(css=css) as demo:
|
|
44 |
|
45 |
# Функция для очистки чата
|
46 |
def clear_chat():
|
47 |
-
return [],
|
48 |
|
49 |
# Обработка отправки сообщения
|
50 |
msg.submit(chat_with_searchgpt, [msg, chatbot], [chatbot, msg], concurrency_limit=250)
|
51 |
clear.click(clear_chat, None, [chatbot, msg], concurrency_limit=250)
|
52 |
|
53 |
# Запуск интерфейса
|
54 |
-
demo.launch(show_api=False, share=False)
|
|
|
15 |
css = " h1{text-align:center} /* Дополнительные стили, если нужны */" # Используем базовый стиль, если загрузка CSS не удалась
|
16 |
|
17 |
# Функция для отправки запроса к API searchgpt
|
18 |
+
def chat_with_searchgpt(user_message, history):
|
19 |
api_url = "https://text.pollinations.ai/searchgpt"
|
20 |
headers = {
|
21 |
"Content-Type": "application/json"
|
22 |
}
|
23 |
+
# Формируем массив сообщений
|
24 |
+
messages = []
|
25 |
+
for msg in history:
|
26 |
+
messages.append({"role": "user", "content": msg[0]})
|
27 |
+
messages.append({"role": "assistant", "content": msg[1]})
|
28 |
+
messages.append({"role": "user", "content": user_message})
|
29 |
+
|
30 |
data = {
|
31 |
+
"messages": messages
|
32 |
}
|
33 |
|
34 |
try:
|
|
|
39 |
except requests.exceptions.RequestException as e:
|
40 |
bot_reply = f"Ошибка при запросе к API: {e}"
|
41 |
|
42 |
+
history.append((user_message, bot_reply))
|
43 |
+
return history, ""
|
44 |
|
45 |
# Определение интерфейса
|
46 |
with gr.Blocks(css=css) as demo:
|
|
|
51 |
|
52 |
# Функция для очистки чата
|
53 |
def clear_chat():
|
54 |
+
return [], ""
|
55 |
|
56 |
# Обработка отправки сообщения
|
57 |
msg.submit(chat_with_searchgpt, [msg, chatbot], [chatbot, msg], concurrency_limit=250)
|
58 |
clear.click(clear_chat, None, [chatbot, msg], concurrency_limit=250)
|
59 |
|
60 |
# Запуск интерфейса
|
61 |
+
demo.launch(show_api=False, share=False)
|