Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
Для получения дополнительной информации о поддержке Inference API в `huggingface_hub` ознакомьтесь с документацией: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
def respond(
|
@@ -14,6 +12,7 @@ def respond(
|
|
14 |
temperature,
|
15 |
top_p,
|
16 |
):
|
|
|
17 |
messages = [{"role": "system", "content": system_message}]
|
18 |
|
19 |
for val in history:
|
@@ -26,7 +25,7 @@ def respond(
|
|
26 |
|
27 |
# Проверка на приветствие
|
28 |
if message.lower() in ["привет", "здравствуйте", "hello", "hi"]:
|
29 |
-
response = "Привет! Как я могу помочь вам сегодня?"
|
30 |
else:
|
31 |
response = ""
|
32 |
for message in client.chat_completion(
|
@@ -40,15 +39,13 @@ def respond(
|
|
40 |
response += token
|
41 |
yield response
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
yield response
|
48 |
|
49 |
-
|
50 |
-
Для получения информации о том, как настроить ChatInterface, ознакомьтесь с документацией gradio: https://www.gradio.app/docs/chatinterface
|
51 |
-
"""
|
52 |
demo = gr.ChatInterface(
|
53 |
respond,
|
54 |
additional_inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Инициализация клиента для взаимодействия с моделью
|
|
|
|
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
7 |
def respond(
|
|
|
12 |
temperature,
|
13 |
top_p,
|
14 |
):
|
15 |
+
# Формирование списка сообщений для отправки в модель
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
|
18 |
for val in history:
|
|
|
25 |
|
26 |
# Проверка на приветствие
|
27 |
if message.lower() in ["привет", "здравствуйте", "hello", "hi"]:
|
28 |
+
response = "Привет! Как я могу помочь вам сегодня? Пожалуйста, опишите симптомы."
|
29 |
else:
|
30 |
response = ""
|
31 |
for message in client.chat_completion(
|
|
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
+
# Форматирование ответа
|
43 |
+
if "предварительный диагноз" in message.lower() or "операция" in message.lower():
|
44 |
+
response = f"Диагноз предварительный: {response.split('Диагноз предварительный:')[-1].split(',')[0].strip()}, Операция: {response.split('Операция:')[-1].split(',')[0].strip()}, Лечение: {response.split('Лечение:')[-1].strip()}"
|
45 |
|
46 |
yield response
|
47 |
|
48 |
+
# Создание интерфейса чата с помощью Gradio
|
|
|
|
|
49 |
demo = gr.ChatInterface(
|
50 |
respond,
|
51 |
additional_inputs=[
|