theodotus commited on
Commit
d7c49f6
1 Parent(s): 1be71e1

Update app

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -6,29 +6,22 @@ import gradio as gr
6
 
7
 
8
  def generate_prompt(history):
9
- prompt = start_message
10
  for chain in history[:-1]:
11
- prompt += f"<|im_start|>user\n{chain[0]}<|im_end|>" +\
12
- f"<|im_start|>assistant\n{chain[1]}<|im_end|>"
13
- prompt += f"<|im_start|>user\n{history[-1][0]}<|im_end|>" +\
14
- "<|im_start|>assistant\n"
15
  return prompt
16
 
17
  def generate(history):
18
  prompt = generate_prompt(history)
19
 
20
- streamer = llm(prompt, stop = stop_tokens, stream=True, threads=2)
21
  return streamer
22
 
23
 
24
 
25
- llm = AutoModelForCausalLM.from_pretrained("model/ggml-model-q8_0.bin", model_type='mpt')
26
- stop_tokens = ["<|im_end|>", "<|endoftext|>"]
27
-
28
- start_message = """<|im_start|>system
29
- You are a helpful assistant chatbot.<|im_end|>
30
- """
31
-
32
 
33
 
34
  with gr.Blocks() as demo:
@@ -53,4 +46,4 @@ with gr.Blocks() as demo:
53
 
54
  demo.queue()
55
  if __name__ == "__main__":
56
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
6
 
7
 
8
  def generate_prompt(history):
9
+ prompt = "<s> "
10
  for chain in history[:-1]:
11
+ prompt += f"<human>: {chain[0]}\n<bot>: {chain[1]}{end_token}\n"
12
+ prompt += f"<human>: {history[-1][0]}\n<bot>: "
 
 
13
  return prompt
14
 
15
  def generate(history):
16
  prompt = generate_prompt(history)
17
 
18
+ streamer = llm(prompt, temperature=0, stream=True)
19
  return streamer
20
 
21
 
22
 
23
+ llm = AutoModelForCausalLM.from_pretrained("model/model_q4_0.bin", model_type='llama')
24
+ end_token = "</s>"
 
 
 
 
 
25
 
26
 
27
  with gr.Blocks() as demo:
 
46
 
47
  demo.queue()
48
  if __name__ == "__main__":
49
+ demo.launch()