mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
890bae3942
* 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>
1016 B
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()