Spaces:
Runtime error
Runtime error
Commit
·
070049d
1
Parent(s):
f1538e7
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from happytransformer import HappyGeneration
|
| 4 |
+
|
| 5 |
+
happy_gen = HappyGeneration("GPT-NEO", "DarwinAnim8or/GPT-Greentext-125m")
|
| 6 |
+
|
| 7 |
+
from happytransformer import GENSettings
|
| 8 |
+
args_top_k = GENSettings(no_repeat_ngram_size=3, do_sample=True,top_k=80, temperature=0.4, max_length=50, early_stopping=False)
|
| 9 |
+
|
| 10 |
+
def generate(text):
|
| 11 |
+
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"
|
| 12 |
+
inputText += ">" + text + "\n>"
|
| 13 |
+
|
| 14 |
+
result = happy_gen.generate_text(inputText, args=args_top_k)
|
| 15 |
+
generated_text = result.text #returns generated text only
|
| 16 |
+
|
| 17 |
+
#replace \n with actual newlines:
|
| 18 |
+
generated_text = generated_text.replace('\\n', '\n')
|
| 19 |
+
|
| 20 |
+
return generated_text
|
| 21 |
+
|
| 22 |
+
examples = [
|
| 23 |
+
["be me"],
|
| 24 |
+
["be going to heaven"],
|
| 25 |
+
["be going to work"],
|
| 26 |
+
["be baking a pie"],
|
| 27 |
+
["come home after another tiring day"]
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=generate,
|
| 32 |
+
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
| 33 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 34 |
+
examples=examples
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
demo.launch()
|