hiyouga commited on
Commit
e1e6dcd
1 Parent(s): ea4be8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -6,27 +6,17 @@ from threading import Thread
6
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
7
 
8
 
9
- TITLE = "<h1><center>LLaMA Board: A One-stop Web UI for Getting Started with LLaMA Factory</center></h1>"
10
-
11
- DESCRIPTION = "<h3><center>Visit <a href='' target='_blank'>LLaMA Factory</a> for details.</center></h3>"
12
-
13
- CSS = r"""
14
- .duplicate-button {
15
- margin: auto !important;
16
- color: white !important;
17
- background: black !important;
18
- border-radius: 100vh !important;
19
- }
20
- """
21
 
 
22
 
23
  tokenizer = AutoTokenizer.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat")
24
  model = AutoModelForCausalLM.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat", device_map="auto")
25
 
26
 
27
- @spaces.GPU(duration=120)
28
- def stream_chat(message: str, history: list, temperature: float, max_new_tokens: int):
29
- conversation = []
30
  for prompt, answer in history:
31
  conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
32
 
@@ -54,16 +44,17 @@ def stream_chat(message: str, history: list, temperature: float, max_new_tokens:
54
  yield output
55
 
56
 
57
- with gr.Blocks(fill_height=True, css=CSS) as demo:
58
- gr.HTML(TITLE)
59
- gr.HTML(DESCRIPTION)
60
- gr.DuplicateButton(value="Duplicate Space for private use", elem_classes="duplicate-button")
61
-
62
  gr.ChatInterface(
63
  fn=stream_chat,
64
  fill_height=True,
65
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
66
  additional_inputs=[
 
 
 
 
 
67
  gr.Slider(
68
  minimum=0,
69
  maximum=1,
@@ -82,13 +73,12 @@ with gr.Blocks(fill_height=True, css=CSS) as demo:
82
  ),
83
  ],
84
  examples=[
85
- ['How to setup a human base on Mars? Give short answer.'],
86
- ['Explain theory of relativity to me like I’m 8 years old.'],
87
- ['What is 9,000 * 9,000?'],
88
- ['Write a pun-filled happy birthday message to my friend Alex.'],
89
- ['Justify why a penguin might make a good king of the jungle.']
90
  ],
91
  cache_examples=False,
 
 
92
  )
93
 
94
 
 
6
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
7
 
8
 
9
+ TITLE = "Chat with Llama3-8B-Chinese"
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ DESCRIPTION = "Visit <a href='https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat' target='_blank'>our model page</a> for details."
12
 
13
  tokenizer = AutoTokenizer.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat")
14
  model = AutoModelForCausalLM.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat", device_map="auto")
15
 
16
 
17
+ @spaces.GPU
18
+ def stream_chat(message: str, history: list, system: str, temperature: float, max_new_tokens: int):
19
+ conversation = [{"role": "system", "content": system}]
20
  for prompt, answer in history:
21
  conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
22
 
 
44
  yield output
45
 
46
 
47
+ with gr.Blocks(fill_height=True) as demo:
 
 
 
 
48
  gr.ChatInterface(
49
  fn=stream_chat,
50
  fill_height=True,
51
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
52
  additional_inputs=[
53
+ gr.Text(
54
+ value="You are a helpful assistant.",
55
+ label="System",
56
+ render=False,
57
+ ),
58
  gr.Slider(
59
  minimum=0,
60
  maximum=1,
 
73
  ),
74
  ],
75
  examples=[
76
+ ["我的蓝牙耳机坏了,我该去看牙科还是耳鼻喉科?"],
77
+ ["今日行军进展如何", "扮演诸葛亮和我对话。"],
 
 
 
78
  ],
79
  cache_examples=False,
80
+ title=TITLE,
81
+ description=DESCRIPTION,
82
  )
83
 
84