Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from transformers import GPT2Tokenizer, TFGPT2LMHeadModel, pipeline
|
| 4 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
| 5 |
+
model = TFGPT2LMHeadModel.from_pretrained('gpt2')
|
| 6 |
+
|
| 7 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def predict(x):
|
| 11 |
+
output = pipe(text_inputs=x, max_length=50)
|
| 12 |
+
return output[0]['generated_text']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# Generate some text with this demo ! ")
|
| 17 |
+
input = gr.Textbox(label="Input Text")
|
| 18 |
+
output = gr.Textbox(label="Output Text")
|
| 19 |
+
generate_btn = gr.Button("Generate")
|
| 20 |
+
generate_btn.click(fn=predict, inputs=input, outputs=output)
|
| 21 |
+
gr.Markdown("## Examples")
|
| 22 |
+
gr.Examples(examples=["My name is James and i like", "I go every day at the "],
|
| 23 |
+
cache_examples=True,
|
| 24 |
+
inputs=input,
|
| 25 |
+
outputs=output,
|
| 26 |
+
fn=predict)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
demo.launch(server_name="0.0.0.0")
|