Makaria commited on
Commit
bd7ac30
·
1 Parent(s): e091083
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
- # Получаем токен из переменных окружения
6
  client = InferenceClient(os.getenv("HUGGINGFACE_TOKEN"))
7
 
8
  def respond(
@@ -25,23 +25,28 @@ def respond(
25
 
26
  response = ""
27
 
28
- for message in client.chat_completion(
29
- messages,
30
- max_tokens=max_tokens,
31
- stream=True,
32
- temperature=temperature,
33
- top_p=top_p,
34
- ):
35
- token = message.choices[0].delta.content
36
- response += token
37
- yield response
 
 
 
 
 
38
 
39
  demo = gr.ChatInterface(
40
  respond,
41
  additional_inputs=[
42
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
43
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
44
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
45
  gr.Slider(
46
  minimum=0.1,
47
  maximum=1.0,
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Инициализация клиента с токеном
6
  client = InferenceClient(os.getenv("HUGGINGFACE_TOKEN"))
7
 
8
  def respond(
 
25
 
26
  response = ""
27
 
28
+ try:
29
+ for message in client.chat_completion(
30
+ model="sambanovasystems/SambaLingo-Russian-Chat",
31
+ messages=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
+ response += token
39
+ yield response
40
+ except Exception as e:
41
+ print(f"Error: {e}")
42
+ yield "Произошла ошибка при обработке вашего запроса."
43
 
44
  demo = gr.ChatInterface(
45
  respond,
46
  additional_inputs=[
47
+ gr.Textbox(value="Ты дружелюбный чат-бот.", label="Системное сообщение"),
48
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Максимум новых токенов"),
49
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Температура"),
50
  gr.Slider(
51
  minimum=0.1,
52
  maximum=1.0,