Markusa-14 commited on
Commit
51ca12d
·
verified ·
1 Parent(s): a226980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,9 +1,6 @@
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
 
@@ -15,6 +12,10 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
 
 
 
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
@@ -27,6 +28,7 @@ def respond(
27
 
28
  response = ""
29
 
 
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,18 +37,18 @@ def respond(
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="You are a friendly Chatbot.", 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(
@@ -62,3 +64,4 @@ demo = gr.ChatInterface(
62
 
63
  if __name__ == "__main__":
64
  demo.launch()
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
 
 
12
  temperature,
13
  top_p,
14
  ):
15
+ # Добавляем инструкцию для поддержки многоязычности
16
+ system_message = system_message or "You are a multilingual assistant. Respond in the user's language and provide clear, correct answers."
17
+
18
+ # Составляем историю сообщений для отправки модели
19
  messages = [{"role": "system", "content": system_message}]
20
 
21
  for val in history:
 
28
 
29
  response = ""
30
 
31
+ # Генерация ответа с потоковой выдачей токенов
32
  for message in client.chat_completion(
33
  messages,
34
  max_tokens=max_tokens,
 
37
  top_p=top_p,
38
  ):
39
  token = message.choices[0].delta.content
 
40
  response += token
41
  yield response
42
 
43
 
44
+ # Интерфейс Gradio с дополнительными настройками
 
 
45
  demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
48
+ gr.Textbox(
49
+ value="You are a multilingual assistant. Respond in the user's language and provide clear, correct answers.",
50
+ label="System message",
51
+ ),
52
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
  gr.Slider(
 
64
 
65
  if __name__ == "__main__":
66
  demo.launch()
67
+