Spaces:
Runtime error
Runtime error
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() |