Spaces:
Sleeping
Sleeping
Update app.py
Browse files23 unmodified lines24252627282930313233347 unmodified lines424344454647484950515253545556575859606162636465666768697023 unmodified lines)return output_sequencesdefault_value = "See how a modern neural network auto-completes your text ๐ค This site, built by the Hugging Face team, lets you write a whole document directly from your browser, and you can trigger the Transformer anywhere using the Tab key. Its like having a smart machine that completes your thoughts ๐ Get started by typing a custom snippet, check out the repository, or try one of the examples. Have fun!"#promptsst.title("Write with Transformers ๐ฆ")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.")sent = st.text_area("Text", default_value, height = 275)max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=30)7 unmodified lineselse:input_ids = encoded_promptoutput_sequences = infer(input_ids, max_length, temperature, top_k, top_p)for generated_sequence_idx, generated_sequence in enumerate(output_sequences):print(f"=== GENERATED SEQUENCE {generated_sequence_idx + 1} ===")generated_sequences = generated_sequence.tolist()# Decode texttext = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True)# Remove all text after the stop token#text = text[: text.find(args.stop_token) if args.stop_token else None]# Add the prompt at the beginning of the sequence. Remove the excess text that was used for pre-processingtotal_sequence = (sent + text[len(tokenizer.decode(encoded_prompt[0], clean_up_tokenization_spaces=True)) :])generated_sequences.append(total_sequence)print(total_sequence)st.write(generated_sequences[-1])23 unmodified lines242526272829303132337 unmodified lines41424344454647484950515253545556575823 unmodified lines)return output_sequencesdefault_value = "Once upon a time, in a galaxy far, far away...."#promptsst.title("Text completion with GPT-2")sent = st.text_area("Text", default_value, height = 275)max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=30)7 unmodified lineselse:input_ids = encoded_promptoutput_sequences = infer(input_ids, max_length, temperature, top_k, top_p)for generated_sequence_idx, generated_sequence in enumerate(output_sequences):print(f"=== GENERATED SEQUENCE {generated_sequence_idx + 1} ===")generated_sequences = generated_sequence.tolist()text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True)total_sequence = (sent + text[len(tokenizer.decode(encoded_prompt[0], clean_up_tokenization_spaces=True)) :])generated_sequences.append(total_sequence)st.write(generated_sequences[-1])
app.py+3-15