Spaces:
Sleeping
Sleeping
Download app.py from Jitendra14355/GPT_2_Text_Generation: direct link, hf CLI and curl.
- Browser
- Download file 749 Bytes
-
https://huggingface.co/spaces/Jitendra14355/GPT_2_Text_Generation/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jitendra14355/GPT_2_Text_Generation/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jitendra14355/GPT_2_Text_Generation/resolve/main/app.py
749 Bytes
| from transformers import pipeline | |
| import gradio as gr | |
| # Load GPT-2 model | |
| generator = pipeline("text-generation", model="gpt2") | |
| # Function to generate text | |
| def generate_text(prompt, max_length): | |
| result = generator( | |
| prompt, | |
| max_length=max_length, | |
| num_return_sequences=1, | |
| do_sample=True, | |
| temperature=0.7 | |
| ) | |
| return result[0]['generated_text'] | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=generate_text, | |
| inputs=[ | |
| gr.Textbox(lines=4, placeholder="Enter your prompt here..."), | |
| gr.Slider(minimum=20, maximum=200, value=50, label="Max Length") | |
| ], | |
| outputs="text", | |
| title="🤖 GPT-2 Text Generator", | |
| description="Enter a prompt and generate text using GPT-2" | |
| ) | |
| demo.launch() |