File size: 1,728 Bytes
04bfb88
 
 
 
13b2bc5
04bfb88
 
 
d2c9db1
0b24949
04bfb88
 
 
 
 
 
 
 
 
 
 
 
 
 
e4d84d7
 
 
 
04bfb88
 
 
 
 
 
247e28f
d2c9db1
04bfb88
 
 
 
9217443
 
04bfb88
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr

from happytransformer import HappyGeneration

happy_gen = HappyGeneration("GPT2", "DarwinAnim8or/GPT-NoSleep-1.5b")

from happytransformer import GENSettings

def generate(text, length=100, penalty=1, temperature=0.8):
    args_top_k = GENSettings(no_repeat_ngram_size=penalty, do_sample=False, top_k=80, top_p=1, temperature=temperature, max_length=length, early_stopping=False)
    print("Prompt: " + text)
    
    inputText = "[WP] " + text + " [RESPONSE] "
    
    result = happy_gen.generate_text(inputText, args=args_top_k)
    generated_text = result.text #returns generated text only

    generated_text = generated_text.replace('.', '.\n')

    return generated_text

examples = [
    ["We don't go to the forest anymore."],
    ["There used to be a smile on my face. "],
    #["Now I know why they're called 'Mans best friend'"],
    #["The terror in the night"],
    #["I still see them."],
    #["The curse of the plague doctor"]
]

demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.inputs.Textbox(lines=5, label="Input Text"),
        gr.inputs.Slider(25, 500, label='Length', default=250, step=25),
        gr.inputs.Slider(1, 10, label='no repeat ngram size', default=1, step=1),
        gr.inputs.Slider(0.0, 1.0, label='Temperature - control randomness', default=0.6, step=0.1)
    ],
    outputs=gr.outputs.Textbox(label="Generated Text"),
    examples=examples,
    title="NoSleep Horror Story Generator",
    description="Using the 1.5b size model. You may need to run it a few times in order to get something good! TIP: if you want a writing prompt, use this model in combination: https://huggingface.co/spaces/DarwinAnim8or/NoSleepWritingPromptGenerator"
)

demo.launch()