Leo8613 commited on
Commit
4cdd699
·
verified ·
1 Parent(s): 9a193c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -1,27 +1,23 @@
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,
12
  history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
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]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
 
26
  messages.append({"role": "user", "content": message})
27
 
@@ -35,13 +31,9 @@ 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
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
  demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
@@ -58,6 +50,5 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
61
-
62
  if __name__ == "__main__":
63
- demo.launch()
 
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: str,
8
  history: list[tuple[str, str]],
9
+ system_message: str,
10
+ max_tokens: int,
11
+ temperature: float,
12
+ top_p: float,
13
  ):
14
  messages = [{"role": "system", "content": system_message}]
15
 
16
+ for user_message, assistant_message in history:
17
+ if user_message:
18
+ messages.append({"role": "user", "content": user_message})
19
+ if assistant_message:
20
+ messages.append({"role": "assistant", "content": assistant_message})
21
 
22
  messages.append({"role": "user", "content": message})
23
 
 
31
  top_p=top_p,
32
  ):
33
  token = message.choices[0].delta.content
 
34
  response += token
35
  yield response
36
 
 
 
 
37
  demo = gr.ChatInterface(
38
  respond,
39
  additional_inputs=[
 
50
  ],
51
  )
52
 
 
53
  if __name__ == "__main__":
54
+ demo.launch()