SanAbdra commited on
Commit
4538a14
·
verified ·
1 Parent(s): 035de4a
Files changed (1) hide show
  1. app.py +22 -71
app.py CHANGED
@@ -3,37 +3,22 @@ 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 = ""
27
- for message in client.chat_completion(
28
  messages,
29
- max_tokens=max_tokens,
30
- stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
- ):
34
- token = message.choices[0].delta.content
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
@@ -46,53 +31,19 @@ calendar_system_message = """You are a calendar event parser assistant. Your tas
46
  "dateto": "2025-01-DD HH:mm",
47
  "description": "<improved event description>"
48
  }
 
49
 
50
- Rules for responses:
51
- - For Russian messages, provide event_name and description in Russian
52
- - For English messages, provide event_name and description in English
53
- - Always use grammar-correct, professional language
54
- - Make event names clear and concise
55
- - Add helpful details to descriptions
56
- - Use 24-hour time format (HH:mm)
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,
72
- maximum=2048,
73
- value=200,
74
- step=1,
75
- label="Max new tokens"
76
- ),
77
- gr.Slider(
78
- minimum=0.1,
79
- maximum=4.0,
80
- value=0.1,
81
- step=0.1,
82
- label="Temperature"
83
- ),
84
- gr.Slider(
85
- minimum=0.1,
86
- maximum=1.0,
87
- value=0.95,
88
- step=0.05,
89
- label="Top-p (nucleus sampling)"
90
- ),
91
  ],
 
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()
 
3
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
+ def process_event(text, system_message):
7
+ messages = [
8
+ {"role": "system", "content": system_message},
9
+ {"role": "user", "content": text}
10
+ ]
 
 
 
 
11
 
12
+ # Получаем ответ от модели
13
+ response = client.chat_completion(
 
 
 
 
 
 
 
 
 
 
14
  messages,
15
+ max_tokens=200,
16
+ temperature=0.1,
17
+ top_p=0.95,
18
+ )
19
+
20
+ # Возвращаем сгенерированный текст
21
+ return response.choices[0].content
 
22
 
23
  calendar_system_message = """You are a calendar event parser assistant. Your task is to:
24
  1. Understand the event description provided by the user
 
31
  "dateto": "2025-01-DD HH:mm",
32
  "description": "<improved event description>"
33
  }
34
+ """
35
 
36
+ # Создаем простой интерфейс
37
+ demo = gr.Interface(
38
+ fn=process_event,
39
+ inputs=[
40
+ gr.Textbox(label="Введите описание события / Enter event description"),
41
+ gr.Textbox(value=calendar_system_message, label="System message", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ],
43
+ outputs=gr.Textbox(label="Результат / Result"),
44
  title="Парсер событий календаря / Calendar Event Parser",
45
  description="Введите описание события, и я создам JSON для календаря / Enter event description and I will create a calendar JSON"
46
  )
47
 
 
48
  if __name__ == "__main__":
49
  demo.launch()