Chad commited on
Commit
da45833
·
1 Parent(s): aa1bfde
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -3,14 +3,7 @@ from huggingface_hub import InferenceClient
3
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
- def respond(
7
- message,
8
- history: list[tuple[str, str]],
9
- system_message,
10
- max_tokens,
11
- temperature,
12
- top_p,
13
- ):
14
  if history is None:
15
  history = []
16
 
@@ -25,13 +18,12 @@ def respond(
25
  messages.append({"role": "user", "content": message})
26
 
27
  response = ""
28
-
29
  for message in client.chat_completion(
30
  messages,
31
- max_tokens=max_tokens,
32
  stream=True,
33
- temperature=temperature,
34
- top_p=top_p,
35
  ):
36
  token = message.choices[0].delta.content
37
  response += token
@@ -42,18 +34,23 @@ demo = gr.ChatInterface(
42
  additional_inputs=[],
43
  examples=[
44
  ["How did the Leaning Tower of Pisa start leaning?"],
45
- ["Who built the Colosseum?"],
46
- ["What caused the fall of the Roman Empire?"],
47
- ["When did World War II begin and end?"],
48
- ["What was the significance of the Magna Carta?"],
49
  ["Comment la tour de Pise a-t-elle commencé à pencher ?"],
 
50
  ["Qui a construit le Colisée ?"],
 
51
  ["Quelles sont les causes de la chute de l'Empire romain ?"],
 
52
  ["Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?"],
 
53
  ["Quelle est l'importance de la Magna Carta ?"]
54
  ],
55
- cache_examples=False
56
  )
57
 
 
 
 
 
 
58
  if __name__ == "__main__":
59
  demo.launch()
 
3
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
+ def respond(message, history):
 
 
 
 
 
 
 
7
  if history is None:
8
  history = []
9
 
 
18
  messages.append({"role": "user", "content": message})
19
 
20
  response = ""
 
21
  for message in client.chat_completion(
22
  messages,
23
+ max_tokens=512,
24
  stream=True,
25
+ temperature=0.7,
26
+ top_p=0.95,
27
  ):
28
  token = message.choices[0].delta.content
29
  response += token
 
34
  additional_inputs=[],
35
  examples=[
36
  ["How did the Leaning Tower of Pisa start leaning?"],
 
 
 
 
37
  ["Comment la tour de Pise a-t-elle commencé à pencher ?"],
38
+ ["Who built the Colosseum?"],
39
  ["Qui a construit le Colisée ?"],
40
+ ["What caused the fall of the Roman Empire?"],
41
  ["Quelles sont les causes de la chute de l'Empire romain ?"],
42
+ ["When did World War II begin and end?"],
43
  ["Quand la Seconde Guerre mondiale a-t-elle commencé et terminé ?"],
44
+ ["What was the significance of the Magna Carta?"],
45
  ["Quelle est l'importance de la Magna Carta ?"]
46
  ],
47
+ cache_examples=False,
48
  )
49
 
50
+ clear_button = gr.Button("Clear Chat")
51
+ clear_button.click(lambda: None, None, demo.chatbot, queue=False)
52
+
53
+ demo = gr.Column([demo, clear_button])
54
+
55
  if __name__ == "__main__":
56
  demo.launch()