File size: 1,347 Bytes
070049d
 
 
 
f915829
070049d
 
f915829
070049d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f915829
 
 
070049d
 
 
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
import gradio as gr

from happytransformer import HappyGeneration

happy_gen = HappyGeneration("GPT2", "DarwinAnim8or/GPT-Greentext-355m")

from happytransformer import GENSettings
args_top_k = GENSettings(no_repeat_ngram_size=3, do_sample=True, top_k=80, temperature=0.8, 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,
    title="GPT-Greentext Playground",
    description="Using the 355m size model. You may need to run it a few times in order to get something good!"
)

demo.launch()