Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,23 @@
|
|
| 1 |
-
import
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Initialize the text-generation pipeline with a pre-trained model (e.g., GPT-2)
|
| 5 |
+
generator = pipeline("text-generation", model="gpt-2")
|
| 6 |
|
| 7 |
+
def generate_blogpost(topic):
|
| 8 |
+
prompt = f"Write a detailed blog post about {topic}."
|
| 9 |
+
result = generator(prompt, max_length=300, num_return_sequences=1)
|
| 10 |
+
return result[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Define the Gradio interface
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=generate_blogpost,
|
| 15 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter blog topic here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Blog Post Generator",
|
| 18 |
+
description="Generate a detailed blog post for a given topic using GPT-2."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the Gradio interface
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|