Spaces:
No application file
No application file
Commit
·
6c95d0c
1
Parent(s):
7623f20
Upload 5 files
Browse files- idea_generation.py +104 -0
- insta_image_caption_generation.py +27 -0
- keywords_generation.py +83 -0
- landing_page_generation.py +13 -0
- linkedIn_ads_generation.py +15 -0
idea_generation.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def ideas_generator(topic, keywords, llm, tone_of_voice='Professional', num_of_ideas=3):
|
| 6 |
+
|
| 7 |
+
'''
|
| 8 |
+
Description:
|
| 9 |
+
|
| 10 |
+
The ideas_generator() function designed to generate catchy short or long form article titles for a given topic,
|
| 11 |
+
utilizing a set of specified keywords.
|
| 12 |
+
This function employs a language model to create these titles,
|
| 13 |
+
The function can produce either a single title or multiple titles based on the value of the num argument and supports both concise and informative title generation.
|
| 14 |
+
'''
|
| 15 |
+
|
| 16 |
+
'''
|
| 17 |
+
Parameters:
|
| 18 |
+
|
| 19 |
+
topic (str, required): The topic or subject matter of the article for which you want to generate titles.
|
| 20 |
+
keywords (str, required): A list of keywords that should be used to help generate catchy titles relevant to the topic. These keywords can provide context and improve the quality of the titles.
|
| 21 |
+
llm (langchain.llms object, required): An instance of a pre-trained language model (e.g., GPT-3 or GPT-4) that will be used to generate the titles. This model should be provided by the user.
|
| 22 |
+
num_of_ideas (int, optional): The number of long-form titles to generate. If num is set to 1, the function will produce a single title. If num is greater than 1, it will generate multiple titles. Default is 3.
|
| 23 |
+
tone_of_voice (str, optional): A String to determine the tone of voice of the title. Default Value Professional
|
| 24 |
+
'''
|
| 25 |
+
|
| 26 |
+
'''
|
| 27 |
+
Returns:
|
| 28 |
+
|
| 29 |
+
ideas (str): Functions returns a text with number of ideas numbered with roman numerals
|
| 30 |
+
'''
|
| 31 |
+
|
| 32 |
+
if num_of_ideas == 1:
|
| 33 |
+
|
| 34 |
+
ideas_prompt = f"Generate only 1 {tone_of_voice} and catchy Innovation title for my article about {topic} topic.\n\nuse this keywords to help you generate {tone_of_voice} catchy title: {keywords}."
|
| 35 |
+
|
| 36 |
+
else:
|
| 37 |
+
ideas_prompt = f"Generate only {num_of_ideas} {tone_of_voice} and catchy Innovation titles for my article about {topic} topic.\n\nuse this keywords to help you generate {tone_of_voice} catchy titles: {keywords}."
|
| 38 |
+
|
| 39 |
+
ideas_promptTemp = PromptTemplate(
|
| 40 |
+
input_variables=["text_input"],
|
| 41 |
+
template="You are a professional content creator and Title Generator:\n\n{text_input}\n\n:Titles (number them with roman numerals):")
|
| 42 |
+
|
| 43 |
+
ideas_extraction_chain = LLMChain(llm=llm, prompt=ideas_promptTemp)
|
| 44 |
+
ideas = ideas_extraction_chain.run(ideas_prompt)
|
| 45 |
+
|
| 46 |
+
return ideas
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def filter_ideas(ideas):
|
| 50 |
+
|
| 51 |
+
'''
|
| 52 |
+
Description:
|
| 53 |
+
|
| 54 |
+
The filter_ideas() function extracts and filters article titles numbered with roman numerals from a given block of text.
|
| 55 |
+
This function uses a regular expression to identify and extract these titles and returns them as a list of strings.
|
| 56 |
+
'''
|
| 57 |
+
'''
|
| 58 |
+
Parameters:
|
| 59 |
+
|
| 60 |
+
ideas (str): A block of text that contain article titles formatted with Roman numerals and their corresponding content.
|
| 61 |
+
'''
|
| 62 |
+
|
| 63 |
+
'''
|
| 64 |
+
Returns
|
| 65 |
+
filtered_ideas (list of str): A list of long-form article titles extracted from the input text.
|
| 66 |
+
'''
|
| 67 |
+
pattern = r'\b[IVXLCDM]+\.\s*(.*?)(?:\n|$)'
|
| 68 |
+
filtered_ideas = re.findall(pattern, ideas)
|
| 69 |
+
|
| 70 |
+
return filtered_ideas
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def pick_idea(list_ideas):
|
| 74 |
+
|
| 75 |
+
"""
|
| 76 |
+
Description:
|
| 77 |
+
|
| 78 |
+
The pick_idea() function allows a user to choose one idea from a list of ideas.
|
| 79 |
+
It presents the user with a numbered list of ideas and prompts them to select an idea by typing the corresponding number.
|
| 80 |
+
The selected idea is then returned as the output of the function.
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
"""
|
| 84 |
+
Parameters:
|
| 85 |
+
|
| 86 |
+
list_ideas (list of str): A list of ideas from which the user will choose one.
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
"""
|
| 90 |
+
Return:
|
| 91 |
+
|
| 92 |
+
idea (str): The idea selected by the user from the list of ideas.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
print("Choose One Idea:\n")
|
| 96 |
+
|
| 97 |
+
for counter, idea in enumerate(list_ideas):
|
| 98 |
+
c = counter+1
|
| 99 |
+
print(f"{c}. {idea}")
|
| 100 |
+
|
| 101 |
+
x = int(input("Type the number of the idea: "))
|
| 102 |
+
idea = list_ideas[x-1]
|
| 103 |
+
|
| 104 |
+
return idea
|
insta_image_caption_generation.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from langchain.prompts import PromptTemplate
|
| 3 |
+
from langchain.chains import LLMChain
|
| 4 |
+
|
| 5 |
+
def img2text(url):
|
| 6 |
+
|
| 7 |
+
image_to_text = pipeline("image-to-text", model='Salesforce/blip-image-captioning-base')
|
| 8 |
+
|
| 9 |
+
text = image_to_text(url)
|
| 10 |
+
|
| 11 |
+
out = text[0]['generated_text']
|
| 12 |
+
|
| 13 |
+
return out
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def generate_InstaCap(scenario, tone_of_voice, form, llm):
|
| 17 |
+
|
| 18 |
+
instaCap_prompt = f"Craft a {form} Caption on my Instagram Image Here is the description of my Instagram Image: {scenario}.\nThe tone should be {tone_of_voice}"
|
| 19 |
+
|
| 20 |
+
instaCap_promptTemp = PromptTemplate(
|
| 21 |
+
input_variables=["text_input"],
|
| 22 |
+
template="You are infulencer:\n{text_input}\nInstagram Caption:")
|
| 23 |
+
|
| 24 |
+
instaCap_extraction_chain = LLMChain(llm=llm, prompt=instaCap_promptTemp)
|
| 25 |
+
instaCap = instaCap_extraction_chain.run(instaCap_prompt)
|
| 26 |
+
|
| 27 |
+
return instaCap
|
keywords_generation.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def keywords_generator(topic, llm, num_keywords=10):
|
| 6 |
+
|
| 7 |
+
'''
|
| 8 |
+
Description:
|
| 9 |
+
|
| 10 |
+
Generates a list of keywords for a given topic using a large language model (LLM).
|
| 11 |
+
'''
|
| 12 |
+
|
| 13 |
+
'''
|
| 14 |
+
Parameters:
|
| 15 |
+
|
| 16 |
+
topic (str): Required Parameter -> The topic for which to generate keywords.
|
| 17 |
+
llm (langchain.llms object): Required Parameter -> The LLM to use for generating keywords.
|
| 18 |
+
num_keywords (int): Optional Parameter -> The number of keywords to generate. Default Value is 10
|
| 19 |
+
long_tail_keywords (bool): Optional Parameter -> A boolean flag indicating whether to generate long-tail keywords. Default Value is False
|
| 20 |
+
'''
|
| 21 |
+
|
| 22 |
+
'''
|
| 23 |
+
Returns:
|
| 24 |
+
Keywords (str): A Text of list of keywords numbered with roman numerals for the given topic -> str datatype.
|
| 25 |
+
'''
|
| 26 |
+
|
| 27 |
+
keywords_prompt = f"Identify {num_keywords} SEO keywords related to '{topic}'."
|
| 28 |
+
|
| 29 |
+
keywords_promptTemp = PromptTemplate(
|
| 30 |
+
input_variables=["text_input"],
|
| 31 |
+
template="You are a professional content creator and SEO Keywords Generator:\n\n{text_input}\n\nKeywords (number them with roman numerals):")
|
| 32 |
+
|
| 33 |
+
keywords_extraction_chain = LLMChain(llm=llm, prompt=keywords_promptTemp)
|
| 34 |
+
keywords = keywords_extraction_chain.run(keywords_prompt)
|
| 35 |
+
|
| 36 |
+
return keywords
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def filter_keywords(keywords):
|
| 40 |
+
'''
|
| 41 |
+
Description:
|
| 42 |
+
|
| 43 |
+
Filters keywords to extract the keywords that numbered with roman numerals using regx
|
| 44 |
+
'''
|
| 45 |
+
|
| 46 |
+
'''
|
| 47 |
+
Parameters:
|
| 48 |
+
|
| 49 |
+
keywords (str): Required Parameter -> A Text of keywords Numbered with roman numerals to filter.
|
| 50 |
+
'''
|
| 51 |
+
|
| 52 |
+
'''
|
| 53 |
+
Returns:
|
| 54 |
+
|
| 55 |
+
filtered_keywords(list): A filtered list of keywords.
|
| 56 |
+
'''
|
| 57 |
+
|
| 58 |
+
pattern = r'\b[IVXLCDM]+\.\s*(.*?)(?:\n|$)'
|
| 59 |
+
filtered_keywords = re.findall(pattern, keywords)
|
| 60 |
+
|
| 61 |
+
return filtered_keywords
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def process_keywords(list_keywords):
|
| 65 |
+
|
| 66 |
+
'''
|
| 67 |
+
Description:
|
| 68 |
+
Formats a list of keywords into a comma-separated string.
|
| 69 |
+
'''
|
| 70 |
+
|
| 71 |
+
'''
|
| 72 |
+
Parameters:
|
| 73 |
+
|
| 74 |
+
list_keywords (list):Required Parameters -> A list of keywords to format.
|
| 75 |
+
'''
|
| 76 |
+
|
| 77 |
+
'''
|
| 78 |
+
Returns:
|
| 79 |
+
|
| 80 |
+
formatted_keywords (str): A comma-separated string of keywords.
|
| 81 |
+
'''
|
| 82 |
+
formatted_keywords = ", ".join(list_keywords)
|
| 83 |
+
return formatted_keywords
|
landing_page_generation.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
|
| 4 |
+
def landing_page_gen(product_name, product_desc, target_audience, goal, llm):
|
| 5 |
+
|
| 6 |
+
landing_page_prompt = f"Generate a landing page content for {product_name}. {product_name} is {product_desc} that is targeted at {target_audience} and has the goal of {goal}. The landing page should be clear, concise, and persuasive. It should also include a call to action."
|
| 7 |
+
landing_page_promptTemp = PromptTemplate(
|
| 8 |
+
input_variables=["text_input"],
|
| 9 |
+
template="{text_input}")
|
| 10 |
+
landing_page_extraction_chain = LLMChain(llm=llm, prompt=landing_page_promptTemp)
|
| 11 |
+
landing_page = landing_page_extraction_chain.run(landing_page_prompt)
|
| 12 |
+
|
| 13 |
+
return landing_page
|
linkedIn_ads_generation.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.prompts import PromptTemplate
|
| 2 |
+
from langchain.chains import LLMChain
|
| 3 |
+
|
| 4 |
+
def linkedIn_ads_gen(product_name, product_desc, target_audience, target_keywords, llm):
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
linkedIn_ads_prompt = f"Generate a LinkedIn ad for {product_name}. {product_name} is {product_desc} that is targeted at {target_audience} and uses the keywords {target_keywords}. The ad should be persuasive and engaging, and it should include a call to action."
|
| 8 |
+
|
| 9 |
+
linkedIn_ads_promptTemp = PromptTemplate(
|
| 10 |
+
input_variables=["text_input"],
|
| 11 |
+
template="You are a Professional LinkedIn Ad Copywriter:\n{text_input}\nFacebook Ad:")
|
| 12 |
+
linkedIn_ad_extraction_chain = LLMChain(llm=llm, prompt=linkedIn_ads_promptTemp)
|
| 13 |
+
linkedIn_ad = linkedIn_ad_extraction_chain.run(linkedIn_ads_prompt)
|
| 14 |
+
|
| 15 |
+
return linkedIn_ad
|