Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,18 +5,29 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
| 5 |
model_name = "gpt2"
|
| 6 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 7 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def generate_blog(title):
|
| 10 |
input_ids = tokenizer.encode(title, return_tensors='pt')
|
| 11 |
output = model.generate(input_ids, max_length=800, num_return_sequences=1, no_repeat_ngram_size=2)
|
| 12 |
-
blog = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 13 |
-
return blog
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
st.title("AI Blog Generator")
|
| 17 |
-
st.write("Enter a blog title and the AI will generate the blog content for you.")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
| 5 |
model_name = "gpt2"
|
| 6 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 7 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 8 |
+
def make_prompt(example_title, example_content, new_title):
|
| 9 |
+
prompt = f"""
|
| 10 |
+
Title: The Benefits of Daily Meditation
|
| 11 |
|
| 12 |
+
Blog Content:
|
| 13 |
+
Meditation is a practice where an individual uses a technique – such as mindfulness,
|
| 14 |
+
or focusing the mind on a particular object, thought, or activity – to train attention and awareness,
|
| 15 |
+
and achieve a mentally clear and emotionally calm and stable state. Daily meditation can bring numerous
|
| 16 |
+
benefits such as reducing stress, improving concentration, and promoting a healthy lifestyle.
|
| 17 |
+
|
| 18 |
+
Title: {new_title}
|
| 19 |
+
|
| 20 |
+
Blog Content:
|
| 21 |
+
"""
|
| 22 |
+
return prompt
|
| 23 |
def generate_blog(title):
|
| 24 |
input_ids = tokenizer.encode(title, return_tensors='pt')
|
| 25 |
output = model.generate(input_ids, max_length=800, num_return_sequences=1, no_repeat_ngram_size=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
if st.button("Generate Blog"):
|
| 28 |
+
if title:
|
| 29 |
+
title=make_prompt(title)
|
| 30 |
+
blog_content = generate_blog(title)
|
| 31 |
+
st.subheader("Generated Blog")
|
| 32 |
+
st.write(blog_content)
|
| 33 |
|