import gradio as gr from transformers import pipeline def generator_gpt2(text): gen = pipeline('text-generation', model='gpt2') return gen(text, max_length=30, num_return_sequences=1)[0]['generated_text'] def generator_openai_gpt(text): gen = pipeline('text-generation', model='openai-gpt') return gen(text, max_length=30, num_return_sequences=1)[0]['generated_text'] examples=[["Hello, I'm a language model,"], ["How are you?\n"]] demo1 = gr.Interface(fn=generator_gpt2, inputs=gr.inputs.Textbox(label="input"), outputs=gr.outputs.Textbox(label="gpt2"), ) demo2 = gr.Interface(fn=generator_openai_gpt, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Textbox(label="openai-gpt"), ) demo = gr.Parallel(demo1, demo2, examples=examples, allow_flagging="auto", css='styles.css', ) # demo.launch(server_name="0.0.0.0",show_error=True,debug=True)