Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
top_p=top_p,
|
37 |
-
):
|
38 |
-
token = message.choices[0].delta.content
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
42 |
-
|
43 |
-
|
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 |
-
|
|
|
|
|
49 |
demo = gr.ChatInterface(
|
50 |
respond,
|
51 |
additional_inputs=[
|
52 |
-
gr.Textbox(value="
|
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()
|