Spaces:
Running
Running
File size: 1,238 Bytes
5725936 c84bdec 5725936 79e13b5 c84bdec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
from transformers import pipeline
generator = pipeline('text-generation', model="Pankaj8922/gpt2-fs", pad_token_id=50256)
def generate_text(prompt, max_length, temperature, top_k, top_p):
result = generator(
prompt,
max_length=max_length,
temperature=temperature,
top_k=top_k,
top_p=top_p,
do_sample=True,
truncation=True
)
return result[0]['generated_text']
with gr.Blocks() as demo:
gr.Markdown("# GPT-2 Text Generation with Custom Settings")
prompt = gr.Textbox(label="Enter your prompt here")
max_length = gr.Slider(label="Max Length", minimum=10, maximum=200, value=50, step=1)
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
top_k = gr.Slider(label="Top-K Sampling", minimum=0, maximum=100, value=50, step=1)
top_p = gr.Slider(label="Top-P (Nucleus Sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.1)
output = gr.Textbox(label="Generated Text", interactive=False)
generate_button = gr.Button("Generate")
generate_button.click(generate_text, inputs=[prompt, max_length, temperature, top_k, top_p], outputs=output)
demo.launch() |