SanAbdra commited on
Commit
7aab6f6
·
verified ·
1 Parent(s): 4be97c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -31
app.py CHANGED
@@ -4,61 +4,61 @@ import re
4
 
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
- # Системное сообщение с инструкциями
8
- calendar_system_message = """You are a calendar event parser. Follow these rules STRICTLY:
9
 
10
- LANGUAGE RULES:
11
- - If input contains Cyrillic letters - respond in Russian ONLY
12
- - If input is in English - respond in English ONLY
13
- - Never mix languages in response
 
 
14
 
15
  DATE AND TIME RULES:
16
- - Today's date is 2025-01-02
17
- - All events should be scheduled in the future relative to today
18
- - If month is not specified, use next occurrence of that date
19
- - If only day is mentioned (like "7th"), use next occurrence in January 2025
20
- - Always use year 2025 for all dates
21
- - Format times in 24-hour format (HH:mm)
22
 
23
- FORMAT RULES:
24
- Return exactly this JSON with no additional text:
25
  {
26
- "event_name": "<name in same language as input>",
27
  "datefrom": "2025-01-DD HH:mm",
28
  "dateto": "2025-01-DD HH:mm",
29
- "description": "<description in same language as input>"
30
  }
31
 
32
- RUSSIAN INPUT EXAMPLE:
33
- Input: "встреча 7 числа в 15:00"
 
 
 
 
 
 
 
 
34
  Response:
35
  {
36
  "event_name": "Встреча",
37
  "datefrom": "2025-01-07 15:00",
38
  "dateto": "2025-01-07 16:00",
39
- "description": "Деловая встреча 7 января"
40
- }
41
-
42
- EXTRA RULES:
43
- - Keep all text fields in the EXACT same language as input
44
- - Fix grammar and spelling while keeping original language
45
- - NEVER translate event names or descriptions to another language
46
- - Make descriptions clear and professional in the original language
47
- - Always assume current year is 2025"""
48
 
49
  def detect_language(text):
50
- # Проверяем наличие кириллицы
51
  has_cyrillic = bool(re.search('[а-яА-Я]', text))
52
  return 'ru' if has_cyrillic else 'en'
53
 
54
  def process_event(text, system_message):
55
  lang = detect_language(text)
56
 
57
- # Добавляем явное указание языка в промпт
58
  if lang == 'ru':
59
- prompt = f"Ответ должен быть на русском языке. Текст события: {text}"
 
 
60
  else:
61
- prompt = f"Response must be in English. Event text: {text}"
62
 
63
  messages = [
64
  {"role": "system", "content": system_message},
@@ -71,6 +71,8 @@ def process_event(text, system_message):
71
  max_tokens=200,
72
  temperature=0.1,
73
  top_p=0.95,
 
 
74
  )
75
 
76
  generated_text = response.choices[0].message.content
 
4
 
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
+ calendar_system_message = """You are a calendar event parser with STRICT language rules.
 
8
 
9
+ CRITICAL LANGUAGE RULES (HIGHEST PRIORITY):
10
+ - If user input contains ANY Cyrillic letters - you MUST respond in Russian language
11
+ - If user input is in English - respond in English
12
+ - NEVER mix languages
13
+ - NEVER translate to another language
14
+ - The language of the input DICTATES the language of the output
15
 
16
  DATE AND TIME RULES:
17
+ - Current date: 2025-01-02
18
+ - All events MUST be in 2025
19
+ - If day number is less than today's date, use the next suitable month
20
+ - Use 24-hour time format (HH:mm)
 
 
21
 
22
+ FORMAT:
23
+ For Russian input, return ONLY:
24
  {
25
+ "event_name": "<название на РУССКОМ>",
26
  "datefrom": "2025-01-DD HH:mm",
27
  "dateto": "2025-01-DD HH:mm",
28
+ "description": "<описание на РУССКОМ>"
29
  }
30
 
31
+ For English input, return ONLY:
32
+ {
33
+ "event_name": "<name in ENGLISH>",
34
+ "datefrom": "2025-01-DD HH:mm",
35
+ "dateto": "2025-01-DD HH:mm",
36
+ "description": "<description in ENGLISH>"
37
+ }
38
+
39
+ EXAMPLES:
40
+ Russian input: "встреча 7 числа в 15:00"
41
  Response:
42
  {
43
  "event_name": "Встреча",
44
  "datefrom": "2025-01-07 15:00",
45
  "dateto": "2025-01-07 16:00",
46
+ "description": "Плановая встреча 7 января"
47
+ }"""
 
 
 
 
 
 
 
48
 
49
  def detect_language(text):
 
50
  has_cyrillic = bool(re.search('[а-яА-Я]', text))
51
  return 'ru' if has_cyrillic else 'en'
52
 
53
  def process_event(text, system_message):
54
  lang = detect_language(text)
55
 
 
56
  if lang == 'ru':
57
+ prompt = f"""СТРОГО на русском языке!
58
+ Если видишь кириллицу - ТОЛЬКО русский язык в ответе!
59
+ Текст события: {text}"""
60
  else:
61
+ prompt = f"Event text: {text}"
62
 
63
  messages = [
64
  {"role": "system", "content": system_message},
 
71
  max_tokens=200,
72
  temperature=0.1,
73
  top_p=0.95,
74
+ presence_penalty=0,
75
+ frequency_penalty=0
76
  )
77
 
78
  generated_text = response.choices[0].message.content