SanAbdra commited on
Commit
035de4a
·
verified ·
1 Parent(s): af1a74d
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -1,25 +1,26 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """For more information on `huggingface_hub` Inference API support, please check the docs:
5
- https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""
6
-
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  def respond(
10
  message,
11
- history: list[tuple[str, str]],
12
  system_message,
13
  max_tokens,
14
  temperature,
15
  top_p,
16
  ):
17
  messages = [{"role": "system", "content": system_message}]
18
- for val in history:
19
- if val[0]:
20
- messages.append({"role": "user", "content": val[0]})
21
- if val[1]:
22
- messages.append({"role": "assistant", "content": val[1]})
 
 
 
 
23
  messages.append({"role": "user", "content": message})
24
 
25
  response = ""
@@ -34,9 +35,6 @@ def respond(
34
  response += token
35
  yield response
36
 
37
- """For information on how to customize the ChatInterface, peruse the gradio docs:
38
- https://www.gradio.app/docs/chatinterface"""
39
-
40
  calendar_system_message = """You are a calendar event parser assistant. Your task is to:
41
  1. Understand the event description provided by the user
42
  2. Always respond in the same language as the user's message
@@ -59,12 +57,15 @@ Rules for responses:
59
  - Always use 2025 as the year
60
  - Always return only the JSON object, no additional text"""
61
 
 
62
  demo = gr.ChatInterface(
63
- respond,
 
64
  additional_inputs=[
65
  gr.Textbox(
66
  value=calendar_system_message,
67
- label="System message"
 
68
  ),
69
  gr.Slider(
70
  minimum=1,
@@ -91,3 +92,7 @@ demo = gr.ChatInterface(
91
  title="Парсер событий календаря / Calendar Event Parser",
92
  description="Введите описание события, и я создам JSON для календаря / Enter event description and I will create a calendar JSON"
93
  )
 
 
 
 
 
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, # Убрали аннотацию типа для совместимости
9
  system_message,
10
  max_tokens,
11
  temperature,
12
  top_p,
13
  ):
14
  messages = [{"role": "system", "content": system_message}]
15
+
16
+ # Преобразуем историю в правильный формат
17
+ if history:
18
+ for user_msg, assistant_msg in history:
19
+ if user_msg:
20
+ messages.append({"role": "user", "content": user_msg})
21
+ if assistant_msg:
22
+ messages.append({"role": "assistant", "content": assistant_msg})
23
+
24
  messages.append({"role": "user", "content": message})
25
 
26
  response = ""
 
35
  response += token
36
  yield response
37
 
 
 
 
38
  calendar_system_message = """You are a calendar event parser assistant. Your task is to:
39
  1. Understand the event description provided by the user
40
  2. Always respond in the same language as the user's message
 
57
  - Always use 2025 as the year
58
  - Always return only the JSON object, no additional text"""
59
 
60
+ # Создаем интерфейс с новым форматом сообщений
61
  demo = gr.ChatInterface(
62
+ fn=respond,
63
+ chatbot=gr.Chatbot(height=400, type="messages"), # Указываем новый тип messages
64
  additional_inputs=[
65
  gr.Textbox(
66
  value=calendar_system_message,
67
+ label="System message",
68
+ visible=True # Делаем системное сообщение видимым
69
  ),
70
  gr.Slider(
71
  minimum=1,
 
92
  title="Парсер событий календаря / Calendar Event Parser",
93
  description="Введите описание события, и я создам JSON для календаря / Enter event description and I will create a calendar JSON"
94
  )
95
+
96
+ # Запускаем приложение
97
+ if __name__ == "__main__":
98
+ demo.launch()