liang-huggingface commited on
Commit
048277f
1 Parent(s): 14878fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,15 +1,20 @@
1
  import gradio as gr
2
  import os
3
  from pathlib import Path
 
 
 
 
4
  import argparse
5
- model_file = "yi-chat-6b.Q3_K_M.gguf"
6
  if not os.path.isfile(model_file):
7
- os.system("wget -c https://huggingface.co/XeIaso/yi-chat-6B-GGUF/blob/main/yi-chat-6b.Q3_K_M.gguf")
8
 
9
  DEFAULT_MODEL_PATH = model_file
10
 
11
  from llama_cpp import Llama
12
  llm = Llama(model_path=model_file, model_type="mistral")
 
13
 
14
 
15
  def predict(input, chatbot, max_length, top_p, temperature, history):
@@ -17,7 +22,7 @@ def predict(input, chatbot, max_length, top_p, temperature, history):
17
  response = ""
18
  history.append(input)
19
 
20
- for output in llm(input, stream=True, temperature=temperature, top_p=top_p, max_tokens=max_length, ):
21
  piece = output['choices'][0]['text']
22
  response += piece
23
  chatbot[-1] = (chatbot[-1][0], response)
@@ -37,7 +42,7 @@ def reset_state():
37
 
38
 
39
  with gr.Blocks() as demo:
40
- gr.HTML("""<h1 align="center">Yi-6B-GGUF by llama-cpp-python</h1>""")
41
 
42
  chatbot = gr.Chatbot()
43
  with gr.Row():
 
1
  import gradio as gr
2
  import os
3
  from pathlib import Path
4
+
5
+ os.environ["CMAKE_ARGS"] = "-DLLAMA_CUBLAS=on"
6
+ os.system('CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python[server]')
7
+
8
  import argparse
9
+ model_file = "yi-chat-6b.Q4_K_M.gguf"
10
  if not os.path.isfile(model_file):
11
+ os.system("wget -c https://huggingface.co/XeIaso/yi-chat-6B-GGUF/resolve/main/yi-chat-6b.Q4_K_M.gguf")
12
 
13
  DEFAULT_MODEL_PATH = model_file
14
 
15
  from llama_cpp import Llama
16
  llm = Llama(model_path=model_file, model_type="mistral")
17
+ llm._token_eos = 7
18
 
19
 
20
  def predict(input, chatbot, max_length, top_p, temperature, history):
 
22
  response = ""
23
  history.append(input)
24
 
25
+ for output in llm(input, stream=True, temperature=temperature, top_p=top_p, max_tokens=max_length, stop=["<|im_end|>"]):
26
  piece = output['choices'][0]['text']
27
  response += piece
28
  chatbot[-1] = (chatbot[-1][0], response)
 
42
 
43
 
44
  with gr.Blocks() as demo:
45
+ gr.HTML("""<h1 align="center">Yi-6B-Chat by llama-cpp-python</h1>""")
46
 
47
  chatbot = gr.Chatbot()
48
  with gr.Row():