Update app.py
Browse files
app.py
CHANGED
|
@@ -9,26 +9,24 @@ DiarizationLM GGUF inference on CPU
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
model_path = "models"
|
| 12 |
-
|
| 13 |
-
model_name = "model-unsloth.BF16.gguf"
|
| 14 |
hf_hub_download(repo_id="google/DiarizationLM-13b-Fisher-v1", filename=model_name, local_dir=model_path, local_dir_use_symlinks=False)
|
| 15 |
|
| 16 |
print("Start the model init process")
|
| 17 |
-
model = GPT4All(model_name, model_path, allow_download = False, device="cpu")
|
| 18 |
print("Finish the model init process")
|
| 19 |
|
| 20 |
model.config["promptTemplate"] = "{0} --> "
|
| 21 |
model.config["systemPrompt"] = ""
|
| 22 |
model._is_chat_session_activated = False
|
| 23 |
|
| 24 |
-
max_new_tokens = 2048
|
| 25 |
-
|
| 26 |
print("Finish the model config process")
|
| 27 |
|
| 28 |
def generater(message, history, temperature, top_p, top_k):
|
| 29 |
prompt = model.config["promptTemplate"].format(message)
|
|
|
|
| 30 |
outputs = []
|
| 31 |
-
for token in model.generate(prompt=prompt, temp=
|
| 32 |
outputs.append(token)
|
| 33 |
yield "".join(outputs)
|
| 34 |
|
|
@@ -43,44 +41,12 @@ print("Create chatbot")
|
|
| 43 |
chatbot = gr.Chatbot()
|
| 44 |
print("Created chatbot")
|
| 45 |
|
| 46 |
-
print("Add additional_inputs")
|
| 47 |
-
additional_inputs=[
|
| 48 |
-
gr.Slider(
|
| 49 |
-
label="temperature",
|
| 50 |
-
value=0.0,
|
| 51 |
-
minimum=0.0,
|
| 52 |
-
maximum=2.0,
|
| 53 |
-
step=0.05,
|
| 54 |
-
interactive=True,
|
| 55 |
-
info="Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
|
| 56 |
-
),
|
| 57 |
-
gr.Slider(
|
| 58 |
-
label="top_p",
|
| 59 |
-
value=1.0,
|
| 60 |
-
minimum=0.0,
|
| 61 |
-
maximum=1.0,
|
| 62 |
-
step=0.01,
|
| 63 |
-
interactive=True,
|
| 64 |
-
info="0.1 means only the tokens comprising the top 10% probability mass are considered. Suggest set to 1 and use temperature. 1 means 100% and will disable it",
|
| 65 |
-
),
|
| 66 |
-
gr.Slider(
|
| 67 |
-
label="top_k",
|
| 68 |
-
value=50,
|
| 69 |
-
minimum=0,
|
| 70 |
-
maximum=1000,
|
| 71 |
-
step=1,
|
| 72 |
-
interactive=True,
|
| 73 |
-
info="limits candidate tokens to a fixed number after sorting by probability. Setting it higher than the vocabulary size deactivates this limit.",
|
| 74 |
-
)
|
| 75 |
-
]
|
| 76 |
-
print("Added additional_inputs")
|
| 77 |
-
|
| 78 |
iface = gr.ChatInterface(
|
| 79 |
fn = generater,
|
| 80 |
title=title,
|
| 81 |
description = description,
|
| 82 |
chatbot=chatbot,
|
| 83 |
-
additional_inputs=
|
| 84 |
examples=[
|
| 85 |
["<speaker:1> Hello, how are you doing <speaker:2> today? I am doing well."],
|
| 86 |
]
|
|
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
model_path = "models"
|
| 12 |
+
model_name = "q4_k_m.gguf"
|
|
|
|
| 13 |
hf_hub_download(repo_id="google/DiarizationLM-13b-Fisher-v1", filename=model_name, local_dir=model_path, local_dir_use_symlinks=False)
|
| 14 |
|
| 15 |
print("Start the model init process")
|
| 16 |
+
model = GPT4All(model_name=model_name, model_path=model_path, allow_download = False, device="cpu")
|
| 17 |
print("Finish the model init process")
|
| 18 |
|
| 19 |
model.config["promptTemplate"] = "{0} --> "
|
| 20 |
model.config["systemPrompt"] = ""
|
| 21 |
model._is_chat_session_activated = False
|
| 22 |
|
|
|
|
|
|
|
| 23 |
print("Finish the model config process")
|
| 24 |
|
| 25 |
def generater(message, history, temperature, top_p, top_k):
|
| 26 |
prompt = model.config["promptTemplate"].format(message)
|
| 27 |
+
max_new_tokens = round(len(prompt) / 3.0 * 1.2)
|
| 28 |
outputs = []
|
| 29 |
+
for token in model.generate(prompt=prompt, temp=0.0, top_k = 50, top_p = 0.9, max_tokens = max_new_tokens, streaming=True):
|
| 30 |
outputs.append(token)
|
| 31 |
yield "".join(outputs)
|
| 32 |
|
|
|
|
| 41 |
chatbot = gr.Chatbot()
|
| 42 |
print("Created chatbot")
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
iface = gr.ChatInterface(
|
| 45 |
fn = generater,
|
| 46 |
title=title,
|
| 47 |
description = description,
|
| 48 |
chatbot=chatbot,
|
| 49 |
+
additional_inputs=[],
|
| 50 |
examples=[
|
| 51 |
["<speaker:1> Hello, how are you doing <speaker:2> today? I am doing well."],
|
| 52 |
]
|