IlyaGusev commited on
Commit
d42be36
1 Parent(s): cc2ccba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -30
app.py CHANGED
@@ -26,34 +26,27 @@ def get_system_tokens(model):
26
  return get_message_tokens(model, **system_message)
27
 
28
 
29
- directory = "."
30
- model_url = "https://huggingface.co/IlyaGusev/saiga_mistral_7b_gguf/resolve/main/model-q4_K.gguf"
31
- model_name = "model-q4_K.gguf"
32
- final_model_path = os.path.join(directory, model_name)
33
-
34
- print("Downloading all files...")
35
- rm_files = [os.path.join(directory, f) for f in os.listdir(directory)]
36
- for f in rm_files:
37
- if os.path.isfile(f):
38
- os.remove(f)
39
- else:
40
- shutil.rmtree(f)
41
- if not os.path.exists(final_model_path):
42
- with open(final_model_path, "wb") as f:
43
- http_get(model_url, f)
44
- os.chmod(final_model_path, 0o777)
45
- print("Files downloaded!")
46
-
47
- model = Llama(
48
- model_path=final_model_path,
49
- verbose=True,
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() or (max_new_tokens is not None and i >= max_new_tokens):
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="Диалог").style(height=400)
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(