Xolkin commited on
Commit
8d3c493
·
verified ·
1 Parent(s): e712661

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -25
app.py CHANGED
@@ -1,8 +1,11 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Инициализация клиента для взаимодействия с моделью
5
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
6
 
7
  def respond(
8
  message,
@@ -12,7 +15,6 @@ def respond(
12
  temperature,
13
  top_p,
14
  ):
15
- # Формирование списка сообщений для отправки в модель
16
  messages = [{"role": "system", "content": system_message}]
17
 
18
  for val in history:
@@ -23,33 +25,28 @@ def respond(
23
 
24
  messages.append({"role": "user", "content": message})
25
 
26
- # Проверка на приветствие
27
- if message.lower() in ["привет", "здравствуйте", "hello", "hi"]:
28
- response = "Привет! Как я могу помочь вам сегодня? Пожалуйста, опишите симптомы."
29
- else:
30
- response = ""
31
- for message in client.chat_completion(
32
- messages,
33
- max_tokens=max_tokens,
34
- stream=True,
35
- temperature=temperature,
36
- top_p=top_p,
37
- ):
38
- token = message.choices[0].delta.content
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=[
52
- gr.Textbox(value="Привет. Я помощник врача! Предварительный диагноз: Операция: (требуется или нет, то какая)", label="System message"),
53
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
  gr.Slider(
@@ -62,5 +59,6 @@ demo = gr.ChatInterface(
62
  ],
63
  )
64
 
 
65
  if __name__ == "__main__":
66
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ """
5
+ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
+ """
7
+ client = InferenceClient("google/gemma-3-27b-it")
8
+
9
 
10
  def respond(
11
  message,
 
15
  temperature,
16
  top_p,
17
  ):
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
 
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
+ response = ""
29
+
30
+ for message in client.chat_completion(
31
+ messages,
32
+ max_tokens=max_tokens,
33
+ stream=True,
34
+ temperature=temperature,
35
+ top_p=top_p,
36
+ ):
37
+ token = message.choices[0].delta.content
 
 
 
 
 
38
 
39
+ response += token
40
+ yield response
 
41
 
 
42
 
43
+ """
44
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
+ """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
+ gr.Textbox(value="Здравствуйте. Я помошник врача больницы штата Alta! Опишите симптомы заболевания пациента, я дам вам кратко предварительный диагноз и операция, если она требуется..", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
  gr.Slider(
 
59
  ],
60
  )
61
 
62
+
63
  if __name__ == "__main__":
64
+ demo.launch()