File size: 1,177 Bytes
9dca603
 
 
 
 
 
 
 
 
 
31f71ec
9dca603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ca9fe6
 
 
9dca603
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()