Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline, set_seed | |
| # Load model | |
| generator = pipeline( | |
| "text-generation", | |
| model="openai-community/gpt2-large" | |
| ) | |
| set_seed(42) | |
| # Chat function | |
| def chat(prompt): | |
| if not prompt.strip(): | |
| return "Please enter a message." | |
| output = generator( | |
| prompt, | |
| max_length=150, | |
| num_return_sequences=1, | |
| do_sample=True, | |
| temperature=0.8 | |
| ) | |
| return output[0]["generated_text"] | |
| # UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🤖 GPT-2 Large Chatbot") | |
| inp = gr.Textbox(label="Your message", placeholder="Type something...") | |
| out = gr.Textbox(label="Response") | |
| btn = gr.Button("Generate") | |
| btn.click(fn=chat, inputs=inp, outputs=out) | |
| demo.launch() |