Chris STC
commited on
Commit
·
1a1c368
1
Parent(s):
7271938
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,22 @@ os.system('CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install llama-cpp-
|
|
| 4 |
import wget
|
| 5 |
from llama_cpp import Llama
|
| 6 |
import random
|
| 7 |
-
|
| 8 |
url = 'https://huggingface.co/TheBloke/WizardLM-7B-uncensored-GGML/resolve/main/WizardLM-7B-uncensored.ggmlv3.q2_K.bin'
|
| 9 |
filename = wget.download(url)
|
| 10 |
llm2 = Llama(model_path=filename, seed=random.randint(1, 2**31))
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
title = """<h1 align="center">Chat with awesome WizardLM 7b model!</h1><br>"""
|
| 13 |
-
with gr.Blocks(theme=
|
| 14 |
gr.HTML(title)
|
| 15 |
-
gr.HTML("This model is awesome for its size! It is only 20th the size of Chatgpt but is around 90% as good as Chatgpt. However, please don't rely on WizardLM to provide 100% true information as it might be wrong sometimes.")
|
| 16 |
chatbot = gr.Chatbot()
|
| 17 |
msg = gr.Textbox()
|
| 18 |
clear = gr.ClearButton([msg, chatbot])
|
|
|
|
| 19 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, default=0.72, step=0.01, label="Temperature")
|
| 20 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, default=0.73, step=0.01, label="Top-p")
|
| 21 |
top_k = gr.Slider(minimum=1, maximum=100, default=50, step=1, label="Top-k")
|
|
@@ -25,14 +29,18 @@ with gr.Blocks(theme=gr.themes.clean) as demo:
|
|
| 25 |
return gr.update(value="", interactive=True), history + [[user_message, None]]
|
| 26 |
|
| 27 |
def bot(history):
|
|
|
|
| 28 |
user_message = history[-1][0]
|
|
|
|
|
|
|
|
|
|
| 29 |
tokens3 = llm2.tokenize(user_message.encode())
|
| 30 |
token4 = llm2.tokenize(b"\n\n### Response:")
|
| 31 |
tokens = tokens3 + token4
|
| 32 |
history[-1][1] = ""
|
| 33 |
count = 0
|
| 34 |
output = ""
|
| 35 |
-
for token in llm2.generate(tokens, top_k=top_k
|
| 36 |
text = llm2.detokenize([token])
|
| 37 |
output += text.decode()
|
| 38 |
count += 1
|
|
|
|
| 4 |
import wget
|
| 5 |
from llama_cpp import Llama
|
| 6 |
import random
|
|
|
|
| 7 |
url = 'https://huggingface.co/TheBloke/WizardLM-7B-uncensored-GGML/resolve/main/WizardLM-7B-uncensored.ggmlv3.q2_K.bin'
|
| 8 |
filename = wget.download(url)
|
| 9 |
llm2 = Llama(model_path=filename, seed=random.randint(1, 2**31))
|
| 10 |
+
filename = wget.download(url)
|
| 11 |
+
theme = gr.themes.Soft(
|
| 12 |
+
primary_hue=gr.themes.Color("#ededed", "#fee2e2", "#fecaca", "#fca5a5", "#f87171", "#ef4444", "#dc2626", "#b91c1c", "#991b1b", "#7f1d1d", "#6c1e1e"),
|
| 13 |
+
neutral_hue="red",
|
| 14 |
+
)
|
| 15 |
title = """<h1 align="center">Chat with awesome WizardLM 7b model!</h1><br>"""
|
| 16 |
+
with gr.Blocks(theme=theme) as demo:
|
| 17 |
gr.HTML(title)
|
| 18 |
+
gr.HTML("This model is awesome for its size! It is only 20th the size of Chatgpt but is around 90% as good as Chatgpt. However, please don't rely on WizardLM to provide 100% true information as it might be wrong sometimes. ")
|
| 19 |
chatbot = gr.Chatbot()
|
| 20 |
msg = gr.Textbox()
|
| 21 |
clear = gr.ClearButton([msg, chatbot])
|
| 22 |
+
instruction = gr.Textbox(label="Instruction", placeholder=)
|
| 23 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, default=0.72, step=0.01, label="Temperature")
|
| 24 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, default=0.73, step=0.01, label="Top-p")
|
| 25 |
top_k = gr.Slider(minimum=1, maximum=100, default=50, step=1, label="Top-k")
|
|
|
|
| 29 |
return gr.update(value="", interactive=True), history + [[user_message, None]]
|
| 30 |
|
| 31 |
def bot(history):
|
| 32 |
+
instruction = history[-1][1] or ""
|
| 33 |
user_message = history[-1][0]
|
| 34 |
+
token1 = llm.tokenize(b"### Instruction: ")
|
| 35 |
+
token2 = llm.tokenize(instruction.encode())
|
| 36 |
+
token3 = llm2.tokenize(b"USER: ")
|
| 37 |
tokens3 = llm2.tokenize(user_message.encode())
|
| 38 |
token4 = llm2.tokenize(b"\n\n### Response:")
|
| 39 |
tokens = tokens3 + token4
|
| 40 |
history[-1][1] = ""
|
| 41 |
count = 0
|
| 42 |
output = ""
|
| 43 |
+
for token in llm2.generate(tokens, top_k=top_k, top_p=top_p, temp=temperature, repeat_penalty=repeat_penalty):
|
| 44 |
text = llm2.detokenize([token])
|
| 45 |
output += text.decode()
|
| 46 |
count += 1
|