DarwinAnim8or's picture
Update app.py
f915829
raw
history blame
1.35 kB
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()