Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Hugging Face's logo
|
2 |
+
Hugging Face
|
3 |
+
Search models, datasets, users...
|
4 |
+
Models
|
5 |
+
Datasets
|
6 |
+
Spaces
|
7 |
+
Docs
|
8 |
+
Solutions
|
9 |
+
Pricing
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
Spaces:
|
14 |
+
|
15 |
+
mshook
|
16 |
+
/
|
17 |
+
gpt2-story-generator-example Copied
|
18 |
+
private
|
19 |
+
|
20 |
+
Logs
|
21 |
+
App
|
22 |
+
Files
|
23 |
+
Community
|
24 |
+
Settings
|
25 |
+
gpt2-story-generator-example
|
26 |
+
/
|
27 |
+
app.py
|
28 |
+
mshook's picture
|
29 |
+
mshook
|
30 |
+
Update app.py
|
31 |
+
26c39e6
|
32 |
+
43 minutes ago
|
33 |
+
raw
|
34 |
+
history
|
35 |
+
blame
|
36 |
+
edit
|
37 |
+
delete
|
38 |
+
735 Bytes
|
39 |
+
import gradio as gr
|
40 |
+
from transformers import pipeline
|
41 |
+
|
42 |
+
#generator = pipeline('text-generation', model='gpt2-xl')
|
43 |
+
generator = pipeline('text-generation', model='pranavpsv/gpt2-genre-story-generator')
|
44 |
+
|
45 |
+
def generate(text):
|
46 |
+
result = generator(text, max_length=100, num_return_sequences=1)
|
47 |
+
return result[0]["generated_text"]
|
48 |
+
|
49 |
+
examples = [
|
50 |
+
["<BOS> <sci_fi> After discovering time travel,"],
|
51 |
+
["<BOS> <superhero> Batman"],
|
52 |
+
["<BOS> <drama> Legolas and Gimli advanced on the orcs, raising their weapons with a harrowing war cry"],
|
53 |
+
]
|
54 |
+
|
55 |
+
demo = gr.Interface(
|
56 |
+
fn=generate,
|
57 |
+
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
58 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
59 |
+
examples=examples
|
60 |
+
)
|
61 |
+
|
62 |
+
demo.launch()
|