Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
070049d c85546a 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 |
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.7, 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() |