mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-06 10:25:17 +08:00
16 lines
384 B
Python
16 lines
384 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']
|
||
|
|
||
|
textbox = gr.Textbox()
|
||
|
|
||
|
demo = gr.Interface(generate_text, textbox, textbox)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
demo.launch()
|