Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,15 +9,20 @@ from transformers import GPT2Tokenizer, GPT2LMHeadModel, GPT2Config
|
|
9 |
|
10 |
def generate(tokenizer, model, text, features):
|
11 |
generated = tokenizer("<|startoftext|><|titlestart|>{}<|titleend|><|authornamebegin|>".format(text), return_tensors="pt").input_ids
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
continue
|
20 |
-
|
|
|
|
|
|
|
21 |
st.markdown('**' + author.strip() + '**: ' + text.replace('<|endoftext|>', '').replace('<|pad|>', '').strip())
|
22 |
|
23 |
|
|
|
9 |
|
10 |
def generate(tokenizer, model, text, features):
|
11 |
generated = tokenizer("<|startoftext|><|titlestart|>{}<|titleend|><|authornamebegin|>".format(text), return_tensors="pt").input_ids
|
12 |
+
count = 0
|
13 |
+
while count < features['num']:
|
14 |
+
sample_outputs = model.generate(
|
15 |
+
generated, do_sample=True, top_k=50,
|
16 |
+
max_length=features['max_length'], top_p=features['top_p'], temperature=features['t'] / 100.0, num_return_sequences=1,
|
17 |
+
)
|
18 |
+
decoded = tokenizer.decode(sample_outputs[0], skip_special_tokens=False)
|
19 |
+
print(decoded, file=sys.stderr)
|
20 |
+
if '<|authornameend|>' not in decoded:
|
21 |
continue
|
22 |
+
|
23 |
+
author, text = decoded.split('<|authornamebegin|>')[-1].split('<|authornameend|>')
|
24 |
+
|
25 |
+
count += 1
|
26 |
st.markdown('**' + author.strip() + '**: ' + text.replace('<|endoftext|>', '').replace('<|pad|>', '').strip())
|
27 |
|
28 |
|