Spaces:
Runtime error
Runtime error
from langchain.prompts import PromptTemplate | |
from langchain.chains import LLMChain | |
class blog_content_generation: | |
''' | |
Description: | |
This Python class, blog_content_generation, is designed to facilitate the creation of various blog-related content using a language model (LLM). | |
It offers functionalities to generate blog post ideas, descriptions, actual posts, and relevant tags for search engine optimization (SEO). | |
Class Methods: | |
__init__(self, llm) | |
Description: Initializes the blog_content_generation class by setting the language model (llm) to be used for content generation. | |
Parameters: | |
llm: The language model instance used for generating content. | |
blog_idea_desc_gen(self, blog) | |
Description: Generates SEO-friendly titles and meta descriptions for a given blog post topic. | |
Parameters: | |
blog: The title or topic of the blog post. | |
Returns: | |
blog_idea_desc: A list of suggested titles and meta descriptions. | |
blog_idea_gen(self, topic) | |
Description: Creates a list of SEO-friendly blog post ideas with emotional and persuasive titles based on a specific topic. | |
Parameters: | |
topic: The subject or theme for which blog post ideas are requested. | |
Returns: | |
blog_idea: A list containing at least 10 suggested blog post ideas. | |
blog_post_gen(self, topic) | |
Description: Generates a blog post on a given topic. | |
Parameters: | |
topic: The subject or theme for the blog post content. | |
Returns: | |
blog_post: The generated blog post content. | |
blog_tags_gen(self, blog) | |
Description: Suggests tags for a specific blog post. | |
Parameters: | |
blog: The title or topic of the blog post for which tags are needed. | |
Returns: | |
blog_tags_desc: A list of suggested tags related to the provided blog post. | |
''' | |
def __init__(self, llm): | |
self.llm = llm | |
def blog_idea_desc_gen(self, blog): | |
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." | |
blog_idea_desc_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:") | |
blog_idea_desc_extraction_chain = LLMChain(llm=self.llm, prompt=blog_idea_desc_promptTemp) | |
blog_idea_desc = blog_idea_desc_extraction_chain.run(blog_idea_desc_prompt) | |
return blog_idea_desc | |
def blog_idea_gen(self, topic): | |
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." | |
blog_idea_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:") | |
blog_idea_extraction_chain = LLMChain(llm=self.llm, prompt=blog_idea_promptTemp) | |
blog_idea = blog_idea_extraction_chain.run(blog_idea_prompt) | |
return blog_idea | |
def blog_post_gen(self, topic): | |
blog_post_prompt = f"Write a blog Plost about {topic}." | |
blog_post_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="You are a Professional Content Creator and Blog Writer:\n{text_input}\nBlog Post:") | |
blog_post_extraction_chain = LLMChain(llm=self.llm, prompt=blog_post_promptTemp) | |
blog_post = blog_post_extraction_chain.run(blog_post_prompt) | |
return blog_post | |
def blog_tags_gen(self, blog): | |
blog_tags_desc_prompt = f" Suggest at least 5 tags for the following blog post.\n{blog}" | |
blog_tags_desc_promptTemp = PromptTemplate( | |
input_variables=["text_input"], | |
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:") | |
blog_tags_desc_extraction_chain = LLMChain(llm=self.llm, prompt=blog_tags_desc_promptTemp) | |
blog_tags_desc = blog_tags_desc_extraction_chain.run(blog_tags_desc_prompt) | |
return blog_tags_desc |