| from transformers import pipeline | |
| import gradio as gr | |
| # Defining the pipeline and the model | |
| pipe_flan = pipeline("text-generation", model="gpt2") | |
| # Text generation | |
| def generator(input): | |
| output = pipe_flan(input, max_length=50, num_return_sequences=1) | |
| return output[0]["generated_text"] | |
| # Creating the Gradio Interface | |
| demo = gr.Interface( | |
| fn=generator, | |
| inputs=gr.inputs.Textbox(lines=5, label="Input Text"), | |
| outputs=gr.outputs.Textbox(label="Generated Text") | |
| ) | |
| # Lauching the Gradio Interface | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |