Xolkin commited on
Commit
89224bc
·
verified ·
1 Parent(s): 9d2ff11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,12 +1,8 @@
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("HuggingFaceH4/zephyr-7b-beta")
8
 
9
-
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,9 +11,6 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
18
- # Установим приветственное сообщение для системы
19
- system_message = "Привет! Я помощник врача в больнице EMS штата Alta! Напиши внизу симптомы заболевания и я поставлю предварительный диагноз! И хирургическую операцию, если надо будет ее провести."
20
-
21
  messages = [{"role": "system", "content": system_message}]
22
 
23
  for val in history:
@@ -38,30 +31,40 @@ def respond(
38
  top_p=top_p,
39
  ):
40
  token = message.choices[0].delta.content
41
-
42
  response += token
43
  yield response
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- """
47
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
48
- """
49
  demo = gr.ChatInterface(
50
  respond,
51
  additional_inputs=[
52
- gr.Textbox(value="You are a friendly Chatbot.", 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(
56
  minimum=0.1,
57
  maximum=1.0,
58
  value=0.95,
59
  step=0.05,
60
- label="Top-p (nucleus sampling)",
61
  ),
62
  ],
63
  )
64
 
65
-
66
  if __name__ == "__main__":
67
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
 
6
  def respond(
7
  message,
8
  history: list[tuple[str, str]],
 
11
  temperature,
12
  top_p,
13
  ):
 
 
 
14
  messages = [{"role": "system", "content": system_message}]
15
 
16
  for val in history:
 
31
  top_p=top_p,
32
  ):
33
  token = message.choices[0].delta.content
 
34
  response += token
35
  yield response
36
 
37
+ # Highlight the diagnosis in bold
38
+ diagnosis_start = response.find("Предварительный диагноз:")
39
+ if diagnosis_start != -1:
40
+ diagnosis_end = response.find("\n", diagnosis_start)
41
+ if diagnosis_end == -1:
42
+ diagnosis_end = len(response)
43
+ diagnosis = response[diagnosis_start:diagnosis_end]
44
+ response = response[:diagnosis_start] + f"<b>{diagnosis}</b>" + response[diagnosis_end:]
45
+
46
+ # Add an identification message to the response
47
+ final_response = f"{response}\n\nСоздано больницей EMS штата Alta"
48
+ yield final_response
49
 
 
 
 
50
  demo = gr.ChatInterface(
51
  respond,
52
  additional_inputs=[
53
+ gr.Textbox(
54
+ value="Привет! Я помощник врача в больнице EMS штата Alta! Опиши свои симптомы, и я поставлю предварительный диагноз.",
55
+ label="Системное сообщение"
56
+ ),
57
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Максимальное количество новых токенов"),
58
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Температура"),
59
  gr.Slider(
60
  minimum=0.1,
61
  maximum=1.0,
62
  value=0.95,
63
  step=0.05,
64
+ label="Top-p (ядерное семплирование)",
65
  ),
66
  ],
67
  )
68
 
 
69
  if __name__ == "__main__":
70
  demo.launch()