gradio/demo/unified_demo_text_generation/run.py
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

16 lines
400 B
Python

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()