Spaces:
Sleeping
Sleeping
Preeti Dave
commited on
Commit
·
e11d2cc
1
Parent(s):
a294c72
- app.py +22 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the pre-trained model for text generation (GPT-2)
|
| 5 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 6 |
+
|
| 7 |
+
# Function to generate poems based on a prompt
|
| 8 |
+
def generate_poem(prompt):
|
| 9 |
+
poem = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
| 10 |
+
return poem.strip()
|
| 11 |
+
|
| 12 |
+
# Gradio interface
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=generate_poem,
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a prompt for your poem here...", label="Poem Prompt"),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Poem Generator",
|
| 18 |
+
description="Generate poems with AI. Provide a prompt and let the AI create a poem for you!",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the Gradio app
|
| 22 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
tensorflow
|