Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,34 +26,27 @@ def get_system_tokens(model):
|
|
26 |
return get_message_tokens(model, **system_message)
|
27 |
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
model_name = "model-q4_K.gguf"
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
use_mmap=True,
|
51 |
-
use_mlock=False,
|
52 |
-
n_ctx=2000,
|
53 |
-
)
|
54 |
-
print("Model loaded!")
|
55 |
-
|
56 |
-
max_new_tokens = 1500
|
57 |
|
58 |
|
59 |
def user(message, history):
|
@@ -92,7 +85,7 @@ def bot(
|
|
92 |
|
93 |
partial_text = ""
|
94 |
for i, token in enumerate(generator):
|
95 |
-
if token == model.token_eos()
|
96 |
break
|
97 |
partial_text += model.detokenize([token]).decode("utf-8", "ignore")
|
98 |
history[-1][1] = partial_text
|
@@ -116,7 +109,7 @@ with gr.Blocks(
|
|
116 |
with gr.Row():
|
117 |
with gr.Column(scale=5):
|
118 |
system_prompt = gr.Textbox(label="Системный промпт", placeholder="", value=SYSTEM_PROMPT, interactive=False)
|
119 |
-
chatbot = gr.Chatbot(label="Диалог"
|
120 |
with gr.Column(min_width=80, scale=1):
|
121 |
with gr.Tab(label="Параметры генерации"):
|
122 |
top_p = gr.Slider(
|
|
|
26 |
return get_message_tokens(model, **system_message)
|
27 |
|
28 |
|
29 |
+
def load_model(
|
30 |
+
directory: str = ".",
|
31 |
+
model_name: str = "model-q4_K.gguf",
|
32 |
+
model_url: str = "https://huggingface.co/IlyaGusev/saiga_mistral_7b_gguf/resolve/main/model-q4_K.gguf"
|
33 |
+
):
|
34 |
+
final_model_path = os.path.join(directory, model_name)
|
35 |
+
|
36 |
+
print("Downloading all files...")
|
37 |
+
if not os.path.exists(final_model_path):
|
38 |
+
with open(final_model_path, "wb") as f:
|
39 |
+
http_get(model_url, f)
|
40 |
+
os.chmod(final_model_path, 0o777)
|
41 |
+
print("Files downloaded!")
|
42 |
+
|
43 |
+
model = Llama(
|
44 |
+
model_path=final_model_path,
|
45 |
+
n_ctx=2048
|
46 |
+
)
|
47 |
+
|
48 |
+
print("Model loaded!")
|
49 |
+
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
def user(message, history):
|
|
|
85 |
|
86 |
partial_text = ""
|
87 |
for i, token in enumerate(generator):
|
88 |
+
if token == model.token_eos():
|
89 |
break
|
90 |
partial_text += model.detokenize([token]).decode("utf-8", "ignore")
|
91 |
history[-1][1] = partial_text
|
|
|
109 |
with gr.Row():
|
110 |
with gr.Column(scale=5):
|
111 |
system_prompt = gr.Textbox(label="Системный промпт", placeholder="", value=SYSTEM_PROMPT, interactive=False)
|
112 |
+
chatbot = gr.Chatbot(label="Диалог", height=400)
|
113 |
with gr.Column(min_width=80, scale=1):
|
114 |
with gr.Tab(label="Параметры генерации"):
|
115 |
top_p = gr.Slider(
|