gradio/demo/unified_demo_text_generation/run.ipynb
Ali Abdalla 890bae3942
Filter out type ignore comments from demos on website (#9043)
* hide type ignore comments

* add changeset

* replace #type

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2024-08-07 22:14:48 -07:00

1016 B

Gradio Demo: unified_demo_text_generation

In [ ]:
!pip install -q gradio torch transformers
In [ ]:
import gradio as gr
from transformers import pipeline

generator = pipeline('text-generation', model = 'gpt2')

def generate_text(text_prompt):
  response = generator(text_prompt, max_length = 30, num_return_sequences=5)
  return response[0]['generated_text']  # type: ignore

textbox = gr.Textbox()

demo = gr.Interface(generate_text, textbox, textbox)

if __name__ == "__main__":
    demo.launch()