Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,11 +24,10 @@ def infer(input_ids, max_length, temperature, top_k, top_p):
|
|
24 |
)
|
25 |
|
26 |
return output_sequences
|
27 |
-
default_value = "
|
28 |
|
29 |
#prompts
|
30 |
-
st.title("
|
31 |
-
st.write("The almighty king of text generation, GPT-2 comes in four available sizes, only three of which have been publicly made available. Feared for its fake news generation capabilities, it currently stands as the most syntactically coherent model. A direct successor to the original GPT, it reinforces the already established pre-training/fine-tuning killer duo. From the paper: Language Models are Unsupervised Multitask Learners by Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei and Ilya Sutskever.")
|
32 |
|
33 |
sent = st.text_area("Text", default_value, height = 275)
|
34 |
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=30)
|
@@ -42,29 +41,18 @@ if encoded_prompt.size()[-1] == 0:
|
|
42 |
else:
|
43 |
input_ids = encoded_prompt
|
44 |
|
45 |
-
|
46 |
output_sequences = infer(input_ids, max_length, temperature, top_k, top_p)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
for generated_sequence_idx, generated_sequence in enumerate(output_sequences):
|
51 |
print(f"=== GENERATED SEQUENCE {generated_sequence_idx + 1} ===")
|
52 |
generated_sequences = generated_sequence.tolist()
|
53 |
|
54 |
-
# Decode text
|
55 |
text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True)
|
56 |
|
57 |
-
# Remove all text after the stop token
|
58 |
-
#text = text[: text.find(args.stop_token) if args.stop_token else None]
|
59 |
-
|
60 |
-
# Add the prompt at the beginning of the sequence. Remove the excess text that was used for pre-processing
|
61 |
total_sequence = (
|
62 |
sent + text[len(tokenizer.decode(encoded_prompt[0], clean_up_tokenization_spaces=True)) :]
|
63 |
)
|
64 |
|
65 |
generated_sequences.append(total_sequence)
|
66 |
-
print(total_sequence)
|
67 |
-
|
68 |
-
|
69 |
-
st.write(generated_sequences[-1])
|
70 |
|
|
|
|
24 |
)
|
25 |
|
26 |
return output_sequences
|
27 |
+
default_value = "Once upon a time, in a galaxy far, far away...."
|
28 |
|
29 |
#prompts
|
30 |
+
st.title("Text completion with GPT-2")
|
|
|
31 |
|
32 |
sent = st.text_area("Text", default_value, height = 275)
|
33 |
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=30)
|
|
|
41 |
else:
|
42 |
input_ids = encoded_prompt
|
43 |
|
|
|
44 |
output_sequences = infer(input_ids, max_length, temperature, top_k, top_p)
|
45 |
|
|
|
|
|
46 |
for generated_sequence_idx, generated_sequence in enumerate(output_sequences):
|
47 |
print(f"=== GENERATED SEQUENCE {generated_sequence_idx + 1} ===")
|
48 |
generated_sequences = generated_sequence.tolist()
|
49 |
|
|
|
50 |
text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True)
|
51 |
|
|
|
|
|
|
|
|
|
52 |
total_sequence = (
|
53 |
sent + text[len(tokenizer.decode(encoded_prompt[0], clean_up_tokenization_spaces=True)) :]
|
54 |
)
|
55 |
|
56 |
generated_sequences.append(total_sequence)
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
st.write(generated_sequences[-1])
|