Spaces:
Runtime error
Runtime error
File size: 914 Bytes
e3c9dd9 8cce078 71eba68 e3c9dd9 71eba68 8cce078 e3c9dd9 8cce078 e3c9dd9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
from transformers import GPT2LMHeadModel, pipeline
import torch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# load pretrained + finetuned GPT2
model = GPT2LMHeadModel.from_pretrained("./model/pytorch_model.bin", from_pt=True)
# model = GPT2LMHeadModel.from_pretrained("/zxc/model_epoch40_50w")
model = model.to(device)
# generator = pipeline('text-generation', model=model)
trump = pipeline("text-generation", model=model, tokenizer=tokenizer, config={"max_length":140})
def generate(text):
result = trump(text, num_return_sequences=1)
return result[0]["generated_text"]
examples = [
["Today I'll be"],
["Why does the lying news media"],
["The democrats have"]
]
demo = gr.Interface(
fn=generate,
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
outputs=gr.outputs.Textbox(label="Generated Text"),
examples=examples
)
demo.launch() |