Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from PIL import Image
|
|
10 |
def get_model(model_name, model_path):
|
11 |
tokenizer = transformers.GPT2Tokenizer.from_pretrained(model_name)
|
12 |
tokenizer.add_special_tokens({
|
13 |
-
|
14 |
})
|
15 |
model = transformers.GPT2LMHeadModel.from_pretrained(model_name)
|
16 |
model.resize_token_embeddings(len(tokenizer))
|
@@ -20,7 +20,7 @@ def get_model(model_name, model_path):
|
|
20 |
|
21 |
|
22 |
#@st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None, re.Pattern: lambda _: None}, allow_output_mutation=True, suppress_st_warning=True)
|
23 |
-
def predict(text, model, tokenizer, n_beams=5, temperature=2.5, top_p=0.8, max_length=
|
24 |
text += '\n'
|
25 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
26 |
length_of_prompt = len(input_ids[0])
|
@@ -31,6 +31,7 @@ def predict(text, model, tokenizer, n_beams=5, temperature=2.5, top_p=0.8, max_l
|
|
31 |
temperature=temperature,
|
32 |
top_p=top_p,
|
33 |
max_length=max_length + length_of_prompt,
|
|
|
34 |
)
|
35 |
|
36 |
return list(map(tokenizer.decode, out))[0]
|
@@ -59,8 +60,10 @@ if button:
|
|
59 |
#for line in lines:
|
60 |
# st.write(line)
|
61 |
|
62 |
-
lines = result.replace('\n', '\n\n')
|
63 |
-
st.write(lines)
|
|
|
|
|
64 |
|
65 |
#except Exception:
|
66 |
# st.error("Ooooops, something went wrong. Try again please and report to me, tg: @vladyur")
|
|
|
10 |
def get_model(model_name, model_path):
|
11 |
tokenizer = transformers.GPT2Tokenizer.from_pretrained(model_name)
|
12 |
tokenizer.add_special_tokens({
|
13 |
+
'eos_token': '[EOS]'
|
14 |
})
|
15 |
model = transformers.GPT2LMHeadModel.from_pretrained(model_name)
|
16 |
model.resize_token_embeddings(len(tokenizer))
|
|
|
20 |
|
21 |
|
22 |
#@st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None, re.Pattern: lambda _: None}, allow_output_mutation=True, suppress_st_warning=True)
|
23 |
+
def predict(text, model, tokenizer, n_beams=5, temperature=2.5, top_p=0.8, max_length=300):
|
24 |
text += '\n'
|
25 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
26 |
length_of_prompt = len(input_ids[0])
|
|
|
31 |
temperature=temperature,
|
32 |
top_p=top_p,
|
33 |
max_length=max_length + length_of_prompt,
|
34 |
+
eos_token_id=tokenizer.eos_token_id
|
35 |
)
|
36 |
|
37 |
return list(map(tokenizer.decode, out))[0]
|
|
|
60 |
#for line in lines:
|
61 |
# st.write(line)
|
62 |
|
63 |
+
#lines = result.replace('\n', '\n\n')
|
64 |
+
#st.write(lines)
|
65 |
+
|
66 |
+
st.text_area(label='', value=result)
|
67 |
|
68 |
#except Exception:
|
69 |
# st.error("Ooooops, something went wrong. Try again please and report to me, tg: @vladyur")
|