Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
text_generator = pipeline('text-generation', model='gpt2')
|
| 5 |
+
|
| 6 |
+
def generate_text(prompt):
|
| 7 |
+
response = text_generator(prompt, max_length=50, num_return_sequences=2)
|
| 8 |
+
return response[0]["generated_text"]
|
| 9 |
+
|
| 10 |
+
example_prompts = [
|
| 11 |
+
["The Earth is a big"],
|
| 12 |
+
["70% of the Earth is covered by"],
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
demo_interface = gr.Interface(
|
| 16 |
+
fn=generate_text,
|
| 17 |
+
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
| 18 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 19 |
+
examples=example_prompts
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
demo_interface.launch()
|