Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ eos_token = "<EOS>"
|
|
14 |
bos_token = "<BOS>"
|
15 |
bot_token = "<Assistant>"
|
16 |
|
|
|
17 |
|
18 |
def is_english_word(tested_string):
|
19 |
pattern = re.compile(r"^[a-zA-Z]+$")
|
@@ -52,14 +53,14 @@ def gradio(model, tokenizer):
|
|
52 |
prompt,
|
53 |
return_tensors="pt",
|
54 |
add_special_tokens=False,
|
55 |
-
)
|
56 |
|
57 |
prompt_length = input_ids.shape[1]
|
58 |
|
59 |
beam_output = model.generate(
|
60 |
input_ids,
|
61 |
pad_token_id=tokenizer.pad_token_id,
|
62 |
-
max_new_tokens=
|
63 |
num_beams=1, # with cpu
|
64 |
top_k=top_k,
|
65 |
top_p=top_p,
|
@@ -75,11 +76,11 @@ def gradio(model, tokenizer):
|
|
75 |
for i, token in enumerate(tokens[:-1]):
|
76 |
if is_english_word(token) and is_english_word(tokens[i + 1]):
|
77 |
tokens[i] = token + " "
|
78 |
-
text = "".join(tokens).replace("##", "").replace("
|
79 |
|
80 |
return text
|
81 |
|
82 |
-
bot = gr.Chatbot(show_copy_button=True, show_share_button=True
|
83 |
|
84 |
with gr.Blocks() as demo:
|
85 |
gr.Markdown("GPT2 chatbot | Powered by nlp-greyfoss")
|
|
|
14 |
bos_token = "<BOS>"
|
15 |
bot_token = "<Assistant>"
|
16 |
|
17 |
+
max_context_length = 750
|
18 |
|
19 |
def is_english_word(tested_string):
|
20 |
pattern = re.compile(r"^[a-zA-Z]+$")
|
|
|
53 |
prompt,
|
54 |
return_tensors="pt",
|
55 |
add_special_tokens=False,
|
56 |
+
)[:, -max_context_length:]
|
57 |
|
58 |
prompt_length = input_ids.shape[1]
|
59 |
|
60 |
beam_output = model.generate(
|
61 |
input_ids,
|
62 |
pad_token_id=tokenizer.pad_token_id,
|
63 |
+
max_new_tokens=250,
|
64 |
num_beams=1, # with cpu
|
65 |
top_k=top_k,
|
66 |
top_p=top_p,
|
|
|
76 |
for i, token in enumerate(tokens[:-1]):
|
77 |
if is_english_word(token) and is_english_word(tokens[i + 1]):
|
78 |
tokens[i] = token + " "
|
79 |
+
text = "".join(tokens).replace("##", "").replace("[UNK]", "").strip()
|
80 |
|
81 |
return text
|
82 |
|
83 |
+
bot = gr.Chatbot(show_copy_button=True, show_share_button=True).style(height="100%")
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.Markdown("GPT2 chatbot | Powered by nlp-greyfoss")
|