Spaces:
Sleeping
Sleeping
Download app.py from saicharan045/GPT2: direct link, hf CLI and curl.
- Browser
- Download file 678 Bytes
-
https://huggingface.co/spaces/saicharan045/GPT2/resolve/main/app.py
- Command line
-
hf download hf://spaces/saicharan045/GPT2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/saicharan045/GPT2/resolve/main/app.py
678 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| generator = pipeline( | |
| "text-generation", | |
| model="distilgpt2" | |
| ) | |
| def generate_text(prompt, temperature): | |
| if not prompt.strip(): | |
| return "Please enter a prompt." | |
| result = generator( | |
| prompt, | |
| max_new_tokens=50, | |
| temperature=temperature, | |
| do_sample=True | |
| ) | |
| return result[0]["generated_text"] | |
| demo = gr.Interface( | |
| fn=generate_text, | |
| inputs=[ | |
| gr.Textbox(label="Prompt", lines=3), | |
| gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature") | |
| ], | |
| outputs=gr.Textbox(label="Generated Text"), | |
| title="GPT2 Text Generator" | |
| ) | |
| demo.launch() |