import gradio as gr from happytransformer import HappyGeneration happy_gen = HappyGeneration("GPT2", "DarwinAnim8or/NoSleepPromptGen") from happytransformer import GENSettings args_top_k = GENSettings(no_repeat_ngram_size=1, do_sample=True, top_k=80, temperature=0.3, max_length=25, early_stopping=True) def generate(text): result = happy_gen.generate_text(text, args=args_top_k) generated_text = result.text #returns generated text only # Remove everything past " generated_text = generated_text.split("\"")[0] return generated_text examples = [ ["[WP] "], ] demo = gr.Interface( fn=generate, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs=gr.outputs.Textbox(label="Generated Text"), examples=examples, title="'NoSleep' Writing Prompt Generator", description="This aims to generate horror story, aka 'NoSleep' writing prompts. You can use this in tandem with: https://huggingface.co/spaces/DarwinAnim8or/NoSleep-Story-Generator.\n Right now, it's recommended to only input '[WP] ' as the input text; I'm working on updating this model to generate a prompt from a description of a story." ) demo.launch()