Spaces:
Sleeping
Sleeping
setarejahandide
commited on
Commit
•
b8c9763
1
Parent(s):
02f0030
Initial commit with text generation app
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load pre-trained text generation pipeline
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
+
|
7 |
+
# Define the function to generate text
|
8 |
+
def generate_text(prompt):
|
9 |
+
generated = generator(prompt, max_length=50, num_return_sequences=1)
|
10 |
+
return generated[0]['generated_text']
|
11 |
+
|
12 |
+
# Create the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=generate_text,
|
15 |
+
inputs="text",
|
16 |
+
outputs="text",
|
17 |
+
title="Text Generation",
|
18 |
+
description="Generate text using GPT-2"
|
19 |
+
)
|
20 |
+
|
21 |
+
# Launch the interface
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|