Spaces:
Sleeping
Sleeping
Eman-Abdelkader25
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
-
generator = pipeline(
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
# Create the Gradio interface
|
12 |
iface = gr.Interface(
|
13 |
fn=generate_text,
|
14 |
-
inputs=
|
15 |
-
|
16 |
-
gr.inputs.Slider(minimum=10, maximum=200, default=50, label="Max Length")
|
17 |
-
],
|
18 |
-
outputs="text",
|
19 |
-
title="GPT-2 Text Generator",
|
20 |
-
description="Generate text using the GPT-2 model."
|
21 |
)
|
22 |
|
23 |
-
# Launch the
|
24 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load a pre-trained Hugging Face model
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
|
7 |
+
def generate_text(prompt):
|
8 |
+
# Generate text using the model
|
9 |
+
result = generator(prompt, max_length=50, num_return_sequences=1)
|
10 |
+
return result[0]["generated_text"]
|
11 |
|
12 |
# Create the Gradio interface
|
13 |
iface = gr.Interface(
|
14 |
fn=generate_text,
|
15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
16 |
+
outputs=gr.Textbox()
|
|
|
|
|
|
|
|
|
|
|
17 |
)
|
18 |
|
19 |
+
# Launch the interface
|
20 |
iface.launch()
|