Spaces:
Running
Running
Upload with huggingface_hub
Browse files- DESCRIPTION.md +1 -0
- README.md +1 -1
- app.py +0 -10
DESCRIPTION.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
This text generation demo takes in input text and returns generated text. It uses the Transformers library to set up the model and has two examples.
|
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
|
2 |
---
|
3 |
title: text_generation
|
4 |
-
emoji:
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
|
|
1 |
|
2 |
---
|
3 |
title: text_generation
|
4 |
+
emoji: 🔥
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
app.py
CHANGED
@@ -1,26 +1,17 @@
|
|
1 |
-
# URL: https://huggingface.co/spaces/gradio/text_generation
|
2 |
-
# DESCRIPTION: This text generation demo takes in input text and returns generated text. It uses the Transformers library to set up the model and has two examples.
|
3 |
-
# imports
|
4 |
import gradio as gr
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
# loading the model
|
8 |
generator = pipeline('text-generation', model='gpt2')
|
9 |
|
10 |
-
|
11 |
-
# defining the core function
|
12 |
def generate(text):
|
13 |
result = generator(text, max_length=30, num_return_sequences=1)
|
14 |
return result[0]["generated_text"]
|
15 |
|
16 |
-
|
17 |
-
# defining examples
|
18 |
examples = [
|
19 |
["The Moon's orbit around Earth has"],
|
20 |
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
21 |
]
|
22 |
|
23 |
-
# defining the interface
|
24 |
demo = gr.Interface(
|
25 |
fn=generate,
|
26 |
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
@@ -28,5 +19,4 @@ demo = gr.Interface(
|
|
28 |
examples=examples
|
29 |
)
|
30 |
|
31 |
-
# launching
|
32 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
4 |
generator = pipeline('text-generation', model='gpt2')
|
5 |
|
|
|
|
|
6 |
def generate(text):
|
7 |
result = generator(text, max_length=30, num_return_sequences=1)
|
8 |
return result[0]["generated_text"]
|
9 |
|
|
|
|
|
10 |
examples = [
|
11 |
["The Moon's orbit around Earth has"],
|
12 |
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
13 |
]
|
14 |
|
|
|
15 |
demo = gr.Interface(
|
16 |
fn=generate,
|
17 |
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
|
|
19 |
examples=examples
|
20 |
)
|
21 |
|
|
|
22 |
demo.launch()
|