File size: 1,164 Bytes
bdbc895
 
 
7818faa
 
 
 
 
bdbc895
 
 
7818faa
 
bdbc895
 
7818faa
bdbc895
7818faa
 
 
bdbc895
 
7818faa
bdbc895
7818faa
bdbc895
 
7818faa
 
 
 
 
 
 
 
 
 
 
bdbc895
 
 
39cb8e3
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
35
36
37
38
39
40
41
42
from transformers import pipeline, set_seed
import gradio as gr

generator = pipeline(
    "text-generation",
    model="Keyurjotaniya007/openai-gpt2-wikitext-textgen"
)

set_seed(42)

def generate_text(prompt):
    if not prompt.strip():
        return "Please enter a prompt to generate text."
    response = generator(
        prompt,
        max_length=150,
        num_return_sequences=1,
        temperature=0.8,
        top_p=0.95,
        do_sample=True,
        truncation=True
    )
    return response[0]["generated_text"]

# Define the Gradio interface
interface = gr.Interface(
    fn=generate_text,
    inputs=gr.Textbox(lines=4, placeholder="Type your prompt here..."),
    outputs=gr.Textbox(label="Generated Text"),
    title="🦄 GPT-2 WikiText Text Generator",
    description=(
        "Generate coherent, fluent English text using **GPT-2 fine-tuned on the WikiText dataset**. "
        "Model: `Keyurjotaniya007/openai-gpt2-wikitext-textgen`"
    ),
    examples=[
        ["Artificial intelligence is transforming the world by"],
        ["Once upon a time, in a small village,"],
    ],
)

if __name__ == "__main__":
    interface.launch()