import gradio as gr from happytransformer import HappyGeneration happy_gen = HappyGeneration("GPT-NEO", "DarwinAnim8or/GPT-Greentext-125m") from happytransformer import GENSettings args_top_k = GENSettings(no_repeat_ngram_size=2, do_sample=True,top_k=80, temperature=0.4, max_length=150, early_stopping=False) def generate(text): inputText = "Write a greentext from 4chan.org. The story should be like a bullet-point list using > as the start of each line. Most greentexts are humorous or absurd in nature. Most greentexts have a twist near the end.\n" inputText += ">" + text + "\n>" result = happy_gen.generate_text(inputText, args=args_top_k) generated_text = result.text #returns generated text only #replace \n with actual newlines: generated_text = generated_text.replace('\\n', '\n') return generated_text examples = [ ["be me"], ["be going to heaven"], ["be going to work"], ["be baking a pie"], ["come home after another tiring day"] ] demo = gr.Interface( fn=generate, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs=gr.outputs.Textbox(label="Generated Text"), examples=examples ) demo.launch()