Spaces:
Configuration error
Configuration error
Commit
·
04bfb88
1
Parent(s):
ffce87b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from happytransformer import HappyGeneration
|
4 |
+
|
5 |
+
happy_gen = HappyGeneration("GPT2", "DarwinAnim8or/GPT-NoSleep-355m")
|
6 |
+
|
7 |
+
from happytransformer import GENSettings
|
8 |
+
|
9 |
+
def generate(text, length=100, penalty=3, temperature=0.8):
|
10 |
+
args_top_k = GENSettings(no_repeat_ngram_size=penalty, do_sample=True, top_k=80, temperature=temperature, max_length=length, early_stopping=False)
|
11 |
+
print("Prompt: " + text)
|
12 |
+
|
13 |
+
inputText = "[WP] " + text + " [RESPONSE] "
|
14 |
+
|
15 |
+
result = happy_gen.generate_text(inputText, args=args_top_k)
|
16 |
+
generated_text = result.text #returns generated text only
|
17 |
+
|
18 |
+
generated_text = generated_text.replace('.', '.\n')
|
19 |
+
|
20 |
+
return generated_text
|
21 |
+
|
22 |
+
examples = [
|
23 |
+
["We don't go to the forest anymore."],
|
24 |
+
["There used to be a smile on my face. "],
|
25 |
+
["Now I know why they're called 'Mans best friend'"],
|
26 |
+
["The terror in the night"],
|
27 |
+
["I still see them."],
|
28 |
+
["The curse of the plague doctor"]
|
29 |
+
]
|
30 |
+
|
31 |
+
demo = gr.Interface(
|
32 |
+
fn=generate,
|
33 |
+
inputs=[
|
34 |
+
gr.inputs.Textbox(lines=5, label="Input Text"),
|
35 |
+
gr.inputs.Slider(25, 500, label='Length', default=100, step=25),
|
36 |
+
gr.inputs.Slider(1, 10, label='no repeat ngram size', default=2, step=1),
|
37 |
+
gr.inputs.Slider(0.0, 1.0, label='Temperature - control randomness', default=0.6, step=0.1)
|
38 |
+
],
|
39 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
40 |
+
examples=examples,
|
41 |
+
title="NoSleep Story Generator",
|
42 |
+
description="Using the 355m size model. You may need to run it a few times in order to get something good!"
|
43 |
+
)
|
44 |
+
|
45 |
+
demo.launch()
|