|
|
|
|
|
"""app.ipynb |
|
|
|
|
|
Automatically generated by Colab. |
|
|
|
|
|
Original file is located at |
|
|
https://colab.research.google.com/drive/1-t9RYzLIxj4UDdky3Q_wyg29YwrPfJZN |
|
|
""" |
|
|
|
|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
generator = pipeline("text-generation", model="gpt2") |
|
|
|
|
|
def generate_text(prompt): |
|
|
output = generator(prompt, max_new_tokens=50, do_sample=True, return_full_text=False) |
|
|
return output[0]["generated_text"] |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=generate_text, |
|
|
inputs=gr.Textbox(lines=4, placeholder="Type a short prompt here..."), |
|
|
outputs=gr.Textbox(lines=4, label="Output"), |
|
|
allow_flagging="never", |
|
|
title="Text Generator Demo", |
|
|
description="A simple Gradio app using GPT-2 from Hugging Face Transformers.", |
|
|
theme="soft", |
|
|
) |
|
|
|
|
|
demo.queue().launch() |