Canstralian commited on
Commit
bc15f0b
1 Parent(s): 141b33f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -6,7 +6,6 @@ For more information on `huggingface_hub` Inference API support, please check th
6
  """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
-
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,8 +14,11 @@ def respond(
15
  temperature,
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]})
@@ -27,6 +29,7 @@ def respond(
27
 
28
  response = ""
29
 
 
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,7 +38,6 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
@@ -46,7 +48,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
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(
 
6
  """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
9
  def respond(
10
  message,
11
  history: list[tuple[str, str]],
 
14
  temperature,
15
  top_p,
16
  ):
17
+ # Set the default system message to the friendly Python chatbot message
18
+ system_message = system_message or "You are a friendly Python code writing Chatbot. Assist with Python programming tasks, debugging, and code optimization. Provide solutions for Python-related queries, help with libraries, algorithms, and best practices, and generate clean, efficient code for various applications."
19
+
20
+ # Prepare the conversation history and current message
21
  messages = [{"role": "system", "content": system_message}]
 
22
  for val in history:
23
  if val[0]:
24
  messages.append({"role": "user", "content": val[0]})
 
29
 
30
  response = ""
31
 
32
+ # Request the response from the model
33
  for message in client.chat_completion(
34
  messages,
35
  max_tokens=max_tokens,
 
38
  top_p=top_p,
39
  ):
40
  token = message.choices[0].delta.content
 
41
  response += token
42
  yield response
43
 
 
48
  demo = gr.ChatInterface(
49
  respond,
50
  additional_inputs=[
51
+ gr.Textbox(value="You are a friendly Python code writing Chatbot. Assist with Python programming tasks, debugging, and code optimization. Provide solutions for Python-related queries, help with libraries, algorithms, and best practices, and generate clean, efficient code for various applications.", label="System message"),
52
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
  gr.Slider(