Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,12 +20,22 @@ topic = st.text_input("Enter the topic for your blog post:")
|
|
| 20 |
# Generate blog post button
|
| 21 |
if st.button("Generate Blog Post"):
|
| 22 |
if topic:
|
| 23 |
-
#
|
| 24 |
-
input_text = f"Write a blog post about {topic}."
|
|
|
|
|
|
|
| 25 |
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
| 26 |
|
| 27 |
# Generate the blog post using GPT-2 large
|
| 28 |
-
outputs = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Decode the generated text
|
| 31 |
blog_post = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 20 |
# Generate blog post button
|
| 21 |
if st.button("Generate Blog Post"):
|
| 22 |
if topic:
|
| 23 |
+
# Refine the input prompt to guide the model towards generating a blog post
|
| 24 |
+
input_text = f"Write a detailed blog post about {topic}. The post should cover various aspects of the topic and provide valuable information to the readers. Start with an introduction and follow with detailed paragraphs."
|
| 25 |
+
|
| 26 |
+
# Encode the input text
|
| 27 |
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
| 28 |
|
| 29 |
# Generate the blog post using GPT-2 large
|
| 30 |
+
outputs = model.generate(
|
| 31 |
+
inputs,
|
| 32 |
+
max_length=500,
|
| 33 |
+
num_return_sequences=1,
|
| 34 |
+
no_repeat_ngram_size=2,
|
| 35 |
+
early_stopping=True,
|
| 36 |
+
temperature=0.7,
|
| 37 |
+
top_p=0.9
|
| 38 |
+
)
|
| 39 |
|
| 40 |
# Decode the generated text
|
| 41 |
blog_post = tokenizer.decode(outputs[0], skip_special_tokens=True)
|