Spaces:
Build error
Build error
Download app.py from tchans123/gpt2-deployment: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/spaces/tchans123/gpt2-deployment/resolve/main/app.py
- Command line
-
hf download hf://spaces/tchans123/gpt2-deployment/app.py
-
curl -L -o app.py https://huggingface.co/spaces/tchans123/gpt2-deployment/resolve/main/app.py
942 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the GPT-2 model from Hugging Face using the pipeline | |
| generator = pipeline('text-generation', model='gpt2-medium') | |
| def generate_text(prompt, max_length=50): | |
| # Generate text using the GPT-2 model | |
| generated_text = generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text'] | |
| return generated_text | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_text, | |
| inputs=[ | |
| gr.Textbox(lines=3, placeholder="Enter your prompt here...", label="Prompt"), | |
| gr.Slider(minimum=10, maximum=250, value=100, label="Max Length"), | |
| ], | |
| outputs=gr.Textbox(label="Generated Text"), | |
| title="GPT-2 Text Generator (OUTDATED)", | |
| description="Enter a prompt and generate text using GPT-2 on Hugging Face. Try out other models [here](https://huggingface.co/tchans123)." | |
| ) | |
| # Launch the Gradio interface | |
| iface.launch(share=True) | |