Spaces:
No application file
No application file
Commit
·
f659457
1
Parent(s):
35792ee
Upload 3 files
Browse files- article_generation.py +80 -0
- blog_content_creation.py +98 -0
- blog_ideas_description_generation.py +15 -0
article_generation.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
|
| 4 |
+
def article_generator(idea, outline, section, llm, tone_of_voice):
|
| 5 |
+
|
| 6 |
+
'''
|
| 7 |
+
Description:
|
| 8 |
+
This function generates paragraphs for an article based on provided inputs such as the main idea, outline, specific section, Long Language Model (LLM), and desired tone of voice.
|
| 9 |
+
It uses a language model to create content either for a catchy introduction paragraph or to expand the article based on an existing outline.
|
| 10 |
+
|
| 11 |
+
Parameters:
|
| 12 |
+
idea (str) -> Required: The main idea or topic of the article.
|
| 13 |
+
outline (str) -> Required: The existing outline (if any) that has been covered in the article.
|
| 14 |
+
section (str) -> Required: The specific section or point that needs content creation or elaboration.
|
| 15 |
+
llm -> Required: The Long Language Model (LLM) used for generating article content.
|
| 16 |
+
tone_of_voice (str) -> Required: The intended tone of the article (e.g., professional, conversational, persuasive).
|
| 17 |
+
|
| 18 |
+
Return Value:
|
| 19 |
+
article (str): The generated article paragraph based on the provided inputs.
|
| 20 |
+
'''
|
| 21 |
+
|
| 22 |
+
if len(outline) == 0:
|
| 23 |
+
article_prompt = f"Generate Catchy Introduction paragraph for my article on {idea} using the following main point: {section}\nThe tone should be {tone_of_voice}."
|
| 24 |
+
else:
|
| 25 |
+
article_prompt = f"Generate well-organized paragraph for my article on {idea}. I have already covered: {outline} in the outline. I need help with the following main point: {section}. Please ensure the paragraphs are connected logically and provide a smooth transition between main topics. The tone should be {tone_of_voice}."
|
| 26 |
+
|
| 27 |
+
article_promptTemp = PromptTemplate(
|
| 28 |
+
input_variables=["text_input"],
|
| 29 |
+
template="You are a Professional content creator and article Writer:\n\n{text_input}\n\nParagraph:")
|
| 30 |
+
|
| 31 |
+
print(article_prompt)
|
| 32 |
+
article_extraction_chain = LLMChain(llm=llm, prompt=article_promptTemp)
|
| 33 |
+
article = article_extraction_chain.run(article_prompt)
|
| 34 |
+
|
| 35 |
+
return article
|
| 36 |
+
|
| 37 |
+
def full_article(idea, outline_list, tone_of_voice, llm):
|
| 38 |
+
|
| 39 |
+
'''
|
| 40 |
+
Description:
|
| 41 |
+
This function generates a full article by iteratively calling the article_generator function for each section in the provided outline list. It accumulates paragraphs generated for each section to construct a complete article based on the specified idea, outline, tone of voice, and Long Language Model (LLM).
|
| 42 |
+
|
| 43 |
+
Parameters:
|
| 44 |
+
idea (str) -> Required: The main idea or topic for the article.
|
| 45 |
+
outline_list (list) -> Required: A list containing sections or subsections for the article's structure.
|
| 46 |
+
tone_of_voice (str) -> Required: The desired tone of the article (e.g., professional, conversational, persuasive).
|
| 47 |
+
llm -> Required: The Long Language Model (LLM) used for generating article content.
|
| 48 |
+
|
| 49 |
+
Return Value:
|
| 50 |
+
article (list): A list of paragraphs representing the article content for each section in the provided outline.
|
| 51 |
+
'''
|
| 52 |
+
|
| 53 |
+
article = []
|
| 54 |
+
outline = []
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
|
| 58 |
+
for section in outline_list:
|
| 59 |
+
|
| 60 |
+
para = article_generator(idea, ' '.join(outline), section, llm, tone_of_voice)
|
| 61 |
+
outline.append(section)
|
| 62 |
+
article.append(para)
|
| 63 |
+
|
| 64 |
+
except:
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
return article
|
| 68 |
+
|
| 69 |
+
def rephrase(par, llm):
|
| 70 |
+
|
| 71 |
+
paraCheck_prompt = f"Rephrase the following paragraph and make it more unique and excited: {par}"
|
| 72 |
+
|
| 73 |
+
paraCheck_promptTemp = PromptTemplate(
|
| 74 |
+
input_variables=["text_input"],
|
| 75 |
+
template="You are a content creator.\n{text_input}")
|
| 76 |
+
|
| 77 |
+
paraCheck_extraction_chain = LLMChain(llm=llm, prompt=paraCheck_promptTemp)
|
| 78 |
+
rephrased_paragraph = paraCheck_extraction_chain.run(paraCheck_prompt)
|
| 79 |
+
|
| 80 |
+
return rephrased_paragraph
|
blog_content_creation.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
|
| 4 |
+
class blog_content_generation:
|
| 5 |
+
|
| 6 |
+
'''
|
| 7 |
+
Description:
|
| 8 |
+
This Python class, blog_content_generation, is designed to facilitate the creation of various blog-related content using a language model (LLM).
|
| 9 |
+
It offers functionalities to generate blog post ideas, descriptions, actual posts, and relevant tags for search engine optimization (SEO).
|
| 10 |
+
|
| 11 |
+
Class Methods:
|
| 12 |
+
__init__(self, llm)
|
| 13 |
+
|
| 14 |
+
Description: Initializes the blog_content_generation class by setting the language model (llm) to be used for content generation.
|
| 15 |
+
Parameters:
|
| 16 |
+
llm: The language model instance used for generating content.
|
| 17 |
+
|
| 18 |
+
blog_idea_desc_gen(self, blog)
|
| 19 |
+
|
| 20 |
+
Description: Generates SEO-friendly titles and meta descriptions for a given blog post topic.
|
| 21 |
+
Parameters:
|
| 22 |
+
blog: The title or topic of the blog post.
|
| 23 |
+
Returns:
|
| 24 |
+
blog_idea_desc: A list of suggested titles and meta descriptions.
|
| 25 |
+
|
| 26 |
+
blog_idea_gen(self, topic)
|
| 27 |
+
|
| 28 |
+
Description: Creates a list of SEO-friendly blog post ideas with emotional and persuasive titles based on a specific topic.
|
| 29 |
+
Parameters:
|
| 30 |
+
topic: The subject or theme for which blog post ideas are requested.
|
| 31 |
+
Returns:
|
| 32 |
+
blog_idea: A list containing at least 10 suggested blog post ideas.
|
| 33 |
+
|
| 34 |
+
blog_post_gen(self, topic)
|
| 35 |
+
|
| 36 |
+
Description: Generates a blog post on a given topic.
|
| 37 |
+
Parameters:
|
| 38 |
+
topic: The subject or theme for the blog post content.
|
| 39 |
+
Returns:
|
| 40 |
+
blog_post: The generated blog post content.
|
| 41 |
+
|
| 42 |
+
blog_tags_gen(self, blog)
|
| 43 |
+
|
| 44 |
+
Description: Suggests tags for a specific blog post.
|
| 45 |
+
Parameters:
|
| 46 |
+
blog: The title or topic of the blog post for which tags are needed.
|
| 47 |
+
Returns:
|
| 48 |
+
blog_tags_desc: A list of suggested tags related to the provided blog post.
|
| 49 |
+
'''
|
| 50 |
+
|
| 51 |
+
def __init__(self, llm):
|
| 52 |
+
self.llm = llm
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def blog_idea_desc_gen(self, blog):
|
| 56 |
+
|
| 57 |
+
blog_idea_desc_prompt = f"Suggest at least 5 SEO-friendly titles and meta descriptions for the following blog post {blog}. Use a persuasive and intriguing tone."
|
| 58 |
+
blog_idea_desc_promptTemp = PromptTemplate(
|
| 59 |
+
input_variables=["text_input"],
|
| 60 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
| 61 |
+
blog_idea_desc_extraction_chain = LLMChain(llm=self.llm, prompt=blog_idea_desc_promptTemp)
|
| 62 |
+
blog_idea_desc = blog_idea_desc_extraction_chain.run(blog_idea_desc_prompt)
|
| 63 |
+
|
| 64 |
+
return blog_idea_desc
|
| 65 |
+
|
| 66 |
+
def blog_idea_gen(self, topic):
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
blog_idea_prompt = f"Create a list of at least 10 blog post ideas on the following topic: {topic}. Suggest SEO-Friendly title and use an emotional and persuasive tone in blog post titles."
|
| 70 |
+
blog_idea_promptTemp = PromptTemplate(
|
| 71 |
+
input_variables=["text_input"],
|
| 72 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
| 73 |
+
blog_idea_extraction_chain = LLMChain(llm=self.llm, prompt=blog_idea_promptTemp)
|
| 74 |
+
blog_idea = blog_idea_extraction_chain.run(blog_idea_prompt)
|
| 75 |
+
|
| 76 |
+
return blog_idea
|
| 77 |
+
|
| 78 |
+
def blog_post_gen(self, topic):
|
| 79 |
+
|
| 80 |
+
blog_post_prompt = f"Write a blog Plost about {topic}."
|
| 81 |
+
blog_post_promptTemp = PromptTemplate(
|
| 82 |
+
input_variables=["text_input"],
|
| 83 |
+
template="You are a Professional Content Creator and Blog Writer:\n{text_input}\nBlog Post:")
|
| 84 |
+
blog_post_extraction_chain = LLMChain(llm=self.llm, prompt=blog_post_promptTemp)
|
| 85 |
+
blog_post = blog_post_extraction_chain.run(blog_post_prompt)
|
| 86 |
+
|
| 87 |
+
return blog_post
|
| 88 |
+
|
| 89 |
+
def blog_tags_gen(self, blog):
|
| 90 |
+
|
| 91 |
+
blog_tags_desc_prompt = f" Suggest at least 5 tags for the following blog post.\n{blog}"
|
| 92 |
+
blog_tags_desc_promptTemp = PromptTemplate(
|
| 93 |
+
input_variables=["text_input"],
|
| 94 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
| 95 |
+
blog_tags_desc_extraction_chain = LLMChain(llm=self.llm, prompt=blog_tags_desc_promptTemp)
|
| 96 |
+
blog_tags_desc = blog_tags_desc_extraction_chain.run(blog_tags_desc_prompt)
|
| 97 |
+
|
| 98 |
+
return blog_tags_desc
|
blog_ideas_description_generation.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
|
| 4 |
+
def blog_idea_desc_gen(blog, llm):
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
blog_idea_desc_prompt = f"Suggest at least 5 SEO-friendly titles and meta descriptions for the following blog post {blog}. Use a persuasive and intriguing tone."
|
| 8 |
+
blog_idea_desc_promptTemp = PromptTemplate(
|
| 9 |
+
input_variables=["text_input"],
|
| 10 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
| 11 |
+
blog_idea_desc_extraction_chain = LLMChain(llm=llm, prompt=blog_idea_desc_promptTemp)
|
| 12 |
+
blog_idea_desc = blog_idea_desc_extraction_chain.run(blog_idea_desc_prompt)
|
| 13 |
+
|
| 14 |
+
return blog_idea_desc
|
| 15 |
+
|