SanAbdra commited on
Commit
af1a74d
·
verified ·
1 Parent(s): c4565d6

ForMyClickTime

Browse files
Files changed (1) hide show
  1. app.py +48 -19
app.py CHANGED
@@ -1,11 +1,10 @@
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
 
10
  def respond(
11
  message,
@@ -16,17 +15,14 @@ def respond(
16
  top_p,
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
-
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
-
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = ""
29
-
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,30 +31,63 @@ 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(
53
  minimum=0.1,
54
  maximum=1.0,
55
  value=0.95,
56
  step=0.05,
57
- label="Top-p (nucleus sampling)",
58
  ),
59
  ],
 
 
60
  )
61
-
62
-
63
- if __name__ == "__main__":
64
- demo.launch()
 
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,
 
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 = ""
 
26
  for message in client.chat_completion(
27
  messages,
28
  max_tokens=max_tokens,
 
31
  top_p=top_p,
32
  ):
33
  token = message.choices[0].delta.content
 
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
43
+ 3. Fix any grammar mistakes in event names and descriptions
44
+ 4. Return ONLY a valid JSON object with this exact format:
45
+ {
46
+ "event_name": "<corrected event name>",
47
+ "datefrom": "2025-01-DD HH:mm",
48
+ "dateto": "2025-01-DD HH:mm",
49
+ "description": "<improved event description>"
50
+ }
51
+
52
+ Rules for responses:
53
+ - For Russian messages, provide event_name and description in Russian
54
+ - For English messages, provide event_name and description in English
55
+ - Always use grammar-correct, professional language
56
+ - Make event names clear and concise
57
+ - Add helpful details to descriptions
58
+ - Use 24-hour time format (HH:mm)
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,
71
+ maximum=2048,
72
+ value=200,
73
+ step=1,
74
+ label="Max new tokens"
75
+ ),
76
+ gr.Slider(
77
+ minimum=0.1,
78
+ maximum=4.0,
79
+ value=0.1,
80
+ step=0.1,
81
+ label="Temperature"
82
+ ),
83
  gr.Slider(
84
  minimum=0.1,
85
  maximum=1.0,
86
  value=0.95,
87
  step=0.05,
88
+ label="Top-p (nucleus sampling)"
89
  ),
90
  ],
91
+ title="Парсер событий календаря / Calendar Event Parser",
92
+ description="Введите описание события, и я создам JSON для календаря / Enter event description and I will create a calendar JSON"
93
  )