Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,42 @@
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
generator = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
set_seed(42)
|
| 6 |
|
| 7 |
def generate_text(prompt):
|
|
|
|
|
|
|
| 8 |
response = generator(
|
| 9 |
prompt,
|
| 10 |
-
max_length=
|
| 11 |
num_return_sequences=1,
|
|
|
|
|
|
|
|
|
|
| 12 |
truncation=True
|
| 13 |
)
|
| 14 |
-
return response[0][
|
| 15 |
|
|
|
|
| 16 |
interface = gr.Interface(
|
| 17 |
fn=generate_text,
|
| 18 |
-
inputs=gr.Textbox(lines=
|
| 19 |
-
outputs="
|
| 20 |
-
title="
|
| 21 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
|
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
generator = pipeline(
|
| 5 |
+
"text-generation",
|
| 6 |
+
model="Keyurjotaniya007/openai-gpt2-wikitext-textgen"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
set_seed(42)
|
| 10 |
|
| 11 |
def generate_text(prompt):
|
| 12 |
+
if not prompt.strip():
|
| 13 |
+
return "Please enter a prompt to generate text."
|
| 14 |
response = generator(
|
| 15 |
prompt,
|
| 16 |
+
max_length=150,
|
| 17 |
num_return_sequences=1,
|
| 18 |
+
temperature=0.8,
|
| 19 |
+
top_p=0.95,
|
| 20 |
+
do_sample=True,
|
| 21 |
truncation=True
|
| 22 |
)
|
| 23 |
+
return response[0]["generated_text"]
|
| 24 |
|
| 25 |
+
# Define the Gradio interface
|
| 26 |
interface = gr.Interface(
|
| 27 |
fn=generate_text,
|
| 28 |
+
inputs=gr.Textbox(lines=4, placeholder="Type your prompt here..."),
|
| 29 |
+
outputs=gr.Textbox(label="Generated Text"),
|
| 30 |
+
title="🦄 GPT-2 WikiText Text Generator",
|
| 31 |
+
description=(
|
| 32 |
+
"Generate coherent, fluent English text using **GPT-2 fine-tuned on the WikiText dataset**. "
|
| 33 |
+
"Model: `Keyurjotaniya007/openai-gpt2-wikitext-textgen`"
|
| 34 |
+
),
|
| 35 |
+
examples=[
|
| 36 |
+
["Artificial intelligence is transforming the world by"],
|
| 37 |
+
["Once upon a time, in a small village,"],
|
| 38 |
+
["The future of natural language processing lies in"],
|
| 39 |
+
],
|
| 40 |
)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|