Spaces:
Runtime error
Runtime error
Commit
·
dfc4131
1
Parent(s):
46c260f
Upload 17 files
Browse files- README.md +1 -13
- X_content_creation.py +350 -53
- app.py +170 -93
- article_generation.py +80 -42
- blog_content_creation.py +194 -38
- calling_apis.py +8 -0
- email_writer.py +171 -26
- idea_generation.py +64 -14
- keywords_generation.py +121 -12
- linkedin_content_creation.py +137 -0
- meta_content_creation.py +250 -52
- outline_generation.py +60 -29
- product_description_generation.py +46 -7
- workout_plan_generation.py +79 -16
README.md
CHANGED
@@ -1,13 +1 @@
|
|
1 |
-
|
2 |
-
title: TexGen
|
3 |
-
emoji: 🦀
|
4 |
-
colorFrom: indigo
|
5 |
-
colorTo: red
|
6 |
-
sdk: streamlit
|
7 |
-
sdk_version: 1.29.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Build Feather AI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
X_content_creation.py
CHANGED
@@ -1,83 +1,380 @@
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
class X_Generator:
|
|
|
|
|
|
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
x_camp = x_camp_extraction_chain.run(x_camp_prompt)
|
20 |
|
21 |
return x_camp
|
22 |
|
23 |
-
def x_retweet_commenting_gen(self, tweet, tone_of_voice):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
x_retweet_comment = x_retweet_comment_extraction_chain.run(x_retweet_comment_prompt)
|
31 |
|
32 |
return x_retweet_comment
|
33 |
|
34 |
-
def X_thread_gen(self, topic, num_tweets, tone_of_voice):
|
35 |
-
|
36 |
-
X_thread_prompt = f"Write a an engagging Twitter Thread on '{topic}' consists of {num_tweets} tweets. Tone should be {tone_of_voice}"
|
37 |
-
|
38 |
-
X_thread_promptTemp = PromptTemplate(
|
39 |
-
input_variables=["text_input"],
|
40 |
-
template="You are a Twitter Content Creator:\n{text_input}\n\nTwitter Thread:")
|
41 |
|
42 |
-
|
43 |
-
X_thread = X_thread_extraction_chain.run(X_thread_prompt)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
X_thread_extraction_chain = LLMChain(llm=self.llm, prompt=X_thread_promptTemp)
|
56 |
-
X_thread = X_thread_extraction_chain.run(X_thread_prompt)
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
x_bio = x_bio_extraction_chain.run(x_bio_prompt)
|
68 |
|
69 |
return x_bio
|
70 |
|
71 |
-
def article_to_x_thread_gen(self, article):
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
|
|
82 |
|
|
|
|
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
7 |
+
|
8 |
|
9 |
class X_Generator:
|
10 |
+
|
11 |
+
"""
|
12 |
+
X_Generator: A class designed to generate various Twitter-related content using language models.
|
13 |
|
14 |
+
This class contains methods that leverage language models to generate diverse content
|
15 |
+
for Twitter campaigns, retweet comments, Twitter threads, bios, and converting articles
|
16 |
+
into coherent Twitter threads.
|
17 |
+
"""
|
18 |
+
|
19 |
+
|
20 |
+
def x_camp_gen(self, product_name:str, product_desc:str, goal:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
21 |
|
22 |
+
"""
|
23 |
+
Generates a Twitter campaign prompt based on product information.
|
24 |
|
25 |
+
Parameters:
|
26 |
+
- product_name (str): Name of the product.
|
27 |
+
- product_desc (str): Description of the product.
|
28 |
+
- goal (str): Goal or objective of the campaign.
|
29 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
30 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
31 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
32 |
+
|
33 |
|
34 |
+
Returns:
|
35 |
+
- x_camp (str): Generated content for the Twitter campaign.
|
36 |
+
"""
|
37 |
+
|
38 |
+
temp = 0
|
39 |
+
|
40 |
+
if creativity == 'Original':
|
41 |
+
temp = 0
|
42 |
+
elif creativity == 'Balanced':
|
43 |
+
temp = 0.25
|
44 |
+
elif creativity == 'Creative':
|
45 |
+
temp = 0.5
|
46 |
+
elif creativity == 'Spirited':
|
47 |
+
temp = 0.75
|
48 |
+
elif creativity == 'Visionary':
|
49 |
+
temp = 1
|
50 |
+
|
51 |
+
|
52 |
+
if model_name == 'Google Palm 2':
|
53 |
+
llm = call_palm(google_api_key, temperature=temp)
|
54 |
+
|
55 |
+
elif model_name == 'GPT-3.5':
|
56 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
57 |
+
|
58 |
+
elif model_name == 'GPT-4':
|
59 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
if language == 'En':
|
64 |
+
|
65 |
+
x_camp_prompt = f"Design a potent Twitter campaign for my product '{product_name}'. {product_name} is {product_desc} aiming to accomplish {goal} through the meticulous adoption of planning and content creation best practices.\n\nCampaign will include: Campaign Teaser, Educational Content Series, Customer Testimonials and Case Studies, Interactive Content, Limited-Time Offer Announcement, Call-to-Action for Consultation and Recap and Thank You."
|
66 |
+
x_camp_promptTemp = PromptTemplate(
|
67 |
+
input_variables=["text_input"],
|
68 |
+
template="You are a Specialist in Twitter Copywriting\n\n{text_input}\n\nMake the tweets engaging, creative and coherent")
|
69 |
+
|
70 |
+
elif language == 'Ar':
|
71 |
+
|
72 |
+
x_camp_prompt = f"قم بتصميم حملة تويتر قوية لمنتجي '{product_name}'. {product_name} هو {product_desc} يهدف إلى تحقيق {goal} من خلال اعتماد دقيق على أفضل الممارسات في التخطيط وإنشاء المحتوى.\n\nستتضمن الحملة: العرض التشويقي للحملة، سلسلة محتوى تعليمي، شهادات العملاء ودراسات الحالة، محتوى تفاعلي، إعلان عن عرض لفترة محدودة، دعوة للعمل والاستشارة، وإعادة النظر والشكر."
|
73 |
+
x_camp_promptTemp = PromptTemplate(
|
74 |
+
input_variables=["text_input"],
|
75 |
+
template="أنت متخصص في كتابة التغريدات على تويتر\n\n{text_input}\n\nاجعل التغريدات جذابة وإبداعية ومترابطة")
|
76 |
+
|
77 |
+
x_camp_extraction_chain = LLMChain(llm=llm, prompt=x_camp_promptTemp)
|
78 |
x_camp = x_camp_extraction_chain.run(x_camp_prompt)
|
79 |
|
80 |
return x_camp
|
81 |
|
82 |
+
def x_retweet_commenting_gen(self, tweet:str, tone_of_voice:str, language = 'En', model_name='Google Palm 2', creativity='Original')->str:
|
83 |
+
|
84 |
+
"""
|
85 |
+
Generates a X Retweet Commenting based on the quote or commenting tweet.
|
86 |
+
|
87 |
+
Parameters:
|
88 |
+
- tweet (str): The Quoted or commented tweet.
|
89 |
+
- tone_of_voice (str): tone of voice of the generated content.
|
90 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
91 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
92 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
93 |
+
|
94 |
+
Returns:
|
95 |
+
- x_retweet_comment (str): Generated content for the Twitter campaign.
|
96 |
+
"""
|
97 |
+
|
98 |
+
temp = 0
|
99 |
+
|
100 |
+
if creativity == 'Original':
|
101 |
+
temp = 0
|
102 |
+
elif creativity == 'Balanced':
|
103 |
+
temp = 0.25
|
104 |
+
elif creativity == 'Creative':
|
105 |
+
temp = 0.5
|
106 |
+
elif creativity == 'Spirited':
|
107 |
+
temp = 0.75
|
108 |
+
elif creativity == 'Visionary':
|
109 |
+
temp = 1
|
110 |
+
|
111 |
+
|
112 |
+
if model_name == 'Google Palm 2':
|
113 |
+
llm = call_palm(google_api_key, temperature=temp)
|
114 |
+
|
115 |
+
elif model_name == 'GPT-3.5':
|
116 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
117 |
+
|
118 |
+
elif model_name == 'GPT-4':
|
119 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
120 |
+
|
121 |
+
|
122 |
+
if language == 'En':
|
123 |
+
|
124 |
+
x_retweet_comment_prompt = f"I'm planning to retweet the following tweet:\n“{tweet}”\nConstruct 5 varied comments I could append to this retweet. tone should be {tone_of_voice}"
|
125 |
+
x_retweet_comment_promptTemp = PromptTemplate(
|
126 |
+
input_variables=["text_input"],
|
127 |
+
template="You are Specilaized Twitter Copywriter\n{text_input}\n\nRetweet Comment:")
|
128 |
+
|
129 |
+
elif language == 'Ar':
|
130 |
+
|
131 |
+
x_retweet_comment_prompt = f"أنا أخطط لإعادة نشر التغريدة التالية:\n“{tweet}”\nقم بصياغة 5 تعليقات متنوعة يمكنني إلحاقها بهذا الإعادة. يجب أن يكون النبرة {tone_of_voice}."
|
132 |
+
x_retweet_comment_promptTemp = PromptTemplate(
|
133 |
+
input_variables=["text_input"],
|
134 |
+
template="أنت كاتب نصوص تويتر متخصص\n{text_input}\n\nتعليق إعادة التغريد:")
|
135 |
+
|
136 |
+
x_retweet_comment_extraction_chain = LLMChain(llm=llm, prompt=x_retweet_comment_promptTemp)
|
137 |
x_retweet_comment = x_retweet_comment_extraction_chain.run(x_retweet_comment_prompt)
|
138 |
|
139 |
return x_retweet_comment
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
+
def x_thread_gen_intro(self, topic:str, thread:str, tone_of_voice:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
|
|
143 |
|
144 |
+
"""
|
145 |
+
Generates a X Retweet Commenting based on the quote or commenting tweet.
|
146 |
+
|
147 |
+
Parameters:
|
148 |
+
- tweet (str): The Quoted or commented tweet.
|
149 |
+
- tone_of_voice (str): tone of voice of the generated content.
|
150 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
151 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
152 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
153 |
|
154 |
+
Returns:
|
155 |
+
- x_retweet_comment (str): Generated content for the Twitter campaign.
|
156 |
+
"""
|
157 |
+
|
158 |
+
temp = 0
|
159 |
+
|
160 |
+
if creativity == 'Original':
|
161 |
+
temp = 0
|
162 |
+
elif creativity == 'Balanced':
|
163 |
+
temp = 0.25
|
164 |
+
elif creativity == 'Creative':
|
165 |
+
temp = 0.5
|
166 |
+
elif creativity == 'Spirited':
|
167 |
+
temp = 0.75
|
168 |
+
elif creativity == 'Visionary':
|
169 |
+
temp = 1
|
170 |
+
|
171 |
+
|
172 |
+
if model_name == 'Google Palm 2':
|
173 |
+
llm = call_palm(google_api_key, temperature=temp)
|
174 |
+
|
175 |
+
elif model_name == 'GPT-3.5':
|
176 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
177 |
+
|
178 |
+
elif model_name == 'GPT-4':
|
179 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
180 |
+
|
181 |
+
|
182 |
+
if language == 'En':
|
183 |
|
184 |
+
x_thread_intro_prompt = f"Write a an engagging and attractive Introduction head tweet for my twitter thread on {topic}. here is my twitter thread:\n{thread}\nTone should be {tone_of_voice}"
|
185 |
+
x_thread_intro_promptTemp = PromptTemplate(
|
186 |
+
input_variables=["text_input"],
|
187 |
+
template="You are a Twitter Content Creator:\n{text_input}\n\nIntroduction Tweet:")
|
|
|
|
|
188 |
|
189 |
+
elif language == 'Ar':
|
190 |
+
|
191 |
+
x_thread_intro_prompt = f"اكتب تغريدة تعريفية جذابة وجذابة للثريد الخاص بي على تويتر {topic}. إليك الثريد الخاص بي على تويتر:\n{thread}\nيجب أن يكون الأسلوب {tone_of_voice}"
|
192 |
+
x_thread_intro_promptTemp = PromptTemplate(
|
193 |
+
input_variables=["text_input"],
|
194 |
+
template="أنت مُنشئ محتوى على تويتر:\n{text_input}\n\n التغريدة التعريفية:")
|
195 |
+
|
196 |
+
x_thread_intro_extraction_chain = LLMChain(llm=llm, prompt=x_thread_intro_promptTemp)
|
197 |
+
x_thread_intro = x_thread_intro_extraction_chain.run(x_thread_intro_prompt)
|
198 |
+
|
199 |
+
return x_thread_intro
|
200 |
+
|
201 |
+
def x_thread_gen(self, topic:str, num_tweets:int, tone_of_voice:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
202 |
+
|
203 |
+
"""
|
204 |
+
Generates a X Retweet Commenting based on the quote or commenting tweet.
|
205 |
+
|
206 |
+
Parameters:
|
207 |
+
- tweet (str): The Quoted or commented tweet.
|
208 |
+
- tone_of_voice (str): tone of voice of the generated content.
|
209 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
210 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
211 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
212 |
+
|
213 |
+
Returns:
|
214 |
+
- x_retweet_comment (str): Generated content for the Twitter campaign.
|
215 |
+
"""
|
216 |
+
|
217 |
+
temp = 0
|
218 |
+
|
219 |
+
if creativity == 'Original':
|
220 |
+
temp = 0
|
221 |
+
elif creativity == 'Balanced':
|
222 |
+
temp = 0.25
|
223 |
+
elif creativity == 'Creative':
|
224 |
+
temp = 0.5
|
225 |
+
elif creativity == 'Spirited':
|
226 |
+
temp = 0.75
|
227 |
+
elif creativity == 'Visionary':
|
228 |
+
temp = 1
|
229 |
+
|
230 |
+
|
231 |
+
if model_name == 'Google Palm 2':
|
232 |
+
llm = call_palm(google_api_key, temperature=temp)
|
233 |
+
|
234 |
+
elif model_name == 'GPT-3.5':
|
235 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
236 |
+
|
237 |
+
elif model_name == 'GPT-4':
|
238 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
239 |
+
|
240 |
+
|
241 |
+
if language == 'En':
|
242 |
+
|
243 |
+
x_thread_prompt = f"Write a an engagging Twitter Thread on '{topic}' consists of {num_tweets} tweets. Tone should be {tone_of_voice}"
|
244 |
+
x_thread_promptTemp = PromptTemplate(
|
245 |
+
input_variables=["text_input"],
|
246 |
+
template="You are a Twitter Content Creator:\n{text_input}\n\nTwitter Thread:")
|
247 |
+
|
248 |
+
elif language == 'Ar':
|
249 |
+
|
250 |
+
x_thread_prompt = f"اكتب سلسلة تغريدات جذابة (ثريد) عن '{topic}' تتكون من {num_tweets} الثريد. يجب أن يكون اللهجة {tone_of_voice}."
|
251 |
+
x_thread_promptTemp = PromptTemplate(
|
252 |
+
input_variables=["text_input"],
|
253 |
+
template="أنت مُنشئ محتوى على تويتر:\n{text_input}\n\n الثريد:")
|
254 |
+
|
255 |
+
x_thread_extraction_chain = LLMChain(llm=llm, prompt=x_thread_promptTemp)
|
256 |
+
x_thread = x_thread_extraction_chain.run(x_thread_prompt)
|
257 |
+
|
258 |
+
return x_thread
|
259 |
+
|
260 |
|
261 |
+
def x_bio_gen(self, info:str, tone_of_voice:str, language='En', model_name = 'Google Palm 2', creativity = 'Original')->str:
|
262 |
+
|
263 |
+
"""
|
264 |
+
Generates an X Bio based on given Profile.
|
265 |
+
|
266 |
+
Parameters:
|
267 |
+
- info (str): Information about the X user.
|
268 |
+
- tone_of_voice (str): tone of voice of the generated X Bio.
|
269 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
270 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
271 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
272 |
+
|
273 |
+
Returns:
|
274 |
+
- x_bio (str): Generated X Bio for The X user.
|
275 |
+
"""
|
276 |
+
|
277 |
+
temp = 0
|
278 |
+
|
279 |
+
if creativity == 'Original':
|
280 |
+
temp = 0
|
281 |
+
elif creativity == 'Balanced':
|
282 |
+
temp = 0.25
|
283 |
+
elif creativity == 'Creative':
|
284 |
+
temp = 0.5
|
285 |
+
elif creativity == 'Spirited':
|
286 |
+
temp = 0.75
|
287 |
+
elif creativity == 'Visionary':
|
288 |
+
temp = 1
|
289 |
+
|
290 |
+
|
291 |
+
if model_name == 'Google Palm 2':
|
292 |
+
llm = call_palm(google_api_key, temperature=temp)
|
293 |
+
|
294 |
+
elif model_name == 'GPT-3.5':
|
295 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
296 |
+
|
297 |
+
elif model_name == 'GPT-4':
|
298 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
299 |
+
|
300 |
+
|
301 |
+
if language == 'En':
|
302 |
+
|
303 |
+
x_bio_prompt = f"Craft a personalized Twitter bio for me, based on the content I create, related to {info}. tone should be {tone_of_voice}, Produce 10 tailor-made Twitter bios for me."
|
304 |
+
x_bio_promptTemp = PromptTemplate(
|
305 |
+
input_variables=["text_input"],
|
306 |
+
template="You are a copywriter\n{text_input}\n\nTwitter Bios:")
|
307 |
+
|
308 |
+
elif language == 'Ar':
|
309 |
+
|
310 |
+
x_bio_prompt = f"قم بكتابة لي سيرة ذاتية شخصية على تويتر، مستندة إلى المحتوى الذي أنشئه، ذات صلة بـ {info}. يجب أن يكون النبرة {tone_of_voice}. أنتج ١٠ سير ذاتية مُصمَّمة خصيصًا لتويتر بالنسبة لي."
|
311 |
+
x_bio_promptTemp = PromptTemplate(
|
312 |
+
input_variables=["text_input"],
|
313 |
+
template="أنت كاتب نسخ\n{text_input}\n\n السير الذاتية لتويتر:")
|
314 |
+
|
315 |
+
x_bio_extraction_chain = LLMChain(llm=llm, prompt=x_bio_promptTemp)
|
316 |
x_bio = x_bio_extraction_chain.run(x_bio_prompt)
|
317 |
|
318 |
return x_bio
|
319 |
|
320 |
+
def article_to_x_thread_gen(self, article:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
321 |
+
|
322 |
+
"""
|
323 |
+
Converts an article into a coherent Twitter thread.
|
324 |
+
|
325 |
+
Parameters:
|
326 |
+
|
327 |
+
- article (str): The article content to be transformed.
|
328 |
+
- language (str): Opitonal Parameter -> The language of the model.
|
329 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
330 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
331 |
+
|
332 |
+
|
333 |
+
Returns:
|
334 |
|
335 |
+
- article_to_x_thread (str): Generated coherent Twitter thread based on the article.
|
336 |
+
"""
|
337 |
+
|
338 |
+
temp = 0
|
339 |
+
|
340 |
+
if creativity == 'Original':
|
341 |
+
temp = 0
|
342 |
+
elif creativity == 'Balanced':
|
343 |
+
temp = 0.25
|
344 |
+
elif creativity == 'Creative':
|
345 |
+
temp = 0.5
|
346 |
+
elif creativity == 'Spirited':
|
347 |
+
temp = 0.75
|
348 |
+
elif creativity == 'Visionary':
|
349 |
+
temp = 1
|
350 |
+
|
351 |
|
352 |
+
if model_name == 'Google Palm 2':
|
353 |
+
llm = call_palm(google_api_key, temperature=temp)
|
354 |
|
355 |
+
elif model_name == 'GPT-3.5':
|
356 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
357 |
|
358 |
+
elif model_name == 'GPT-4':
|
359 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
360 |
+
|
361 |
+
|
362 |
+
|
363 |
+
if language == 'En':
|
364 |
+
|
365 |
+
article_to_x_thread_prompt = f"Transform the ensuing article into a sequence of Twitter posts, creating a coherent Twitter thread between 5 to 20 tweets\nArticle: “{article}.“"
|
366 |
+
article_to_x_thread_promptTemp = PromptTemplate(
|
367 |
+
input_variables=["text_input"],
|
368 |
+
template="You are a twitter copywriter\n{text_input}\n\nCoherent Twitter Thread:")
|
369 |
+
|
370 |
+
elif language == 'Ar':
|
371 |
+
|
372 |
+
article_to_x_thread_prompt = f"حوّل المقال الآتي إلى سلسلة من تغريدات تويتر، مكوّناً سلسلة تويتر مترابطة تتكون من 5 إلى 20 تغريدة. المقال : {article}"
|
373 |
+
article_to_x_thread_promptTemp = PromptTemplate(
|
374 |
+
input_variables=["text_input"],
|
375 |
+
template="أنت كاتب نصوص تويتر\n{text_input}\n\nسلسلة تويتر متناسقة:")
|
376 |
+
|
377 |
+
article_to_x_thread_extraction_chain = LLMChain(llm=llm, prompt=article_to_x_thread_promptTemp)
|
378 |
+
article_to_x_thread = article_to_x_thread_extraction_chain.run(article_to_x_thread_prompt)
|
379 |
+
|
380 |
+
return article_to_x_thread
|
app.py
CHANGED
@@ -1,37 +1,22 @@
|
|
1 |
from remove_astricks import remove_ast
|
2 |
from load_model import call_palm
|
3 |
-
from keywords_generation import keywords_generator, filter_keywords, process_keywords
|
4 |
from idea_generation import ideas_generator, filter_ideas
|
5 |
from outline_generation import outlines_generator, filtered_outlines
|
6 |
-
from article_generation import full_article
|
7 |
from product_description_generation import product_description_gen
|
8 |
-
from x_thread_generation import X_thread_gen, X_thread_gen_intro
|
9 |
-
from linkedin_post_generation import linkedIn_post_gen
|
10 |
-
from insta_image_caption_generation import img2text, generate_InstaCap
|
11 |
-
from facebook_post_generation import facebook_post_gen
|
12 |
-
from facebook_ads_generation import facebook_ads_gen
|
13 |
-
from facebook_campaign import facbook_camp_gen, social_media_camp_gen
|
14 |
-
from linkedIn_ads_generation import linkedIn_ads_gen
|
15 |
-
from email_marketing_campaigns_generation import email_marketing_campaigns_gen
|
16 |
from workout_plan_generation import workout_plan_gen
|
17 |
-
from
|
18 |
-
|
19 |
-
from x_bio_creation import x_bio_gen
|
20 |
-
from x_retweet_commenting_generation import x_retweet_commenting_gen
|
21 |
-
from article_conversion_to_x_thread import article_to_x_thread_gen
|
22 |
-
from x_campaign_generation import x_camp_gen
|
23 |
-
from blog_ideas_generation import blog_idea_gen
|
24 |
-
from blog_ideas_description_generation import blog_idea_desc_gen
|
25 |
-
from blog_post_tags_generation import blog_tags_gen
|
26 |
import X_content_creation
|
27 |
import blog_content_creation
|
28 |
import meta_content_creation
|
29 |
import email_writer
|
30 |
|
31 |
import streamlit as st
|
|
|
32 |
from dotenv import load_dotenv, find_dotenv
|
33 |
import os
|
34 |
-
import time
|
35 |
|
36 |
load_dotenv(find_dotenv())
|
37 |
google_api_key = os.environ['OPENAI_API_KEY']
|
@@ -42,12 +27,14 @@ if __name__ == '__main__':
|
|
42 |
llm = call_palm(google_api_key)
|
43 |
|
44 |
tone_of_voice_list = ('Excited', 'Professional', 'Encouraging', 'Funny', 'Dramatic', 'Witty', 'Sarcastic', 'Engaging', 'Creative')
|
45 |
-
|
|
|
|
|
46 |
|
47 |
with st.sidebar:
|
48 |
|
49 |
st.image('Logo.png')
|
50 |
-
choice = st.radio("Navigation", ["Articles and Blogs", "Product Description", "LinkedIn
|
51 |
st.info("Generate your Content with Feather AI in Seconds..")
|
52 |
|
53 |
|
@@ -57,40 +44,57 @@ if __name__ == '__main__':
|
|
57 |
product_name = st.text_input('Product Name')
|
58 |
product_desc = st.text_area('Product Description')
|
59 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
|
|
|
|
|
|
60 |
|
61 |
-
if product_name and product_desc and tone_of_voice:
|
62 |
|
63 |
if st.button('Generate'):
|
64 |
|
65 |
-
product_description = product_description_gen(product_name, product_desc, tone_of_voice,
|
66 |
st.markdown(product_description)
|
67 |
|
68 |
-
elif choice == 'LinkedIn
|
69 |
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
-
|
|
|
|
|
74 |
|
75 |
-
if st.button('Generate'):
|
76 |
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
|
|
|
80 |
|
81 |
-
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
target_audience = st.text_input("Target Audience")
|
86 |
-
target_keywords = st.text_input("Target Keywords")
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
if st.button("Generate"):
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
|
96 |
elif choice == "Gym Workout Plan":
|
@@ -106,11 +110,15 @@ if __name__ == '__main__':
|
|
106 |
routine = st.selectbox("Preferred Routine", routine_list)
|
107 |
my_goals = st.text_input('Goals')
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
|
111 |
if st.button('Generate'):
|
112 |
|
113 |
-
workout_plan = workout_plan_gen(my_goals, fitness_level, days, hours, health_consd, routine,
|
114 |
st.markdown(workout_plan)
|
115 |
|
116 |
elif choice == "Landing Page":
|
@@ -130,7 +138,7 @@ if __name__ == '__main__':
|
|
130 |
|
131 |
elif choice == 'X Content Creation':
|
132 |
|
133 |
-
X_content = X_content_creation.X_Generator(
|
134 |
|
135 |
x_choices_list = ('X thread', 'X Retweet Commenting', 'X Campaign', 'X Bio Creation', 'Article Conversion to X Thread')
|
136 |
|
@@ -141,13 +149,16 @@ if __name__ == '__main__':
|
|
141 |
topic = st.text_input('Topic')
|
142 |
num_tweets = st.slider('Number of Thread tweet', 1,10,5)
|
143 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
|
|
|
|
|
|
144 |
|
145 |
-
if topic and num_tweets and tone_of_voice:
|
146 |
|
147 |
if st.button('Generate'):
|
148 |
|
149 |
-
X_thread = X_content.
|
150 |
-
intro = X_content.
|
151 |
st.markdown(intro)
|
152 |
st.markdown(X_thread)
|
153 |
|
@@ -156,12 +167,15 @@ if __name__ == '__main__':
|
|
156 |
|
157 |
tweet = st.text_area('Tweet')
|
158 |
tone_of_voice = st.selectbox('Tone of voice', tone_of_voice_list)
|
|
|
|
|
|
|
159 |
|
160 |
-
if tweet and tone_of_voice:
|
161 |
|
162 |
if st.button('Generate'):
|
163 |
|
164 |
-
x_retweet_comment = X_content.x_retweet_commenting_gen(tweet, tone_of_voice)
|
165 |
st.markdown(x_retweet_comment)
|
166 |
|
167 |
elif x_choices == x_choices_list[2]:
|
@@ -169,76 +183,99 @@ if __name__ == '__main__':
|
|
169 |
product_name = st.text_input('Product Name')
|
170 |
product_desc = st.text_area('Product Description')
|
171 |
goal = st.text_input('Goal')
|
|
|
|
|
|
|
172 |
|
173 |
|
174 |
-
if product_name and product_desc and goal:
|
175 |
|
176 |
if st.button('Generate'):
|
177 |
|
178 |
-
x_camp = X_content.x_camp_gen(product_name, product_desc, goal)
|
179 |
st.markdown(x_camp)
|
180 |
|
181 |
elif x_choices == x_choices_list[3]:
|
182 |
|
183 |
info = st.text_area('info')
|
184 |
tone_of_voice = st.selectbox('Tone of voice', tone_of_voice_list)
|
|
|
|
|
|
|
185 |
|
186 |
-
if info and tone_of_voice:
|
187 |
|
188 |
if st.button('Generate'):
|
189 |
|
190 |
-
x_bio = X_content.x_bio_gen(info, tone_of_voice,
|
191 |
st.markdown(x_bio)
|
192 |
|
193 |
elif x_choices == x_choices_list[4]:
|
194 |
|
195 |
article = st.text_area('Article')
|
|
|
|
|
|
|
196 |
|
197 |
-
if article:
|
198 |
|
199 |
if st.button('Generate'):
|
200 |
|
201 |
-
article_to_x_thread = X_content.article_to_x_thread_gen(article)
|
202 |
st.markdown(article_to_x_thread)
|
203 |
|
204 |
elif choice == 'Articles and Blogs':
|
205 |
|
206 |
-
blog_content = blog_content_creation.blog_content_generation(
|
207 |
|
208 |
blog_choices_list = ('Article Writer', 'Blog Post', 'Blog Ideas', 'Blog Tags', 'Blog Ideas description')
|
209 |
|
210 |
blog_choices = st.selectbox('Choose Blog Template', blog_choices_list)
|
211 |
|
|
|
|
|
212 |
if blog_choices == blog_choices_list[0]:
|
213 |
|
214 |
topic = st.text_input('Topic')
|
215 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
|
|
|
|
|
|
216 |
|
217 |
-
if topic:
|
|
|
|
|
|
|
218 |
|
219 |
-
keywords = keywords_generator(topic, llm)
|
220 |
filtered_keywords = filter_keywords(keywords)
|
|
|
|
|
221 |
formatted_keywords = process_keywords(filtered_keywords)
|
|
|
222 |
|
223 |
st.markdown('### Generated Keywords:\n')
|
224 |
st.markdown(formatted_keywords)
|
225 |
|
226 |
formatted_keywords = remove_ast(formatted_keywords)
|
|
|
|
|
227 |
|
228 |
idea_numbers = st.slider("How many ideas you want?",1,10,5)
|
229 |
|
230 |
-
ideas = ideas_generator(topic,
|
231 |
filtered_ideas = filter_ideas(ideas)
|
232 |
|
233 |
index = 1
|
234 |
|
235 |
st.markdown("### Generated Ideas:\n")
|
|
|
236 |
for idea in filtered_ideas:
|
237 |
|
238 |
st.markdown(f"{index} - {idea}")
|
239 |
index+=1
|
240 |
|
241 |
st.text('\n')
|
|
|
242 |
num_idea = st.text_input("Choose the idea you want by number")
|
243 |
|
244 |
if num_idea:
|
@@ -247,73 +284,96 @@ if __name__ == '__main__':
|
|
247 |
idea = filtered_ideas[num_idea-1]
|
248 |
idea = remove_ast(idea)
|
249 |
|
250 |
-
outline = outlines_generator(idea,
|
|
|
251 |
st.text('\n')
|
252 |
st.markdown("### Generated Outline:\n")
|
253 |
st.markdown(outline)
|
254 |
outline_list = filtered_outlines(outline)
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
if st.button('Generate'):
|
258 |
|
259 |
-
article = full_article(idea,
|
260 |
|
261 |
st.markdown("# Your Article:\n")
|
262 |
st.markdown(f"{idea}\n")
|
263 |
st.markdown('\n\n'.join(article))
|
264 |
st.text('\n\n')
|
265 |
-
num_art_chars = len('\n'.join(article))
|
266 |
-
num_art_words = len('\n'.join(article).split(' '))
|
267 |
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
elif blog_choices == blog_choices_list[1]:
|
272 |
|
273 |
topic = st.text_input('Topic')
|
|
|
|
|
|
|
|
|
274 |
|
275 |
-
if topic:
|
276 |
|
277 |
if st.button('Generate'):
|
278 |
-
blog_post = blog_content.blog_post_gen(topic)
|
279 |
st.markdown(blog_post)
|
280 |
|
281 |
elif blog_choices == blog_choices_list[2]:
|
282 |
|
283 |
topic = st.text_input('Topic')
|
|
|
|
|
|
|
284 |
|
285 |
if topic:
|
286 |
|
287 |
if st.button('Generate'):
|
288 |
|
289 |
-
blog_idea = blog_content.blog_idea_gen(topic)
|
290 |
st.markdown(blog_idea)
|
291 |
|
292 |
elif blog_choices == blog_choices_list[4]:
|
293 |
|
294 |
-
|
|
|
|
|
|
|
295 |
|
296 |
-
if
|
297 |
|
298 |
if st.button('Generate'):
|
299 |
|
300 |
-
blog_idea_desc = blog_content.blog_idea_desc_gen(
|
301 |
st.markdown(blog_idea_desc)
|
302 |
|
303 |
elif blog_choices == blog_choices_list[3]:
|
304 |
|
305 |
blog = st.text_area('Blog')
|
|
|
|
|
|
|
306 |
|
307 |
-
if blog:
|
308 |
|
309 |
if st.button('Generate'):
|
310 |
|
311 |
-
blog_tags = blog_content.blog_tags_gen(blog)
|
312 |
st.markdown(blog_tags)
|
313 |
|
314 |
elif choice == 'Meta Content':
|
315 |
|
316 |
-
meta_content_gen = meta_content_creation.meta_content_generation(
|
317 |
|
318 |
meta_choices_list = ('Facebook Post', 'Facebook Ads', 'Facebook Campaign', 'Insta Image Captioning')
|
319 |
|
@@ -323,14 +383,16 @@ if __name__ == '__main__':
|
|
323 |
if meta_choices == meta_choices_list[0]:
|
324 |
|
325 |
topic = st.text_input("Topic")
|
326 |
-
|
327 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
|
|
|
|
|
|
328 |
|
329 |
-
if topic and tone_of_voice:
|
330 |
|
331 |
if st.button('Generate'):
|
332 |
|
333 |
-
facebook_post = meta_content_gen.facebook_post_gen(tone_of_voice, topic)
|
334 |
st.markdown(facebook_post)
|
335 |
|
336 |
elif meta_choices == meta_choices_list[1]:
|
@@ -339,15 +401,16 @@ if __name__ == '__main__':
|
|
339 |
product_desc = st.text_area('Description')
|
340 |
targeted_audience = st.text_input('Target Audience')
|
341 |
plans_proms = st.text_input('Plan and Promotions')
|
342 |
-
|
343 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
344 |
-
|
|
|
|
|
345 |
|
346 |
-
if product_name and product_desc and tone_of_voice:
|
347 |
|
348 |
if st.button('Generate'):
|
349 |
|
350 |
-
face_ad__prom = meta_content_gen.facebook_ads_gen(product_name, product_desc, tone_of_voice, targeted_audience, plans_proms)
|
351 |
st.markdown(face_ad__prom)
|
352 |
|
353 |
elif meta_choices == meta_choices_list[2]:
|
@@ -356,13 +419,16 @@ if __name__ == '__main__':
|
|
356 |
product_desc = st.text_area('Product Description')
|
357 |
days = st.selectbox('Days', (10,15,20,25,30))
|
358 |
goal = st.text_input('Goal')
|
|
|
|
|
|
|
359 |
|
360 |
-
if product_name and product_desc and goal and days:
|
361 |
|
362 |
if st.button('Generate'):
|
363 |
|
364 |
-
|
365 |
-
st.markdown(
|
366 |
|
367 |
elif meta_choices == meta_choices_list[3]:
|
368 |
|
@@ -385,16 +451,21 @@ if __name__ == '__main__':
|
|
385 |
|
386 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
387 |
form = st.selectbox('Caption Form', ('Short Form', 'Medium Form', 'Long Form'))
|
|
|
|
|
|
|
388 |
|
389 |
-
if
|
|
|
|
|
390 |
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
|
395 |
elif choice == 'Emails':
|
396 |
|
397 |
-
email_content_gen = email_writer.email_writing(
|
398 |
|
399 |
email_choices_list = ('Email Writer', 'Email Marketing Campaign')
|
400 |
|
@@ -407,12 +478,15 @@ if __name__ == '__main__':
|
|
407 |
sender_name = st.text_input('Sender Name')
|
408 |
position_sender = st.text_input('Sender Position')
|
409 |
description = st.text_area('Description')
|
|
|
|
|
|
|
410 |
|
411 |
-
if recipient and recipient_position and sender_name and position_sender and description:
|
412 |
|
413 |
if st.button('Generate'):
|
414 |
|
415 |
-
email = email_content_gen.email_gen(recipient, recipient_position, sender_name, position_sender, description)
|
416 |
email_subject = email_content_gen.email_subject_gen(email)
|
417 |
st.markdown(f'Subject: {email_subject}')
|
418 |
st.markdown(email)
|
@@ -423,12 +497,15 @@ if __name__ == '__main__':
|
|
423 |
product_description = st.text_area("Product Description")
|
424 |
target_audience = st.text_input("Target Audience")
|
425 |
goal = st.text_input("Goal")
|
|
|
|
|
|
|
426 |
|
427 |
-
if product_name and product_description and target_audience and goal:
|
428 |
|
429 |
if st.button("Generate"):
|
430 |
|
431 |
-
email_marketing_camp = email_content_gen.email_marketing_campaigns_gen(product_name, product_description, target_audience, goal)
|
432 |
st.markdown(email_marketing_camp)
|
433 |
|
434 |
|
|
|
1 |
from remove_astricks import remove_ast
|
2 |
from load_model import call_palm
|
3 |
+
from keywords_generation import keywords_generator, keywords_generator_long_tail, filter_keywords, process_keywords
|
4 |
from idea_generation import ideas_generator, filter_ideas
|
5 |
from outline_generation import outlines_generator, filtered_outlines
|
6 |
+
from article_generation import full_article
|
7 |
from product_description_generation import product_description_gen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from workout_plan_generation import workout_plan_gen
|
9 |
+
from linkedin_content_creation import linkedIn_content_gen
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
import X_content_creation
|
12 |
import blog_content_creation
|
13 |
import meta_content_creation
|
14 |
import email_writer
|
15 |
|
16 |
import streamlit as st
|
17 |
+
import spacy
|
18 |
from dotenv import load_dotenv, find_dotenv
|
19 |
import os
|
|
|
20 |
|
21 |
load_dotenv(find_dotenv())
|
22 |
google_api_key = os.environ['OPENAI_API_KEY']
|
|
|
27 |
llm = call_palm(google_api_key)
|
28 |
|
29 |
tone_of_voice_list = ('Excited', 'Professional', 'Encouraging', 'Funny', 'Dramatic', 'Witty', 'Sarcastic', 'Engaging', 'Creative')
|
30 |
+
languages = ('En', 'Ar', 'De', 'Fr', 'It', 'Es', 'Pt', 'Ru', 'Hi', 'Ja', 'Nl', 'Zh')
|
31 |
+
creativity_list = ('Original', 'Balanced', 'Creative', 'Spirited', 'Visionary')
|
32 |
+
models = ('Google Palm 2', 'GPT-3.5', 'GPT-4')
|
33 |
|
34 |
with st.sidebar:
|
35 |
|
36 |
st.image('Logo.png')
|
37 |
+
choice = st.radio("Navigation", ["Articles and Blogs", "Product Description", "LinkedIn Content", "Gym Workout Plan", "Landing Page", "X Content Creation", "Meta Content", "Emails"])
|
38 |
st.info("Generate your Content with Feather AI in Seconds..")
|
39 |
|
40 |
|
|
|
44 |
product_name = st.text_input('Product Name')
|
45 |
product_desc = st.text_area('Product Description')
|
46 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
47 |
+
model = st.selectbox('Choose the Model', models)
|
48 |
+
creativity = st.selectbox('Creativity Level', creativity_list)
|
49 |
+
language = st.selectbox('Choose a language', languages)
|
50 |
|
51 |
+
if product_name and product_desc and tone_of_voice and model and creativity and language:
|
52 |
|
53 |
if st.button('Generate'):
|
54 |
|
55 |
+
product_description = product_description_gen(product_name, product_desc, tone_of_voice=tone_of_voice, model_name=model, creativity=creativity, language=language)
|
56 |
st.markdown(product_description)
|
57 |
|
58 |
+
elif choice == 'LinkedIn Content':
|
59 |
|
60 |
+
linkedIn_content_generation = linkedIn_content_gen()
|
61 |
+
|
62 |
+
linkedIn_choices_list = ('LinkedIn Post', 'LinkedIn Ads')
|
63 |
|
64 |
+
linkedIn_choices = st.selectbox('Choose LinkedIn Template', linkedIn_choices_list)
|
65 |
+
|
66 |
+
if linkedIn_choices == linkedIn_choices_list[0]:
|
67 |
|
|
|
68 |
|
69 |
+
topic = st.text_input('Topic')
|
70 |
+
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
71 |
+
model = st.selectbox('Choose a model', models)
|
72 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
73 |
+
language = st.selectbox('Choose a language', languages)
|
74 |
|
75 |
+
if topic and tone_of_voice and model and creativity and language:
|
76 |
|
77 |
+
if st.button('Generate'):
|
78 |
|
79 |
+
linkedIn_post = linkedIn_content_generation.linkedIn_post_gen(topic, tone_of_voice, language=language, model_name=model, creativity=creativity)
|
80 |
+
st.markdown(linkedIn_post)
|
|
|
|
|
81 |
|
82 |
+
elif linkedIn_choices == linkedIn_choices_list[1]:
|
|
|
|
|
83 |
|
84 |
+
product_name = st.text_input('Product Name')
|
85 |
+
product_desc = st.text_area('Product Description')
|
86 |
+
target_audience = st.text_input('Target Audience')
|
87 |
+
target_keywords = st.text_input('Target Keywords')
|
88 |
+
model = st.selectbox('Choose a model', models)
|
89 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
90 |
+
language = st.selectbox('Choose a language', languages)
|
91 |
+
|
92 |
+
if product_name and product_desc and target_audience and target_keywords and model and creativity and language:
|
93 |
+
|
94 |
+
if st.button('Generate'):
|
95 |
+
|
96 |
+
linkedIn_ad = linkedIn_content_generation.linkedIn_ads_gen(product_name, product_desc, target_audience, target_keywords, language=language, model_name=model, creativity=creativity)
|
97 |
+
st.markdown(linkedIn_ad)
|
98 |
|
99 |
|
100 |
elif choice == "Gym Workout Plan":
|
|
|
110 |
routine = st.selectbox("Preferred Routine", routine_list)
|
111 |
my_goals = st.text_input('Goals')
|
112 |
|
113 |
+
model = st.selectbox('Choose a Model', models)
|
114 |
+
creativity = st.selectbox('Creativity Level', creativity_list)
|
115 |
+
language = st.selectbox('Select a Language', languages)
|
116 |
+
|
117 |
+
if fitness_level and days and hours and health_consd and routine and my_goals and model and creativity and language:
|
118 |
|
119 |
if st.button('Generate'):
|
120 |
|
121 |
+
workout_plan = workout_plan_gen(my_goals, fitness_level, days, hours, health_consd, routine, model_name=model, creativity=creativity, language=language)
|
122 |
st.markdown(workout_plan)
|
123 |
|
124 |
elif choice == "Landing Page":
|
|
|
138 |
|
139 |
elif choice == 'X Content Creation':
|
140 |
|
141 |
+
X_content = X_content_creation.X_Generator()
|
142 |
|
143 |
x_choices_list = ('X thread', 'X Retweet Commenting', 'X Campaign', 'X Bio Creation', 'Article Conversion to X Thread')
|
144 |
|
|
|
149 |
topic = st.text_input('Topic')
|
150 |
num_tweets = st.slider('Number of Thread tweet', 1,10,5)
|
151 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
152 |
+
model = st.selectbox('Choose a model', models)
|
153 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
154 |
+
language = st.selectbox('Choose a language', languages)
|
155 |
|
156 |
+
if topic and num_tweets and tone_of_voice and model and creativity and language:
|
157 |
|
158 |
if st.button('Generate'):
|
159 |
|
160 |
+
X_thread = X_content.x_thread_gen(topic, num_tweets, tone_of_voice, language=language, model_name=model, creativity=creativity)
|
161 |
+
intro = X_content.x_thread_gen_intro(topic, X_thread, tone_of_voice, language=language, model_name=model, creativity=creativity)
|
162 |
st.markdown(intro)
|
163 |
st.markdown(X_thread)
|
164 |
|
|
|
167 |
|
168 |
tweet = st.text_area('Tweet')
|
169 |
tone_of_voice = st.selectbox('Tone of voice', tone_of_voice_list)
|
170 |
+
model = st.selectbox('Choose a model', models)
|
171 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
172 |
+
language = st.selectbox('Choose a language', languages)
|
173 |
|
174 |
+
if tweet and tone_of_voice and model and creativity and language:
|
175 |
|
176 |
if st.button('Generate'):
|
177 |
|
178 |
+
x_retweet_comment = X_content.x_retweet_commenting_gen(tweet, tone_of_voice, language=language, model_name=model, creativity=creativity)
|
179 |
st.markdown(x_retweet_comment)
|
180 |
|
181 |
elif x_choices == x_choices_list[2]:
|
|
|
183 |
product_name = st.text_input('Product Name')
|
184 |
product_desc = st.text_area('Product Description')
|
185 |
goal = st.text_input('Goal')
|
186 |
+
model = st.selectbox('Choose a model', models)
|
187 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
188 |
+
language = st.selectbox('Choose a language', languages)
|
189 |
|
190 |
|
191 |
+
if product_name and product_desc and goal and model and creativity and language:
|
192 |
|
193 |
if st.button('Generate'):
|
194 |
|
195 |
+
x_camp = X_content.x_camp_gen(product_name, product_desc, goal, language=language, model_name=model, creativity=creativity)
|
196 |
st.markdown(x_camp)
|
197 |
|
198 |
elif x_choices == x_choices_list[3]:
|
199 |
|
200 |
info = st.text_area('info')
|
201 |
tone_of_voice = st.selectbox('Tone of voice', tone_of_voice_list)
|
202 |
+
model = st.selectbox('Choose a model', models)
|
203 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
204 |
+
language = st.selectbox('Choose a language', languages)
|
205 |
|
206 |
+
if info and tone_of_voice and model and creativity and language:
|
207 |
|
208 |
if st.button('Generate'):
|
209 |
|
210 |
+
x_bio = X_content.x_bio_gen(info, tone_of_voice, language=language, model_name=model, creativity=creativity)
|
211 |
st.markdown(x_bio)
|
212 |
|
213 |
elif x_choices == x_choices_list[4]:
|
214 |
|
215 |
article = st.text_area('Article')
|
216 |
+
model = st.selectbox('Choose a model', models)
|
217 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
218 |
+
language = st.selectbox('Choose a language', languages)
|
219 |
|
220 |
+
if article and model and creativity and language:
|
221 |
|
222 |
if st.button('Generate'):
|
223 |
|
224 |
+
article_to_x_thread = X_content.article_to_x_thread_gen(article, language=language, model_name=model, creativity=creativity)
|
225 |
st.markdown(article_to_x_thread)
|
226 |
|
227 |
elif choice == 'Articles and Blogs':
|
228 |
|
229 |
+
blog_content = blog_content_creation.blog_content_generation()
|
230 |
|
231 |
blog_choices_list = ('Article Writer', 'Blog Post', 'Blog Ideas', 'Blog Tags', 'Blog Ideas description')
|
232 |
|
233 |
blog_choices = st.selectbox('Choose Blog Template', blog_choices_list)
|
234 |
|
235 |
+
|
236 |
+
|
237 |
if blog_choices == blog_choices_list[0]:
|
238 |
|
239 |
topic = st.text_input('Topic')
|
240 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
241 |
+
model = st.selectbox('Choose a model', models)
|
242 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
243 |
+
language = st.selectbox('Choose a language', languages)
|
244 |
|
245 |
+
if topic and tone_of_voice and model and creativity and language:
|
246 |
+
|
247 |
+
keywords = keywords_generator(topic, num_keywords=10, language=language, model_name=model, creativity=creativity)
|
248 |
+
keywords_gen_long_tail = keywords_generator_long_tail(topic, num_keywords=10, language=language, model_name=model, creativity=creativity)
|
249 |
|
|
|
250 |
filtered_keywords = filter_keywords(keywords)
|
251 |
+
filtered_keywords_long_tail = filter_keywords(keywords_gen_long_tail)
|
252 |
+
|
253 |
formatted_keywords = process_keywords(filtered_keywords)
|
254 |
+
formatted_keywords_long_tail = process_keywords(filtered_keywords_long_tail)
|
255 |
|
256 |
st.markdown('### Generated Keywords:\n')
|
257 |
st.markdown(formatted_keywords)
|
258 |
|
259 |
formatted_keywords = remove_ast(formatted_keywords)
|
260 |
+
formatted_keywords_long_tail = remove_ast(formatted_keywords_long_tail)
|
261 |
+
|
262 |
|
263 |
idea_numbers = st.slider("How many ideas you want?",1,10,5)
|
264 |
|
265 |
+
ideas = ideas_generator(topic, formatted_keywords_long_tail, tone_of_voice=tone_of_voice, num_of_ideas=idea_numbers, language=language, model_name=model, creativity=creativity)
|
266 |
filtered_ideas = filter_ideas(ideas)
|
267 |
|
268 |
index = 1
|
269 |
|
270 |
st.markdown("### Generated Ideas:\n")
|
271 |
+
|
272 |
for idea in filtered_ideas:
|
273 |
|
274 |
st.markdown(f"{index} - {idea}")
|
275 |
index+=1
|
276 |
|
277 |
st.text('\n')
|
278 |
+
|
279 |
num_idea = st.text_input("Choose the idea you want by number")
|
280 |
|
281 |
if num_idea:
|
|
|
284 |
idea = filtered_ideas[num_idea-1]
|
285 |
idea = remove_ast(idea)
|
286 |
|
287 |
+
outline = outlines_generator(idea,formatted_keywords_long_tail, language=language, model_name=model, creativity=creativity)
|
288 |
+
|
289 |
st.text('\n')
|
290 |
st.markdown("### Generated Outline:\n")
|
291 |
st.markdown(outline)
|
292 |
outline_list = filtered_outlines(outline)
|
293 |
|
294 |
+
outline_list2=[]
|
295 |
+
|
296 |
+
for section in outline_list:
|
297 |
+
|
298 |
+
cleaned_section = remove_ast(section)
|
299 |
+
outline_list2.append(cleaned_section)
|
300 |
|
301 |
if st.button('Generate'):
|
302 |
|
303 |
+
article = full_article(idea, outline_list2, tone_of_voice=tone_of_voice, language=language, model_name=model, creativity=creativity)
|
304 |
|
305 |
st.markdown("# Your Article:\n")
|
306 |
st.markdown(f"{idea}\n")
|
307 |
st.markdown('\n\n'.join(article))
|
308 |
st.text('\n\n')
|
|
|
|
|
309 |
|
310 |
+
num_full_art_chars = len('\n'.join(article))
|
311 |
+
nlp = spacy.load('en_core_web_sm')
|
312 |
+
doc = nlp('\n'.join(article))
|
313 |
+
num_full_art_words = len(doc)
|
314 |
+
|
315 |
+
st.markdown(f"{num_full_art_chars} Characters")
|
316 |
+
st.markdown(f"{num_full_art_words} Words")
|
317 |
|
318 |
elif blog_choices == blog_choices_list[1]:
|
319 |
|
320 |
topic = st.text_input('Topic')
|
321 |
+
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
322 |
+
model = st.selectbox('Choose a model', models)
|
323 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
324 |
+
language = st.selectbox('Choose a language', languages)
|
325 |
|
326 |
+
if topic and tone_of_voice and model and creativity and language:
|
327 |
|
328 |
if st.button('Generate'):
|
329 |
+
blog_post = blog_content.blog_post_gen(topic, tone_of_voice=tone_of_voice, language=language, creativity=creativity, model_name=model)
|
330 |
st.markdown(blog_post)
|
331 |
|
332 |
elif blog_choices == blog_choices_list[2]:
|
333 |
|
334 |
topic = st.text_input('Topic')
|
335 |
+
model = st.selectbox('Choose a model', models)
|
336 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
337 |
+
language = st.selectbox('Choose a language', languages)
|
338 |
|
339 |
if topic:
|
340 |
|
341 |
if st.button('Generate'):
|
342 |
|
343 |
+
blog_idea = blog_content.blog_idea_gen(topic, model_name=model, creativity=creativity, language=language)
|
344 |
st.markdown(blog_idea)
|
345 |
|
346 |
elif blog_choices == blog_choices_list[4]:
|
347 |
|
348 |
+
topic = st.text_input('topic')
|
349 |
+
model = st.selectbox('Choose a model', models)
|
350 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
351 |
+
language = st.selectbox('Choose a language', languages)
|
352 |
|
353 |
+
if topic and model and creativity and language:
|
354 |
|
355 |
if st.button('Generate'):
|
356 |
|
357 |
+
blog_idea_desc = blog_content.blog_idea_desc_gen(topic, model_name=model, creativity=creativity, language=language)
|
358 |
st.markdown(blog_idea_desc)
|
359 |
|
360 |
elif blog_choices == blog_choices_list[3]:
|
361 |
|
362 |
blog = st.text_area('Blog')
|
363 |
+
model = st.selectbox('Choose a model', models)
|
364 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
365 |
+
language = st.selectbox('Choose a language', languages)
|
366 |
|
367 |
+
if blog and model and creativity and language:
|
368 |
|
369 |
if st.button('Generate'):
|
370 |
|
371 |
+
blog_tags = blog_content.blog_tags_gen(blog, model_name=model, creativity=creativity, language=language)
|
372 |
st.markdown(blog_tags)
|
373 |
|
374 |
elif choice == 'Meta Content':
|
375 |
|
376 |
+
meta_content_gen = meta_content_creation.meta_content_generation()
|
377 |
|
378 |
meta_choices_list = ('Facebook Post', 'Facebook Ads', 'Facebook Campaign', 'Insta Image Captioning')
|
379 |
|
|
|
383 |
if meta_choices == meta_choices_list[0]:
|
384 |
|
385 |
topic = st.text_input("Topic")
|
|
|
386 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
387 |
+
model = st.selectbox('Choose a model', models)
|
388 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
389 |
+
language = st.selectbox('Choose a language', languages)
|
390 |
|
391 |
+
if topic and tone_of_voice and model and creativity and language:
|
392 |
|
393 |
if st.button('Generate'):
|
394 |
|
395 |
+
facebook_post = meta_content_gen.facebook_post_gen(tone_of_voice, topic, language=language, model_name=model, creativity=creativity)
|
396 |
st.markdown(facebook_post)
|
397 |
|
398 |
elif meta_choices == meta_choices_list[1]:
|
|
|
401 |
product_desc = st.text_area('Description')
|
402 |
targeted_audience = st.text_input('Target Audience')
|
403 |
plans_proms = st.text_input('Plan and Promotions')
|
|
|
404 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
405 |
+
model = st.selectbox('Choose a model', models)
|
406 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
407 |
+
language = st.selectbox('Choose a language', languages)
|
408 |
|
409 |
+
if product_name and product_desc and tone_of_voice and model and creativity and language:
|
410 |
|
411 |
if st.button('Generate'):
|
412 |
|
413 |
+
face_ad__prom = meta_content_gen.facebook_ads_gen(product_name, product_desc, tone_of_voice, targeted_audience, plans_proms, language=language, model_name=model, creativity=creativity)
|
414 |
st.markdown(face_ad__prom)
|
415 |
|
416 |
elif meta_choices == meta_choices_list[2]:
|
|
|
419 |
product_desc = st.text_area('Product Description')
|
420 |
days = st.selectbox('Days', (10,15,20,25,30))
|
421 |
goal = st.text_input('Goal')
|
422 |
+
model = st.selectbox('Choose a model', models)
|
423 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
424 |
+
language = st.selectbox('Choose a language', languages)
|
425 |
|
426 |
+
if product_name and product_desc and goal and days and model and creativity and language:
|
427 |
|
428 |
if st.button('Generate'):
|
429 |
|
430 |
+
facebook_camp = meta_content_gen.facbook_camp_gen(product_name, product_desc, days, goal, language=language, model_name=model, creativity=creativity)
|
431 |
+
st.markdown(facebook_camp)
|
432 |
|
433 |
elif meta_choices == meta_choices_list[3]:
|
434 |
|
|
|
451 |
|
452 |
tone_of_voice = st.selectbox('Tone of Voice', tone_of_voice_list)
|
453 |
form = st.selectbox('Caption Form', ('Short Form', 'Medium Form', 'Long Form'))
|
454 |
+
model = st.selectbox('Choose a model', models)
|
455 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
456 |
+
language = st.selectbox('Choose a language', languages)
|
457 |
|
458 |
+
if tone_of_voice and form and model and creativity and language:
|
459 |
+
|
460 |
+
if st.button('Generate'):
|
461 |
|
462 |
+
st.subheader("Generated Instagram Image according to the scenario:")
|
463 |
+
instaCap = meta_content_gen.generate_InstaCap(scenario, tone_of_voice, form, language=language, model_name=model, creativity=creativity)
|
464 |
+
st.markdown(instaCap)
|
465 |
|
466 |
elif choice == 'Emails':
|
467 |
|
468 |
+
email_content_gen = email_writer.email_writing()
|
469 |
|
470 |
email_choices_list = ('Email Writer', 'Email Marketing Campaign')
|
471 |
|
|
|
478 |
sender_name = st.text_input('Sender Name')
|
479 |
position_sender = st.text_input('Sender Position')
|
480 |
description = st.text_area('Description')
|
481 |
+
model = st.selectbox('Choose a model', models)
|
482 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
483 |
+
language = st.selectbox('Choose a language', languages)
|
484 |
|
485 |
+
if recipient and recipient_position and sender_name and position_sender and description and model and creativity and language:
|
486 |
|
487 |
if st.button('Generate'):
|
488 |
|
489 |
+
email = email_content_gen.email_gen(recipient, recipient_position, sender_name, position_sender, description, language=language, model_name=model, creativity=creativity)
|
490 |
email_subject = email_content_gen.email_subject_gen(email)
|
491 |
st.markdown(f'Subject: {email_subject}')
|
492 |
st.markdown(email)
|
|
|
497 |
product_description = st.text_area("Product Description")
|
498 |
target_audience = st.text_input("Target Audience")
|
499 |
goal = st.text_input("Goal")
|
500 |
+
model = st.selectbox('Choose a model', models)
|
501 |
+
creativity = st.selectbox('Choose a creativity', creativity_list)
|
502 |
+
language = st.selectbox('Choose a language', languages)
|
503 |
|
504 |
+
if product_name and product_description and target_audience and goal and model and creativity and language:
|
505 |
|
506 |
if st.button("Generate"):
|
507 |
|
508 |
+
email_marketing_camp = email_content_gen.email_marketing_campaigns_gen(product_name, product_description, target_audience, goal, language=language, model_name=model, creativity=creativity)
|
509 |
st.markdown(email_marketing_camp)
|
510 |
|
511 |
|
article_generation.py
CHANGED
@@ -1,53 +1,104 @@
|
|
|
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
def article_generator(idea, outline, section,
|
5 |
|
6 |
'''
|
7 |
-
Description
|
8 |
-
|
9 |
-
|
10 |
|
11 |
Parameters:
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
tone_of_voice (str)
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
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 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
article_extraction_chain = LLMChain(llm=llm, prompt=article_promptTemp)
|
33 |
article = article_extraction_chain.run(article_prompt)
|
34 |
|
35 |
return article
|
36 |
|
37 |
-
|
|
|
38 |
|
39 |
'''
|
40 |
Description:
|
41 |
-
This function generates a full article by iteratively
|
42 |
|
43 |
Parameters:
|
44 |
-
idea (str)
|
45 |
-
outline_list
|
46 |
-
tone_of_voice (str)
|
47 |
-
llm -> Required:
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
Return
|
50 |
-
article (list)
|
51 |
'''
|
52 |
|
53 |
article = []
|
@@ -57,7 +108,7 @@ def full_article(idea, outline_list, tone_of_voice, llm):
|
|
57 |
|
58 |
for section in outline_list:
|
59 |
|
60 |
-
para = article_generator(idea, ' '.join(outline), section,
|
61 |
outline.append(section)
|
62 |
article.append(para)
|
63 |
|
@@ -65,16 +116,3 @@ def full_article(idea, outline_list, tone_of_voice, llm):
|
|
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
|
|
|
1 |
+
from typing import List
|
2 |
+
|
3 |
from langchain.prompts import PromptTemplate
|
4 |
from langchain.chains import LLMChain
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
|
7 |
+
from load_model import call_palm
|
8 |
+
from calling_apis import google_api_key, openai_api_key
|
9 |
|
10 |
+
def article_generator(idea : str, outline : str, section : str, tone_of_voice : str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
11 |
|
12 |
'''
|
13 |
+
Description
|
14 |
+
|
15 |
+
This function generates paragraphs for an article based on provided parameters such as the main idea, outline, section, language model, and tone of voice. It utilizes a PromptTemplate and an LLMChain for content creation.
|
16 |
|
17 |
Parameters:
|
18 |
+
|
19 |
+
idea -> Required: (str) Represents the main idea or topic of the article.
|
20 |
+
outline -> Required: (str) Indicates the existing outline content (if any) for the article.
|
21 |
+
section -> Required: (str) Specifies the main point or section that requires content generation.
|
22 |
+
tone_of_voice -> Required: (str) Defines the desired tone for the article (e.g., formal, informal, technical).
|
23 |
+
language (str): Opitonal Parameter -> The language of the model.
|
24 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
25 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
26 |
+
|
27 |
+
|
28 |
+
Return:
|
29 |
+
- `article`: (str) The generated article paragraph based on the provided parameters and content prompts.
|
30 |
'''
|
31 |
+
|
32 |
+
temp = 0
|
33 |
+
|
34 |
+
if creativity == 'Original':
|
35 |
+
temp = 0
|
36 |
+
elif creativity == 'Balanced':
|
37 |
+
temp = 0.25
|
38 |
+
elif creativity == 'Creative':
|
39 |
+
temp = 0.5
|
40 |
+
elif creativity == 'Spirited':
|
41 |
+
temp = 0.75
|
42 |
+
elif creativity == 'Visionary':
|
43 |
+
temp = 1
|
44 |
+
|
45 |
+
|
46 |
+
if model_name == 'Google Palm 2':
|
47 |
+
llm = call_palm(google_api_key, temperature=temp)
|
48 |
+
|
49 |
+
elif model_name == 'GPT-3.5':
|
50 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
51 |
|
52 |
+
elif model_name == 'GPT-4':
|
53 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
|
|
|
|
54 |
|
55 |
+
|
56 |
+
if language == 'En':
|
57 |
+
|
58 |
+
if len(outline) == 0:
|
59 |
+
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}."
|
60 |
+
else:
|
61 |
+
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}."
|
62 |
+
|
63 |
+
article_promptTemp = PromptTemplate(
|
64 |
+
input_variables=["text_input"],
|
65 |
+
template="You are a Professional content creator and article Writer:\n\n{text_input}\n\nParagraph:")
|
66 |
|
67 |
+
elif language == 'Ar':
|
68 |
+
|
69 |
+
if len(outline) == 0:
|
70 |
+
article_prompt = f"أنشئ فقرة مثيرة للاهتمام لمقالي عن {idea} باستخدام النقطة الرئيسية التالية: {section}\nيجب أن يكون اللهجة {tone_of_voice}."
|
71 |
+
else:
|
72 |
+
article_prompt = f"انشئ فقرة منظمة تماماً لمقالي حول {idea}. لقد غطيت بالفعل: {outline} في الخطة العريضة. أحتاج مساعدة في النقطة الرئيسية التالية: {section}. يرجى التأكد من أن الفقرات متصلة منطقياً وتوفير انتقال سلس بين المواضيع الرئيسية. يجب أن يكون اللهجة {tone_of_voice}."
|
73 |
+
|
74 |
+
article_promptTemp = PromptTemplate(
|
75 |
+
input_variables=["text_input"],
|
76 |
+
template="أنت مبدع محترف للمحتوى وكاتب مقالات:\n\n{text_input}\n\nالفقرة:")
|
77 |
+
|
78 |
article_extraction_chain = LLMChain(llm=llm, prompt=article_promptTemp)
|
79 |
article = article_extraction_chain.run(article_prompt)
|
80 |
|
81 |
return article
|
82 |
|
83 |
+
|
84 |
+
def full_article(idea : str, outline_list : List[str], tone_of_voice : str, language='En', model_name='Google Palm 2', creativity='Original') -> List[str]:
|
85 |
|
86 |
'''
|
87 |
Description:
|
88 |
+
This function generates a full article by iteratively creating paragraphs for each section in an outline list using the `article_generator` function. It accumulates the generated paragraphs into a list representing the complete article.
|
89 |
|
90 |
Parameters:
|
91 |
+
- `idea` -> Required: (str) Represents the main idea or topic of the article.
|
92 |
+
- `outline_list` -> Required: (list) Contains sections or main points forming the outline structure of the article.
|
93 |
+
- `tone_of_voice` -> Required: (str) Defines the desired tone for the article (e.g., formal, informal, technical).
|
94 |
+
- `llm` -> Required: (object) Represents the language model used for generating the article content.
|
95 |
+
language (str): Opitonal Parameter -> The language of the model.
|
96 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
97 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
98 |
+
|
99 |
|
100 |
+
Return:
|
101 |
+
- `article`: (list) A list containing paragraphs generated for each section in the `outline_list`.
|
102 |
'''
|
103 |
|
104 |
article = []
|
|
|
108 |
|
109 |
for section in outline_list:
|
110 |
|
111 |
+
para = article_generator(idea, ' '.join(outline), section, tone_of_voice, language=language, model_name=model_name, creativity=creativity)
|
112 |
outline.append(section)
|
113 |
article.append(para)
|
114 |
|
|
|
116 |
pass
|
117 |
|
118 |
return article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blog_content_creation.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
class blog_content_generation:
|
5 |
|
@@ -12,87 +17,238 @@ class blog_content_generation:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
31 |
Returns:
|
32 |
-
|
33 |
|
34 |
blog_post_gen(self, topic)
|
35 |
|
36 |
Description: Generates a blog post on a given topic.
|
|
|
37 |
Parameters:
|
38 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
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,
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
blog_tags_desc = blog_tags_desc_extraction_chain.run(blog_tags_desc_prompt)
|
97 |
|
98 |
return blog_tags_desc
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
7 |
+
|
8 |
|
9 |
class blog_content_generation:
|
10 |
|
|
|
17 |
__init__(self, llm)
|
18 |
|
19 |
Description: Initializes the blog_content_generation class by setting the language model (llm) to be used for content generation.
|
|
|
|
|
20 |
|
21 |
blog_idea_desc_gen(self, blog)
|
22 |
|
23 |
Description: Generates SEO-friendly titles and meta descriptions for a given blog post topic.
|
24 |
+
|
25 |
Parameters:
|
26 |
+
|
27 |
+
topic: The title or topic of the blog post.
|
28 |
+
language (str): Opitonal Parameter -> The language of the model.
|
29 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
30 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
31 |
+
|
32 |
+
|
33 |
Returns:
|
34 |
blog_idea_desc: A list of suggested titles and meta descriptions.
|
35 |
|
36 |
blog_idea_gen(self, topic)
|
37 |
|
38 |
Description: Creates a list of SEO-friendly blog post ideas with emotional and persuasive titles based on a specific topic.
|
39 |
+
|
40 |
Parameters:
|
41 |
+
topic: The subject or theme for which blog post ideas are requested.
|
42 |
+
language (str): Opitonal Parameter -> The language of the model.
|
43 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
44 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
45 |
+
|
46 |
Returns:
|
47 |
+
blog_idea: A list containing at least 10 suggested blog post ideas.
|
48 |
|
49 |
blog_post_gen(self, topic)
|
50 |
|
51 |
Description: Generates a blog post on a given topic.
|
52 |
+
|
53 |
Parameters:
|
54 |
+
topic: The subject or theme for the blog post content.
|
55 |
+
language (str): Opitonal Parameter -> The language of the model.
|
56 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
57 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
58 |
+
|
59 |
Returns:
|
60 |
blog_post: The generated blog post content.
|
61 |
|
62 |
blog_tags_gen(self, blog)
|
63 |
|
64 |
Description: Suggests tags for a specific blog post.
|
65 |
+
|
66 |
Parameters:
|
67 |
+
blog: The title or topic of the blog post for which tags are needed.
|
68 |
+
language (str): Opitonal Parameter -> The language of the model.
|
69 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
70 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
71 |
+
|
72 |
Returns:
|
73 |
blog_tags_desc: A list of suggested tags related to the provided blog post.
|
74 |
'''
|
|
|
|
|
|
|
75 |
|
76 |
|
77 |
+
def blog_idea_desc_gen(self, topic, language='En',creativity='Original', model_name='Google Palm 2'):
|
78 |
+
|
79 |
+
temp = 0
|
80 |
+
|
81 |
+
if creativity == 'Original':
|
82 |
+
temp = 0
|
83 |
+
elif creativity == 'Balanced':
|
84 |
+
temp = 0.25
|
85 |
+
elif creativity == 'Creative':
|
86 |
+
temp = 0.5
|
87 |
+
elif creativity == 'Spirited':
|
88 |
+
temp = 0.75
|
89 |
+
elif creativity == 'Visionary':
|
90 |
+
temp = 1
|
91 |
+
|
92 |
+
|
93 |
+
if model_name == 'Google Palm 2':
|
94 |
+
llm = call_palm(google_api_key, temperature=temp)
|
95 |
+
|
96 |
+
elif model_name == 'GPT-3.5':
|
97 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
98 |
+
|
99 |
+
elif model_name == 'GPT-4':
|
100 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
101 |
+
|
102 |
+
|
103 |
+
if language == 'En':
|
104 |
+
|
105 |
+
blog_idea_desc_prompt = f"Suggest at least 5 SEO-friendly titles and meta descriptions for blog post topic delimeted by three backtick. Use a persuasive and intriguing tone.\n```{topic}```"
|
106 |
+
blog_idea_desc_promptTemp = PromptTemplate(
|
107 |
+
input_variables=["text_input"],
|
108 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
109 |
+
|
110 |
+
elif language == 'Ar':
|
111 |
+
|
112 |
+
blog_idea_desc_prompt = f"اقترح على الأقل 5 عناوين ووصفات ودية لمحركات البحث (SEO) لمقالة الويب التالية {topic}. استخدم نبرة مقنعة ومثيرة للاهتمام."
|
113 |
+
blog_idea_desc_promptTemp = PromptTemplate(
|
114 |
+
input_variables=["text_input"],
|
115 |
+
template="أنت كاتب مدونتي\n\n{text_input}\n\nأفكار مقالات مدونة حول تحسين محركات البحث:")
|
116 |
+
|
117 |
+
blog_idea_desc_extraction_chain = LLMChain(llm=llm, prompt=blog_idea_desc_promptTemp)
|
118 |
blog_idea_desc = blog_idea_desc_extraction_chain.run(blog_idea_desc_prompt)
|
119 |
|
120 |
return blog_idea_desc
|
121 |
|
122 |
+
def blog_idea_gen(self, topic, language='En', creativity='Original', model_name='Google Palm 2'):
|
|
|
123 |
|
124 |
+
temp = 0
|
125 |
+
|
126 |
+
if creativity == 'Original':
|
127 |
+
temp = 0
|
128 |
+
elif creativity == 'Balanced':
|
129 |
+
temp = 0.25
|
130 |
+
elif creativity == 'Creative':
|
131 |
+
temp = 0.5
|
132 |
+
elif creativity == 'Spirited':
|
133 |
+
temp = 0.75
|
134 |
+
elif creativity == 'Visionary':
|
135 |
+
temp = 1
|
136 |
+
|
137 |
+
|
138 |
+
if model_name == 'Google Palm 2':
|
139 |
+
llm = call_palm(google_api_key, temperature=temp)
|
140 |
+
|
141 |
+
elif model_name == 'GPT-3.5':
|
142 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
143 |
+
|
144 |
+
elif model_name == 'GPT-4':
|
145 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
146 |
+
|
147 |
+
|
148 |
+
if language == 'En':
|
149 |
+
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."
|
150 |
+
blog_idea_promptTemp = PromptTemplate(
|
151 |
+
input_variables=["text_input"],
|
152 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
153 |
+
|
154 |
+
elif language == 'Ar':
|
155 |
+
blog_idea_prompt = f"أنشئ قائمة تحتوي على على الأقل 10 أفكار لمقالات في موضوع: {topic}. اقترح عناوين صديقة لمحركات البحث واستخدم نبرة عاطفية ومقنعة في عناوين مقالات البلوج"
|
156 |
+
blog_idea_promptTemp = PromptTemplate(
|
157 |
+
input_variables=["text_input"],
|
158 |
+
template="أنت كاتب مدونتي\n\n{text_input}\n\nأفكار مقالات مدونة تحسين محركات البحث:")
|
159 |
+
|
160 |
+
blog_idea_extraction_chain = LLMChain(llm=llm, prompt=blog_idea_promptTemp)
|
161 |
blog_idea = blog_idea_extraction_chain.run(blog_idea_prompt)
|
162 |
|
163 |
return blog_idea
|
164 |
|
165 |
+
def blog_post_gen(self, topic, tone_of_voice='Excited', language='En', creativity='Original', model_name='Google Palm 2'):
|
166 |
+
|
167 |
+
temp = 0
|
168 |
+
|
169 |
+
if creativity == 'Original':
|
170 |
+
temp = 0
|
171 |
+
elif creativity == 'Balanced':
|
172 |
+
temp = 0.25
|
173 |
+
elif creativity == 'Creative':
|
174 |
+
temp = 0.5
|
175 |
+
elif creativity == 'Spirited':
|
176 |
+
temp = 0.75
|
177 |
+
elif creativity == 'Visionary':
|
178 |
+
temp = 1
|
179 |
+
|
180 |
+
|
181 |
+
if model_name == 'Google Palm 2':
|
182 |
+
llm = call_palm(google_api_key, temperature=temp)
|
183 |
+
|
184 |
+
elif model_name == 'GPT-3.5':
|
185 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
186 |
+
|
187 |
+
elif model_name == 'GPT-4':
|
188 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
189 |
+
|
190 |
+
|
191 |
+
if language == 'En':
|
192 |
+
|
193 |
+
blog_post_prompt = f"""Write a well organized and attractive blog Plost about the topic delimited by triple backticks.
|
194 |
+
The tone should be {tone_of_voice}.
|
195 |
+
```{topic}```."""
|
196 |
+
blog_post_promptTemp = PromptTemplate(
|
197 |
+
input_variables=["text_input"],
|
198 |
+
template="You are a Professional Content Creator and Blog Writer:\n{text_input}\nBlog Post:")
|
199 |
+
|
200 |
+
elif language == 'Ar':
|
201 |
+
|
202 |
+
blog_post_prompt = f"اكتب مقالة في المدونة حول {topic}."
|
203 |
+
blog_post_promptTemp = PromptTemplate(
|
204 |
+
input_variables=["text_input"],
|
205 |
+
template="أنت مبدع محترف للمحتوى وكاتب للمدوّنات:\n{text_input}\nمقال المدوّنة:")
|
206 |
+
|
207 |
+
blog_post_extraction_chain = LLMChain(llm=llm, prompt=blog_post_promptTemp)
|
208 |
blog_post = blog_post_extraction_chain.run(blog_post_prompt)
|
209 |
|
210 |
return blog_post
|
211 |
|
212 |
+
def blog_tags_gen(self, blog, language='En', creativity='Original', model_name='Google Palm 2'):
|
213 |
+
|
214 |
+
temp = 0
|
215 |
+
|
216 |
+
if creativity == 'Original':
|
217 |
+
temp = 0
|
218 |
+
elif creativity == 'Balanced':
|
219 |
+
temp = 0.25
|
220 |
+
elif creativity == 'Creative':
|
221 |
+
temp = 0.5
|
222 |
+
elif creativity == 'Spirited':
|
223 |
+
temp = 0.75
|
224 |
+
elif creativity == 'Visionary':
|
225 |
+
temp = 1
|
226 |
+
|
227 |
+
|
228 |
+
if model_name == 'Google Palm 2':
|
229 |
+
llm = call_palm(google_api_key, temperature=temp)
|
230 |
+
|
231 |
+
elif model_name == 'GPT-3.5':
|
232 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
233 |
+
|
234 |
+
elif model_name == 'GPT-4':
|
235 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
236 |
+
|
237 |
+
|
238 |
+
if language == 'En':
|
239 |
+
|
240 |
+
blog_tags_desc_prompt = f" Suggest at least 5 tags for the following blog post.\n{blog}"
|
241 |
+
blog_tags_desc_promptTemp = PromptTemplate(
|
242 |
+
input_variables=["text_input"],
|
243 |
+
template="You are my blogger writter\n\n{text_input}\n\nSEO blog post ideas:")
|
244 |
+
|
245 |
+
elif language == 'Ar':
|
246 |
+
blog_tags_desc_prompt = f"اقترح ما لا يقل عن 5 علامات لمنشور المدونة التالي.\n{blog}"
|
247 |
+
blog_tags_desc_promptTemp = PromptTemplate(
|
248 |
+
input_variables=["text_input"],
|
249 |
+
template="أنت كاتب مدونتي\n\n{text_input}\n\nأفكار مقالات مدونة محركات البحث:")
|
250 |
+
|
251 |
+
blog_tags_desc_extraction_chain = LLMChain(llm=llm, prompt=blog_tags_desc_promptTemp)
|
252 |
blog_tags_desc = blog_tags_desc_extraction_chain.run(blog_tags_desc_prompt)
|
253 |
|
254 |
return blog_tags_desc
|
calling_apis.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import find_dotenv, load_dotenv
|
2 |
+
import os
|
3 |
+
|
4 |
+
load_dotenv(find_dotenv())
|
5 |
+
|
6 |
+
google_api_key = os.environ['GOOGLE_API_KEY']
|
7 |
+
openai_api_key = os.environ['OPENAI_API_KEY']
|
8 |
+
|
email_writer.py
CHANGED
@@ -1,46 +1,191 @@
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
3 |
|
4 |
class email_writing:
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
def email_gen(self, recipient, recipient_position, sender_name, position_sender, desc):
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
|
22 |
-
def email_subject_gen(self, email):
|
|
|
|
|
|
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
email_subject = email_subject_extraction_chain.run(email_subject_prompt)
|
32 |
|
33 |
return email_subject
|
34 |
|
35 |
-
def email_marketing_campaigns_gen(self, product_name, product_description, target_audience, goal):
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
email = email_extraction_chain.run(email_prompt)
|
45 |
|
46 |
return email
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
7 |
|
8 |
class email_writing:
|
9 |
+
|
10 |
+
"""
|
11 |
+
A class for generating emails and email marketing campaigns using a language model.
|
12 |
+
|
13 |
+
"""
|
14 |
|
15 |
+
def email_gen(self, recipient:str, recipient_position:str, sender_name:str, position_sender:str, desc:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
16 |
+
|
17 |
+
"""
|
18 |
+
Generates an email based on provided details.
|
19 |
|
|
|
20 |
|
21 |
+
Args:
|
22 |
+
recipient (str): Name of the email recipient.
|
23 |
+
recipient_position (str): Position of the email recipient.
|
24 |
+
sender_name (str): Name of the email sender.
|
25 |
+
position_sender (str): Position of the email sender.
|
26 |
+
desc (str): Description or context for the email.
|
27 |
+
language (str): the language of the generated content (optional, default value is 'EN').
|
28 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
29 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
30 |
|
31 |
+
|
32 |
+
Returns:
|
33 |
+
email (str): Generated email content.
|
34 |
+
"""
|
35 |
+
|
36 |
+
temp = 0
|
37 |
+
|
38 |
+
if creativity == 'Original':
|
39 |
+
temp = 0
|
40 |
+
elif creativity == 'Balanced':
|
41 |
+
temp = 0.25
|
42 |
+
elif creativity == 'Creative':
|
43 |
+
temp = 0.5
|
44 |
+
elif creativity == 'Spirited':
|
45 |
+
temp = 0.75
|
46 |
+
elif creativity == 'Visionary':
|
47 |
+
temp = 1
|
48 |
+
|
49 |
+
|
50 |
+
if model_name == 'Google Palm 2':
|
51 |
+
llm = call_palm(google_api_key, temperature=temp)
|
52 |
+
|
53 |
+
elif model_name == 'GPT-3.5':
|
54 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
55 |
+
|
56 |
+
elif model_name == 'GPT-4':
|
57 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
58 |
+
|
59 |
+
|
60 |
+
if language == 'En':
|
61 |
+
email_prompt = f"Write a professional and well organized Email on {desc}.\nThe name of the Recipient is {recipient} and the recipient position is {recipient_position}.\nMy Name is {sender_name} and my Position is {position_sender}."
|
62 |
+
email_promptTemp = PromptTemplate(
|
63 |
+
input_variables=["text_input"],
|
64 |
+
template="You are a professional email writer:\n{text_input}\nEmail:")
|
65 |
+
|
66 |
+
elif language == 'Ar':
|
67 |
+
email_prompt = f"اكتب بريدًا إلكترونيًا احترافيًا ومنظمًا حول {desc}.\nاسم المستلم هو {recipient} وموقع المستلم هو {recipient_position}.\nاسمي هو {sender_name} وموقعي هو {position_sender}."
|
68 |
+
email_promptTemp = PromptTemplate(
|
69 |
+
input_variables=["text_input"],
|
70 |
+
template="أنت كاتب بريد إلكتروني محترف:\n{text_input}\nالبريد الإلكتروني:")
|
71 |
+
|
72 |
+
email_extraction_chain = LLMChain(llm=llm, prompt=email_promptTemp)
|
73 |
+
email = email_extraction_chain.run(email_prompt)
|
74 |
|
75 |
+
return email
|
76 |
|
77 |
+
def email_subject_gen(self, email:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
78 |
+
|
79 |
+
"""
|
80 |
+
Generates a subject for a given email.
|
81 |
|
82 |
+
Args:
|
83 |
+
email (str): Email content for which the subject needs to be generated.
|
84 |
+
language (str): the language of the generated content (optional, default value is 'EN').
|
85 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
86 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
87 |
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
email_subject (str): Generated email subject.
|
91 |
+
"""
|
92 |
+
|
93 |
+
temp = 0
|
94 |
+
|
95 |
+
if creativity == 'Original':
|
96 |
+
temp = 0
|
97 |
+
elif creativity == 'Balanced':
|
98 |
+
temp = 0.25
|
99 |
+
elif creativity == 'Creative':
|
100 |
+
temp = 0.5
|
101 |
+
elif creativity == 'Spirited':
|
102 |
+
temp = 0.75
|
103 |
+
elif creativity == 'Visionary':
|
104 |
+
temp = 1
|
105 |
+
|
106 |
+
|
107 |
+
if model_name == 'Google Palm 2':
|
108 |
+
llm = call_palm(google_api_key, temperature=temp)
|
109 |
+
|
110 |
+
elif model_name == 'GPT-3.5':
|
111 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
112 |
+
|
113 |
+
elif model_name == 'GPT-4':
|
114 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
115 |
+
|
116 |
+
|
117 |
+
if language == 'En':
|
118 |
+
email_subject_prompt = f"Generate a subject for the following email:\n{email}\n"
|
119 |
+
email_subject_promptTemp = PromptTemplate(
|
120 |
+
input_variables=["text_input"],
|
121 |
+
template="You are a professional email writer:\n{text_input}\nEmail Subject:")
|
122 |
+
|
123 |
+
elif language == 'Ar':
|
124 |
+
email_subject_prompt = f"أنشئ موضوعًا للبريد الإلكتروني التالي:\n{email}\n"
|
125 |
+
email_subject_promptTemp = PromptTemplate(
|
126 |
+
input_variables=["text_input"],
|
127 |
+
template="أنت كاتب بريد إلكتروني محترف:\n{text_input}\nعنوان البريد الإلكتروني:")
|
128 |
+
|
129 |
+
email_subject_extraction_chain = LLMChain(llm=llm, prompt=email_subject_promptTemp)
|
130 |
email_subject = email_subject_extraction_chain.run(email_subject_prompt)
|
131 |
|
132 |
return email_subject
|
133 |
|
134 |
+
def email_marketing_campaigns_gen(self, product_name:str, product_description:str, target_audience:str, goal:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
135 |
+
|
136 |
+
"""
|
137 |
+
Generates a subject for a given email.
|
138 |
+
|
139 |
+
Args:
|
140 |
+
product_name (str): Name of the product.
|
141 |
+
product_description (str): Description of the product.
|
142 |
+
target_audience (str): Targeted audience for the campaign.
|
143 |
+
goal (str): Goal of the Campaign.
|
144 |
+
language (str): the language of the generated content (optional, default value is 'EN').
|
145 |
+
|
146 |
+
Returns:
|
147 |
+
email (str): Generated emails marketing campaigns.
|
148 |
+
"""
|
149 |
+
|
150 |
+
temp = 0
|
151 |
+
|
152 |
+
if creativity == 'Original':
|
153 |
+
temp = 0
|
154 |
+
elif creativity == 'Balanced':
|
155 |
+
temp = 0.25
|
156 |
+
elif creativity == 'Creative':
|
157 |
+
temp = 0.5
|
158 |
+
elif creativity == 'Spirited':
|
159 |
+
temp = 0.75
|
160 |
+
elif creativity == 'Visionary':
|
161 |
+
temp = 1
|
162 |
+
|
163 |
+
|
164 |
+
if model_name == 'Google Palm 2':
|
165 |
+
llm = call_palm(google_api_key, temperature=temp)
|
166 |
+
|
167 |
+
elif model_name == 'GPT-3.5':
|
168 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
169 |
+
|
170 |
+
elif model_name == 'GPT-4':
|
171 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
172 |
+
|
173 |
+
|
174 |
+
if language == 'En':
|
175 |
|
176 |
+
email_prompt = f"Generate a high-converting email marketing campaign for {product_name}. {product_name} is {product_description}. that is targeted at {target_audience} and has the goal of {goal}. The campaign should include a welcome email, a nurture sequence, and a promotional email."
|
177 |
+
email_promptTemp = PromptTemplate(
|
178 |
+
input_variables=["text_input"],
|
179 |
+
template="You are a Professional Email Marketing Copywriter:\n{text_input}\nEmail Marketing Campaign:")
|
180 |
+
|
181 |
+
elif language == 'Ar':
|
182 |
+
|
183 |
+
email_prompt = f"أنشئ حملة تسويق بريد إلكتروني فعّالة لـ {product_name}. {product_name} هو {product_description}. مستهدفة لـ {target_audience} ولها هدف {goal}. يجب أن تتضمن الحملة رسالة ترحيب، سلسلة تغذية، ورسالة ترويجية."
|
184 |
+
email_promptTemp = PromptTemplate(
|
185 |
+
input_variables=["text_input"],
|
186 |
+
template="أنت كاتب نصوص تسويق البريد الإلكتروني المحترف:\n{text_input}\nحملة تسويق البريد الإلكتروني:")
|
187 |
+
|
188 |
+
email_extraction_chain = LLMChain(llm=llm, prompt=email_promptTemp)
|
189 |
email = email_extraction_chain.run(email_prompt)
|
190 |
|
191 |
return email
|
idea_generation.py
CHANGED
@@ -1,8 +1,14 @@
|
|
|
|
|
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
-
import
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
'''
|
8 |
Description:
|
@@ -18,9 +24,12 @@ def ideas_generator(topic, keywords, llm, tone_of_voice='Professional', num_of_i
|
|
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 |
'''
|
@@ -29,16 +38,57 @@ def ideas_generator(topic, keywords, llm, tone_of_voice='Professional', num_of_i
|
|
29 |
ideas (str): Functions returns a text with number of ideas numbered with roman numerals
|
30 |
'''
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
|
|
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)
|
@@ -46,7 +96,7 @@ def ideas_generator(topic, keywords, llm, tone_of_voice='Professional', num_of_i
|
|
46 |
return ideas
|
47 |
|
48 |
|
49 |
-
def filter_ideas(ideas):
|
50 |
|
51 |
'''
|
52 |
Description:
|
@@ -70,7 +120,7 @@ def filter_ideas(ideas):
|
|
70 |
return filtered_ideas
|
71 |
|
72 |
|
73 |
-
def pick_idea(list_ideas):
|
74 |
|
75 |
"""
|
76 |
Description:
|
@@ -98,7 +148,7 @@ def pick_idea(list_ideas):
|
|
98 |
c = counter+1
|
99 |
print(f"{c}. {idea}")
|
100 |
|
101 |
-
x = int(input("
|
102 |
idea = list_ideas[x-1]
|
103 |
|
104 |
return idea
|
|
|
1 |
+
import re
|
2 |
+
from typing import List
|
3 |
+
|
4 |
from langchain.prompts import PromptTemplate
|
5 |
from langchain.chains import LLMChain
|
6 |
+
from langchain.llms import OpenAI
|
7 |
|
8 |
+
from load_model import call_palm
|
9 |
+
from calling_apis import google_api_key, openai_api_key
|
10 |
+
|
11 |
+
def ideas_generator(topic : str, keywords : str, tone_of_voice='Professional', num_of_ideas=3, language = 'En', creativity='Original', model_name='Google Palm 2') -> str:
|
12 |
|
13 |
'''
|
14 |
Description:
|
|
|
24 |
|
25 |
topic (str, required): The topic or subject matter of the article for which you want to generate titles.
|
26 |
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.
|
|
|
27 |
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.
|
28 |
+
tone_of_voice (str, optional): A String to determine the tone of voice of the title. Default Value Professional.
|
29 |
+
language (str): Opitonal Parameter -> The language of the model.
|
30 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
31 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
32 |
+
|
33 |
'''
|
34 |
|
35 |
'''
|
|
|
38 |
ideas (str): Functions returns a text with number of ideas numbered with roman numerals
|
39 |
'''
|
40 |
|
41 |
+
temp = 0
|
42 |
+
|
43 |
+
if creativity == 'Original':
|
44 |
+
temp = 0
|
45 |
+
elif creativity == 'Balanced':
|
46 |
+
temp = 0.25
|
47 |
+
elif creativity == 'Creative':
|
48 |
+
temp = 0.5
|
49 |
+
elif creativity == 'Spirited':
|
50 |
+
temp = 0.75
|
51 |
+
elif creativity == 'Visionary':
|
52 |
+
temp = 1
|
53 |
+
|
54 |
+
|
55 |
+
if model_name == 'Google Palm 2':
|
56 |
+
llm = call_palm(google_api_key, temperature=temp)
|
57 |
+
|
58 |
+
elif model_name == 'GPT-3.5':
|
59 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
60 |
+
|
61 |
+
elif model_name == 'GPT-4':
|
62 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
63 |
+
|
64 |
+
|
65 |
+
if language == 'En':
|
66 |
|
67 |
+
if num_of_ideas == 1:
|
68 |
+
|
69 |
+
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}."
|
70 |
+
|
71 |
+
else:
|
72 |
+
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}."
|
73 |
+
|
74 |
+
ideas_promptTemp = PromptTemplate(
|
75 |
+
input_variables=["text_input"],
|
76 |
+
template="You are a professional content creator and Title Generator:\n\n{text_input}\n\n:Titles (number them with roman numerals):")
|
77 |
+
|
78 |
+
elif language == 'Ar':
|
79 |
+
|
80 |
+
if num_of_ideas == 1:
|
81 |
+
|
82 |
+
ideas_prompt = f"تولّد عنوان واحد فقط بنبرة {tone_of_voice} وجاذبية لمقالتي حول موضوع {topic}.\n\nاستخدم هذه الكلمات الرئيسية للمساعدة في إنشاء عنوان جذّاب وبنبرة {tone_of_voice}: {keywords}"
|
83 |
+
|
84 |
+
else:
|
85 |
+
|
86 |
+
ideas_prompt = f"توليد فقط {num_of_ideas} {tone_of_voice} وعناوين جذابة للابتكارات لمقالتي حول موضوع {topic}.\n\nاستخدم هذه الكلمات الرئيسية لمساعدتك في إنشاء عناوين جذابة بنفس {tone_of_voice}: {keywords}."
|
87 |
|
88 |
+
ideas_promptTemp = PromptTemplate(
|
89 |
+
input_variables=["text_input"],
|
90 |
+
template="أنت صانع محتوى احترافي ومولّد عناوين\n\n{text_input}\nالعناوين (عدّها باستخدام الأرقام الرومانية):")
|
91 |
|
|
|
|
|
|
|
92 |
|
93 |
ideas_extraction_chain = LLMChain(llm=llm, prompt=ideas_promptTemp)
|
94 |
ideas = ideas_extraction_chain.run(ideas_prompt)
|
|
|
96 |
return ideas
|
97 |
|
98 |
|
99 |
+
def filter_ideas(ideas : str) -> List[str]:
|
100 |
|
101 |
'''
|
102 |
Description:
|
|
|
120 |
return filtered_ideas
|
121 |
|
122 |
|
123 |
+
def pick_idea(list_ideas : List[str]) -> str:
|
124 |
|
125 |
"""
|
126 |
Description:
|
|
|
148 |
c = counter+1
|
149 |
print(f"{c}. {idea}")
|
150 |
|
151 |
+
x = int(input("\nType the number of the idea: "))
|
152 |
idea = list_ideas[x-1]
|
153 |
|
154 |
return idea
|
keywords_generation.py
CHANGED
@@ -1,34 +1,75 @@
|
|
|
|
|
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
-
import
|
|
|
|
|
|
|
4 |
|
5 |
-
def keywords_generator(topic,
|
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 |
-
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
keywords_extraction_chain = LLMChain(llm=llm, prompt=keywords_promptTemp)
|
34 |
keywords = keywords_extraction_chain.run(keywords_prompt)
|
@@ -36,7 +77,75 @@ def keywords_generator(topic, llm, num_keywords=10):
|
|
36 |
return keywords
|
37 |
|
38 |
|
39 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
'''
|
41 |
Description:
|
42 |
|
@@ -61,7 +170,7 @@ def filter_keywords(keywords):
|
|
61 |
return filtered_keywords
|
62 |
|
63 |
|
64 |
-
def process_keywords(list_keywords):
|
65 |
|
66 |
'''
|
67 |
Description:
|
|
|
1 |
+
import re
|
2 |
+
from typing import List
|
3 |
+
|
4 |
from langchain.prompts import PromptTemplate
|
5 |
from langchain.chains import LLMChain
|
6 |
+
from langchain.llms import OpenAI
|
7 |
+
|
8 |
+
from load_model import call_palm
|
9 |
+
from calling_apis import google_api_key, openai_api_key
|
10 |
|
11 |
+
def keywords_generator(topic : str,num_keywords=10, language='En', creativity='Original', model_name='Google Palm 2') -> str:
|
12 |
|
13 |
'''
|
14 |
Description:
|
15 |
|
16 |
+
Generates a list of short-tail keywords for a given topic using a large language model (LLM).
|
17 |
'''
|
18 |
|
19 |
'''
|
20 |
Parameters:
|
21 |
|
22 |
topic (str): Required Parameter -> The topic for which to generate keywords.
|
|
|
23 |
num_keywords (int): Optional Parameter -> The number of keywords to generate. Default Value is 10
|
24 |
+
language (str): Opitonal Parameter -> The language of the model.
|
25 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
26 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
27 |
+
|
28 |
'''
|
29 |
|
30 |
'''
|
31 |
Returns:
|
32 |
Keywords (str): A Text of list of keywords numbered with roman numerals for the given topic -> str datatype.
|
33 |
'''
|
34 |
+
temp = 0
|
35 |
+
|
36 |
+
if creativity == 'Original':
|
37 |
+
temp = 0
|
38 |
+
elif creativity == 'Balanced':
|
39 |
+
temp = 0.25
|
40 |
+
elif creativity == 'Creative':
|
41 |
+
temp = 0.5
|
42 |
+
elif creativity == 'Spirited':
|
43 |
+
temp = 0.75
|
44 |
+
elif creativity == 'Visionary':
|
45 |
+
temp = 1
|
46 |
+
|
47 |
+
|
48 |
+
if model_name == 'Google Palm 2':
|
49 |
+
llm = call_palm(google_api_key, temperature=temp)
|
50 |
+
|
51 |
+
elif model_name == 'GPT-3.5':
|
52 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
53 |
+
|
54 |
+
elif model_name == 'GPT-4':
|
55 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
56 |
+
|
57 |
+
|
58 |
+
if language == 'En':
|
59 |
+
|
60 |
+
keywords_prompt = f"Generate {num_keywords} SEO keywords related to '{topic}'."
|
61 |
|
62 |
+
keywords_promptTemp = PromptTemplate(
|
63 |
+
input_variables=["text_input"],
|
64 |
+
template="You are a professional content creator and SEO Keywords Generator:\n\n{text_input}\n\nKeywords (number them with roman numerals):")
|
65 |
+
|
66 |
+
elif language == 'Ar':
|
67 |
+
|
68 |
+
keywords_prompt = f"قم بإنشاء {num_keywords} كلمة أساسية SEO متعلقة بـ '{topic}'."
|
69 |
+
|
70 |
+
keywords_promptTemp = PromptTemplate(
|
71 |
+
input_variables=["text_input"],
|
72 |
+
template="أنت منشئ محتوى محترف ومولد كلمات أساسية SEO:\n\n{text_input}\n\nالكلمات الأساسية (قم بترقيمها بالأرقام الرومانية):")
|
73 |
|
74 |
keywords_extraction_chain = LLMChain(llm=llm, prompt=keywords_promptTemp)
|
75 |
keywords = keywords_extraction_chain.run(keywords_prompt)
|
|
|
77 |
return keywords
|
78 |
|
79 |
|
80 |
+
def keywords_generator_long_tail(topic : str, num_keywords=10, language='En', creativity='Original', model_name='Google Palm 2') -> str:
|
81 |
+
|
82 |
+
'''
|
83 |
+
Description:
|
84 |
+
|
85 |
+
Generates a list of long-tail keywords for a given topic using a large language model (LLM).
|
86 |
+
'''
|
87 |
+
|
88 |
+
'''
|
89 |
+
Parameters:
|
90 |
+
|
91 |
+
topic (str): Required Parameter -> The topic for which to generate keywords.
|
92 |
+
num_keywords (int): Optional Parameter -> The number of keywords to generate. Default Value is 10
|
93 |
+
language (str): Opitonal Parameter -> The language of the model.
|
94 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
95 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
96 |
+
|
97 |
+
'''
|
98 |
+
|
99 |
+
'''
|
100 |
+
Returns:
|
101 |
+
Keywords (str): A Text of list of keywords numbered with roman numerals for the given topic -> str datatype.
|
102 |
+
'''
|
103 |
+
|
104 |
+
temp = 0
|
105 |
+
|
106 |
+
if creativity == 'Original':
|
107 |
+
temp = 0
|
108 |
+
elif creativity == 'Balanced':
|
109 |
+
temp = 0.25
|
110 |
+
elif creativity == 'Creative':
|
111 |
+
temp = 0.5
|
112 |
+
elif creativity == 'Spirited':
|
113 |
+
temp = 0.75
|
114 |
+
elif creativity == 'Visionary':
|
115 |
+
temp = 1
|
116 |
+
|
117 |
+
|
118 |
+
if model_name == 'Google Palm 2':
|
119 |
+
llm = call_palm(google_api_key, temperature=temp)
|
120 |
+
|
121 |
+
elif model_name == 'GPT-3.5':
|
122 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
123 |
+
|
124 |
+
elif model_name == 'GPT-4':
|
125 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
126 |
+
|
127 |
+
if language == 'En':
|
128 |
+
|
129 |
+
keywords_prompt = f"Generate {num_keywords} long-tail SEO keywords related to '{topic}'."
|
130 |
+
|
131 |
+
keywords_promptTemp = PromptTemplate(
|
132 |
+
input_variables=["text_input"],
|
133 |
+
template="You are a professional content creator and SEO Keywords Generator:\n\n{text_input}\n\nKeywords (number them with roman numerals):")
|
134 |
+
|
135 |
+
elif language == 'Ar':
|
136 |
+
|
137 |
+
keywords_prompt = f"قم بإنشاء {num_keywords} كلمة أساسية SEO طويلة الذيل متعلقة بـ '{topic}'."
|
138 |
+
|
139 |
+
keywords_promptTemp = PromptTemplate(
|
140 |
+
input_variables=["text_input"],
|
141 |
+
template="أنت منشئ محتوى محترف ومولد كلمات أساسية SEO:\n\n{text_input}\n\nالكلمات الأساسية (قم بترقيمها بالأرقام الرومانية):")
|
142 |
+
|
143 |
+
keywords_extraction_chain = LLMChain(llm=llm, prompt=keywords_promptTemp)
|
144 |
+
keywords = keywords_extraction_chain.run(keywords_prompt)
|
145 |
+
|
146 |
+
return keywords
|
147 |
+
|
148 |
+
def filter_keywords(keywords : str) -> List[str]:
|
149 |
'''
|
150 |
Description:
|
151 |
|
|
|
170 |
return filtered_keywords
|
171 |
|
172 |
|
173 |
+
def process_keywords(list_keywords : List[str]) -> str:
|
174 |
|
175 |
'''
|
176 |
Description:
|
linkedin_content_creation.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.prompts import PromptTemplate
|
2 |
+
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
7 |
+
|
8 |
+
class linkedIn_content_gen:
|
9 |
+
|
10 |
+
"""
|
11 |
+
A class for generating linkedIn Content.
|
12 |
+
|
13 |
+
"""
|
14 |
+
|
15 |
+
|
16 |
+
def linkedIn_post_gen(self, topic: str, tone_of_voice:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
17 |
+
|
18 |
+
"""
|
19 |
+
Generate an engaging LinkedIn post based on the provided topic and tone of voice.
|
20 |
+
|
21 |
+
Parmaeters:
|
22 |
+
- self: The instance of the class containing this method.
|
23 |
+
- topic (str): The topic for the LinkedIn post.
|
24 |
+
- tone_of_voice (str): The desired tone of voice for the post.
|
25 |
+
- language (str): the language of the generated content (optional, default value is 'EN').
|
26 |
+
- creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
27 |
+
- model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
28 |
+
|
29 |
+
|
30 |
+
Returns:
|
31 |
+
- linkedIn_post (str): The generated LinkedIn post.
|
32 |
+
|
33 |
+
"""
|
34 |
+
temp = 0
|
35 |
+
|
36 |
+
if creativity == 'Original':
|
37 |
+
temp = 0
|
38 |
+
elif creativity == 'Balanced':
|
39 |
+
temp = 0.25
|
40 |
+
elif creativity == 'Creative':
|
41 |
+
temp = 0.5
|
42 |
+
elif creativity == 'Spirited':
|
43 |
+
temp = 0.75
|
44 |
+
elif creativity == 'Visionary':
|
45 |
+
temp = 1
|
46 |
+
|
47 |
+
|
48 |
+
if model_name == 'Google Palm 2':
|
49 |
+
llm = call_palm(google_api_key, temperature=temp)
|
50 |
+
|
51 |
+
elif model_name == 'GPT-3.5':
|
52 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
53 |
+
|
54 |
+
elif model_name == 'GPT-4':
|
55 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
56 |
+
|
57 |
+
|
58 |
+
if language == 'En':
|
59 |
+
|
60 |
+
linkedIn_post_prompt = f"Write an engagging LinkedIn Post on {topic}. The tone should be {tone_of_voice}."
|
61 |
+
linkedIn_post_promptTemp = PromptTemplate(
|
62 |
+
input_variables=["text_input"],
|
63 |
+
template="You are a content creator and LinkedIn Posts writer :\n{text_input}\nLinkedIn Post:")
|
64 |
+
|
65 |
+
elif language == 'Ar':
|
66 |
+
|
67 |
+
linkedIn_post_prompt = f"اكتب منشورًا جذابًا على LinkedIn حول {topic}. يجب أن يكون النبرة {tone_of_voice}."
|
68 |
+
linkedIn_post_promptTemp = PromptTemplate(
|
69 |
+
input_variables=["text_input"],
|
70 |
+
template="أنت مُنشئ محتوى وكاتب لمنشورات LinkedIn :\n{text_input}\nمنشور LinkedIn:")
|
71 |
+
|
72 |
+
|
73 |
+
linkedIn_post_extraction_chain = LLMChain(llm=llm, prompt=linkedIn_post_promptTemp)
|
74 |
+
linkedIn_post = linkedIn_post_extraction_chain.run(linkedIn_post_prompt)
|
75 |
+
|
76 |
+
return linkedIn_post
|
77 |
+
|
78 |
+
|
79 |
+
def linkedIn_ads_gen(self, product_name:str, product_desc:str, target_audience:str, target_keywords:str, language='En', model_name='Google Palm 2', creativity='Original'):
|
80 |
+
|
81 |
+
"""
|
82 |
+
Generates a LinkedIn ad based on the provided product information and target details.
|
83 |
+
|
84 |
+
Args:
|
85 |
+
- product_name (str): The name of the product being advertised.
|
86 |
+
- product_desc (str): A description of the product being advertised.
|
87 |
+
- target_audience (str): The intended audience or demographic for the product.
|
88 |
+
- target_keywords (str): Keywords relevant to the product or its marketing strategy.
|
89 |
+
- language (str): the language of the generated content (optional, default value is 'EN').
|
90 |
+
|
91 |
+
Returns:
|
92 |
+
- linkedIn_ad (str): The generated LinkedIn ad copy based on the provided parameters.
|
93 |
+
|
94 |
+
"""
|
95 |
+
|
96 |
+
temp = 0
|
97 |
+
|
98 |
+
if creativity == 'Original':
|
99 |
+
temp = 0
|
100 |
+
elif creativity == 'Balanced':
|
101 |
+
temp = 0.25
|
102 |
+
elif creativity == 'Creative':
|
103 |
+
temp = 0.5
|
104 |
+
elif creativity == 'Spirited':
|
105 |
+
temp = 0.75
|
106 |
+
elif creativity == 'Visionary':
|
107 |
+
temp = 1
|
108 |
+
|
109 |
+
|
110 |
+
if model_name == 'Google Palm 2':
|
111 |
+
llm = call_palm(google_api_key, temperature=temp)
|
112 |
+
|
113 |
+
elif model_name == 'GPT-3.5':
|
114 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
115 |
+
|
116 |
+
elif model_name == 'GPT-4':
|
117 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
118 |
+
|
119 |
+
|
120 |
+
if language == 'En':
|
121 |
+
|
122 |
+
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."
|
123 |
+
linkedIn_ads_promptTemp = PromptTemplate(
|
124 |
+
input_variables=["text_input"],
|
125 |
+
template="You are a Professional LinkedIn Ad Copywriter:\n{text_input}\nFacebook Ad:")
|
126 |
+
|
127 |
+
elif language == 'Ar':
|
128 |
+
|
129 |
+
linkedIn_ads_prompt = f"أنشئ إعلانًا على LinkedIn لـ {product_name}. {product_name} هو {product_desc} المستهدف نحو {target_audience} ويستخدم الكلمات الرئيسية {target_keywords}. يجب أن يكون الإعلان مقنعًا وجذابًا، ويجب أن يتضمن دعوة للعمل."
|
130 |
+
linkedIn_ads_promptTemp = PromptTemplate(
|
131 |
+
input_variables=["text_input"],
|
132 |
+
template="أنت كاتب إعلانات محترف على LinkedIn:\n{text_input}\nإعلان على فيسبوك:")
|
133 |
+
|
134 |
+
linkedIn_ad_extraction_chain = LLMChain(llm=llm, prompt=linkedIn_ads_promptTemp)
|
135 |
+
linkedIn_ad = linkedIn_ad_extraction_chain.run(linkedIn_ads_prompt)
|
136 |
+
|
137 |
+
return linkedIn_ad
|
meta_content_creation.py
CHANGED
@@ -1,94 +1,292 @@
|
|
|
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
-
from
|
|
|
|
|
|
|
4 |
|
5 |
class meta_content_generation:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
def facebook_ads_gen(self, product_name, product_description, tone_of_voice, targeted_audience="", plans_promotions=""):
|
13 |
-
|
14 |
-
if targeted_audience != "" and plans_promotions != "":
|
15 |
-
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Our Target Audience is {targeted_audience}. Our plans and promotions is {plans_promotions}. Tone of the ad should be {tone_of_voice}"
|
16 |
|
17 |
-
elif targeted_audience == "" and plans_promotions != "":
|
18 |
-
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Our plans and promotions is {plans_promotions}. Tone of the ad should be {tone_of_voice}"
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
facebook_ads_promptTemp = PromptTemplate(
|
27 |
input_variables=["text_input"],
|
28 |
template="You are a Professional Facebook Ad Copywriter:\n{text_input}\nFacebook Ad:")
|
29 |
|
30 |
-
facebook_ad_extraction_chain = LLMChain(llm=
|
31 |
facebook_ad = facebook_ad_extraction_chain.run(facebook_ads_prompt)
|
32 |
|
33 |
return facebook_ad
|
34 |
|
35 |
-
def facbook_camp_gen(self, product_name, product_desc, days, goal):
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
Day 3-4: Teaser posts about how FAQGenius can save time and improve customer satisfaction.
|
46 |
-
Day 5-7: User testimonials and success stories with FAQGenius." and so on..
|
47 |
-
""")
|
48 |
-
facebook_ad_extraction_chain = LLMChain(llm=self.llm, prompt=facebook_ads_promptTemp)
|
49 |
-
facebook_ad = facebook_ad_extraction_chain.run(facebook_ads_prompt)
|
50 |
|
51 |
-
|
|
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
product_desc = productDesc_extraction_chain.run(productDesc_prompt)
|
63 |
|
64 |
return product_desc
|
65 |
|
66 |
-
def img2text(self, url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
73 |
|
74 |
-
|
75 |
|
76 |
|
77 |
-
def generate_InstaCap(self, scenario, tone_of_voice, form):
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
89 |
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
|
|
|
|
93 |
|
|
|
|
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
from langchain.prompts import PromptTemplate
|
4 |
from langchain.chains import LLMChain
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
|
7 |
+
from load_model import call_palm
|
8 |
+
from calling_apis import google_api_key, openai_api_key
|
9 |
|
10 |
class meta_content_generation:
|
11 |
+
|
12 |
+
"""
|
13 |
+
Class meta_content_generation:
|
14 |
+
Provides methods to generate content for social media platforms using Language Models (LLMs) and prompt templates.
|
15 |
+
"""
|
16 |
+
|
17 |
+
|
18 |
|
19 |
+
def facebook_ads_gen(self, product_name:str, product_description:str, tone_of_voice:str, targeted_audience="", plans_promotions="", language='En', model_name='Google Palm 2', creativity='Original')->str:
|
20 |
|
21 |
+
"""
|
22 |
+
Generates a Facebook ad based on the provided product details and parameters.
|
23 |
|
24 |
+
Parameters:
|
25 |
+
- product_name (str): Name of the product for the ad.
|
26 |
+
- product_description (str): Description of the product for the ad.
|
27 |
+
- tone_of_voice (str): Tone of the ad.
|
28 |
+
- targeted_audience (str): Target audience for the ad (optional).
|
29 |
+
- plans_promotions (str): Plans and promotions for the ad (optional).
|
30 |
+
|
31 |
+
Returns:
|
32 |
+
- Generated Facebook ad text.
|
33 |
+
"""
|
34 |
+
|
35 |
+
temp = 0
|
36 |
+
|
37 |
+
if creativity == 'Original':
|
38 |
+
temp = 0
|
39 |
+
elif creativity == 'Balanced':
|
40 |
+
temp = 0.25
|
41 |
+
elif creativity == 'Creative':
|
42 |
+
temp = 0.5
|
43 |
+
elif creativity == 'Spirited':
|
44 |
+
temp = 0.75
|
45 |
+
elif creativity == 'Visionary':
|
46 |
+
temp = 1
|
47 |
+
|
48 |
+
|
49 |
+
if model_name == 'Google Palm 2':
|
50 |
+
llm = call_palm(google_api_key, temperature=temp)
|
51 |
+
|
52 |
+
elif model_name == 'GPT-3.5':
|
53 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
54 |
+
|
55 |
+
elif model_name == 'GPT-4':
|
56 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
57 |
|
|
|
|
|
|
|
|
|
58 |
|
|
|
|
|
59 |
|
60 |
+
if language == 'En':
|
61 |
+
|
62 |
+
if targeted_audience != "" and plans_promotions != "":
|
63 |
+
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Our Target Audience is {targeted_audience}. Our plans and promotions is {plans_promotions}. Tone of the ad should be {tone_of_voice}"
|
64 |
+
|
65 |
+
elif targeted_audience == "" and plans_promotions != "":
|
66 |
+
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Our plans and promotions is {plans_promotions}. Tone of the ad should be {tone_of_voice}"
|
67 |
+
|
68 |
+
elif targeted_audience != "" and plans_promotions == "":
|
69 |
+
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Our Target Audience is {targeted_audience}. Tone of the ad should be{tone_of_voice}."
|
70 |
+
|
71 |
+
else:
|
72 |
+
facebook_ads_prompt = f"Generate a Facebook ad for {product_name} Product. {product_name} is {product_description}. Tone of the ad Should be {tone_of_voice}."
|
73 |
|
74 |
+
elif language == 'Ar':
|
75 |
+
|
76 |
+
if targeted_audience != "" and plans_promotions != "":
|
77 |
+
facebook_ads_prompt = f"انشئ إعلانًا على فيسبوك لمنتج {product_name}. {product_name} هو {product_description}. جمهورنا المستهدف هو {targeted_audience}. خططنا وعروضنا هي {plans_promotions}. يجب أن يكون توجه الإعلان {tone_of_voice}."
|
78 |
|
79 |
+
elif targeted_audience == "" and plans_promotions != "":
|
80 |
+
facebook_ads_prompt = f"قم بإنشاء إعلان على فيسبوك لـ {product_name} المنتج. {product_name} هو {product_description}. خططنا وعروضنا هي {plans_promotions}. يجب أن يكون تون الإعلان {tone_of_voice}"
|
81 |
+
|
82 |
+
elif targeted_audience != "" and plans_promotions == "":
|
83 |
+
facebook_ads_prompt = f"أنشئ إعلانًا على فيسبوك لمنتج {product_name}. {product_name} هو {product_description}. جمهورنا المستهدف هو {targeted_audience}. يجب أن يكون طابع الإعلان {tone_of_voice}"
|
84 |
+
|
85 |
+
else:
|
86 |
+
facebook_ads_prompt = f"انشئ إعلانًا على فيسبوك لـ {product_name} المنتج. {product_name} هو {product_description}. يجب أن يكون نبرة الإعلان {tone_of_voice}."
|
87 |
+
|
88 |
+
|
89 |
facebook_ads_promptTemp = PromptTemplate(
|
90 |
input_variables=["text_input"],
|
91 |
template="You are a Professional Facebook Ad Copywriter:\n{text_input}\nFacebook Ad:")
|
92 |
|
93 |
+
facebook_ad_extraction_chain = LLMChain(llm=llm, prompt=facebook_ads_promptTemp)
|
94 |
facebook_ad = facebook_ad_extraction_chain.run(facebook_ads_prompt)
|
95 |
|
96 |
return facebook_ad
|
97 |
|
98 |
+
def facbook_camp_gen(self, product_name:str, product_desc:str, days:int, goal:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
99 |
|
100 |
+
"""
|
101 |
+
Generates a Facebook Campign based on the provided product details and goals.
|
102 |
+
|
103 |
+
Parameters:
|
104 |
+
- product_name (str): Name of the product for the ad.
|
105 |
+
- product_desc (str): Description of the product for the ad.
|
106 |
+
- days (int): Number of campaign days.
|
107 |
+
- goal (str): Goal of the campaign.
|
108 |
+
- language (str): the language of the generated content (optional, default value is 'EN').
|
109 |
+
|
110 |
+
Returns:
|
111 |
+
- Facebook_ad (str): Generated Facebook Campaign .
|
112 |
+
"""
|
113 |
+
temp = 0
|
114 |
+
|
115 |
+
if creativity == 'Original':
|
116 |
+
temp = 0
|
117 |
+
elif creativity == 'Balanced':
|
118 |
+
temp = 0.25
|
119 |
+
elif creativity == 'Creative':
|
120 |
+
temp = 0.5
|
121 |
+
elif creativity == 'Spirited':
|
122 |
+
temp = 0.75
|
123 |
+
elif creativity == 'Visionary':
|
124 |
+
temp = 1
|
125 |
+
|
126 |
+
|
127 |
+
if model_name == 'Google Palm 2':
|
128 |
+
llm = call_palm(google_api_key, temperature=temp)
|
129 |
+
|
130 |
+
elif model_name == 'GPT-3.5':
|
131 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
132 |
+
|
133 |
+
elif model_name == 'GPT-4':
|
134 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
135 |
+
|
136 |
+
|
137 |
+
if language == 'En':
|
138 |
+
|
139 |
+
facebook_ads_prompt = f"Generate a {days} days Persuative Facebook campaign (don't mention any budget) calendar for our {product_name}. {product_name} is {product_desc}. with the goal to {goal}."
|
140 |
+
facebook_ads_promptTemp = PromptTemplate(
|
141 |
+
input_variables=["text_input"],
|
142 |
+
template="""You are a Professional Facebook Digital Marketer:\n{text_input}\nFacebook Campaign:""")
|
143 |
|
144 |
+
elif language == 'Ar':
|
145 |
+
|
146 |
+
facebook_ads_prompt = f"قم بإنشاء حملة فايسبوك قائمة لمدة {days} يومًا (دون الإشارة إلى أي ميزانية) لـ {product_name} الخاص بنا. {product_name} هو {product_desc}. بهدف {goal}."
|
147 |
+
facebook_ads_promptTemp = PromptTemplate(
|
148 |
+
input_variables=["text_input"],
|
149 |
+
template="أنت مسوّق رقمي محترف على فيسبوك:\n{text_input}\nحملة فيسبوك:")
|
150 |
+
|
151 |
+
facebook_ad_extraction_chain = LLMChain(llm=llm, prompt=facebook_ads_promptTemp)
|
152 |
+
facebook_ad = facebook_ad_extraction_chain.run(facebook_ads_prompt)
|
153 |
+
|
154 |
+
return facebook_ad
|
155 |
|
156 |
+
def facebook_post_gen(self, tone_of_voice:str, topic:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
+
"""
|
159 |
+
Generates a Facebook Post based on the provided topic.
|
160 |
|
161 |
+
Parameters:
|
162 |
+
- tone_of_voice (str): The tone of the facebook post.
|
163 |
+
- topic (str): The facebook post topic
|
164 |
+
- language (str): the language of the generated content (optional, default value is 'EN').
|
165 |
+
|
166 |
+
Returns:
|
167 |
+
- Facebook_post (str): Generated Facebook Post .
|
168 |
+
"""
|
169 |
+
|
170 |
+
temp = 0
|
171 |
+
|
172 |
+
if creativity == 'Original':
|
173 |
+
temp = 0
|
174 |
+
elif creativity == 'Balanced':
|
175 |
+
temp = 0.25
|
176 |
+
elif creativity == 'Creative':
|
177 |
+
temp = 0.5
|
178 |
+
elif creativity == 'Spirited':
|
179 |
+
temp = 0.75
|
180 |
+
elif creativity == 'Visionary':
|
181 |
+
temp = 1
|
182 |
+
|
183 |
+
|
184 |
+
if model_name == 'Google Palm 2':
|
185 |
+
llm = call_palm(google_api_key, temperature=temp)
|
186 |
+
|
187 |
+
elif model_name == 'GPT-3.5':
|
188 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
189 |
+
|
190 |
+
elif model_name == 'GPT-4':
|
191 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
192 |
+
|
193 |
+
|
194 |
+
if language == 'En':
|
195 |
|
196 |
+
productDesc_prompt = f"Generate an attractive and persuasive facebook post on {topic}. Tone should be {tone_of_voice}. Post dosen't include any photos or videos."
|
197 |
+
productDesc_promptTemp = PromptTemplate(
|
198 |
+
input_variables=["text_input"],
|
199 |
+
template="You are a professional facebook content creator:\n{text_input}\n\nFacebook Post:")
|
200 |
|
201 |
+
|
202 |
+
elif language == 'Ar':
|
203 |
+
|
204 |
+
productDesc_prompt = f"انشر منشورًا جذابًا ومقنعًا على فيسبوك حول {topic}. يجب أن يكون النبرة {tone_of_voice}. لا يتضمن المنشور أي صور أو مقاطع فيديو."
|
205 |
+
productDesc_promptTemp = PromptTemplate(
|
206 |
+
input_variables=["text_input"],
|
207 |
+
template="أنت مبدع محترف في إنشاء محتوى على فيسبوك:\n{text_input}\n\nمنشور فيسبوك:")
|
208 |
+
|
209 |
+
productDesc_extraction_chain = LLMChain(llm=llm, prompt=productDesc_promptTemp)
|
210 |
product_desc = productDesc_extraction_chain.run(productDesc_prompt)
|
211 |
|
212 |
return product_desc
|
213 |
|
214 |
+
def img2text(self, url:str) -> str:
|
215 |
+
|
216 |
+
"""
|
217 |
+
Function to extract text from an image using a pre-trained image captioning model.
|
218 |
+
|
219 |
+
Parameters:
|
220 |
+
self: The instance of a class (if this function is part of a class).
|
221 |
+
url (str): The URL pointing to the image for which text extraction is required.
|
222 |
|
223 |
+
Returns:
|
224 |
+
out (str): The extracted text from the provided image.
|
225 |
+
"""
|
226 |
+
|
227 |
+
image_to_text = pipeline("image-to-text", model='Salesforce/blip-image-captioning-base')
|
228 |
|
229 |
+
text = image_to_text(url)
|
230 |
|
231 |
+
out = text[0]['generated_text']
|
232 |
|
233 |
+
return out
|
234 |
|
235 |
|
236 |
+
def generate_InstaCap(self, scenario:str, tone_of_voice:str, form:str, language='En', model_name='Google Palm 2', creativity='Original') -> str:
|
237 |
|
238 |
+
"""
|
239 |
+
Generates a Instagram Caption based on the image description.
|
240 |
+
|
241 |
+
Parameters:
|
242 |
+
- tone_of_voice (str): The tone of the facebook post.
|
243 |
+
- scenario (str): The description of the image
|
244 |
+
- form (str): the form of the caption (short - long) forms
|
245 |
+
|
246 |
+
Returns:
|
247 |
+
- instaCap (str): Generated Image Caption.
|
248 |
+
"""
|
249 |
|
250 |
+
temp = 0
|
251 |
+
|
252 |
+
if creativity == 'Original':
|
253 |
+
temp = 0
|
254 |
+
elif creativity == 'Balanced':
|
255 |
+
temp = 0.25
|
256 |
+
elif creativity == 'Creative':
|
257 |
+
temp = 0.5
|
258 |
+
elif creativity == 'Spirited':
|
259 |
+
temp = 0.75
|
260 |
+
elif creativity == 'Visionary':
|
261 |
+
temp = 1
|
262 |
+
|
263 |
|
264 |
+
if model_name == 'Google Palm 2':
|
265 |
+
llm = call_palm(google_api_key, temperature=temp)
|
266 |
|
267 |
+
elif model_name == 'GPT-3.5':
|
268 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
269 |
|
270 |
+
elif model_name == 'GPT-4':
|
271 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
272 |
+
|
273 |
+
|
274 |
+
if language == 'En':
|
275 |
+
|
276 |
+
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}"
|
277 |
+
instaCap_promptTemp = PromptTemplate(
|
278 |
+
input_variables=["text_input"],
|
279 |
+
template="You are infulencer:\n{text_input}\nInstagram Caption:")
|
280 |
+
|
281 |
+
elif language == 'Ar':
|
282 |
+
|
283 |
+
instaCap_prompt = f"صياغة توضيح {form} على صورة إنستغرام الخاصة بي. إليك وصف صورة إنستغرامي: {scenario}.يجب أن يكون التون {tone_of_voice}."
|
284 |
+
instaCap_promptTemp = PromptTemplate(
|
285 |
+
input_variables=["text_input"],
|
286 |
+
template="أنت مؤثر: \n{text_input}\n وصف بوست الانستغرام:")
|
287 |
+
|
288 |
+
instaCap_extraction_chain = LLMChain(llm=llm, prompt=instaCap_promptTemp)
|
289 |
+
instaCap = instaCap_extraction_chain.run(instaCap_prompt)
|
290 |
+
|
291 |
+
return instaCap
|
292 |
+
|
outline_generation.py
CHANGED
@@ -1,10 +1,16 @@
|
|
1 |
-
from langchain.prompts import PromptTemplate
|
2 |
-
from langchain.chains import LLMChain
|
3 |
import re
|
4 |
from remove_astricks import remove_ast
|
|
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
'''
|
10 |
Description:
|
@@ -18,7 +24,10 @@ def outlines_generator(idea, keywords, llm):
|
|
18 |
|
19 |
idea (str): The main idea or topic of the article for which you want to generate an outline.
|
20 |
keywords (str): A set of keywords or topic-related terms that will be used as section headings in the outline. These headings help organize the content and provide a structure for the article.
|
21 |
-
|
|
|
|
|
|
|
22 |
'''
|
23 |
|
24 |
'''
|
@@ -27,41 +36,63 @@ def outlines_generator(idea, keywords, llm):
|
|
27 |
outlines (str): The generated outline for the article, including section headings and placeholders for content under each heading.
|
28 |
'''
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
outlines_extraction_chain = LLMChain(llm=llm, prompt=outlines_promptTemp)
|
37 |
outlines = outlines_extraction_chain.run(outlines_prompt)
|
38 |
|
39 |
return outlines
|
40 |
|
41 |
|
42 |
-
def filtered_outlines(outline):
|
43 |
-
|
44 |
'''
|
45 |
Description:
|
46 |
-
This function processes an outline text
|
47 |
-
|
48 |
-
The resulting output is a list of cleaned outline sections.
|
49 |
-
|
50 |
Parameters:
|
51 |
-
|
52 |
-
|
53 |
Return:
|
54 |
-
|
55 |
'''
|
56 |
-
|
57 |
-
sections = re.split(r'\b[
|
58 |
sections = [f"{i}. {section}" for i, section in enumerate(sections, start=1)]
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
for section in sections:
|
63 |
-
cleaned_section = remove_ast(section)
|
64 |
-
outline_list.append(cleaned_section)
|
65 |
-
|
66 |
-
return outline_list
|
67 |
-
|
|
|
|
|
|
|
1 |
import re
|
2 |
from remove_astricks import remove_ast
|
3 |
+
from typing import List
|
4 |
|
5 |
+
from langchain.prompts import PromptTemplate
|
6 |
+
from langchain.chains import LLMChain
|
7 |
+
from langchain.llms import OpenAI
|
8 |
|
9 |
+
from load_model import call_palm
|
10 |
+
from calling_apis import google_api_key, openai_api_key
|
11 |
+
|
12 |
+
|
13 |
+
def outlines_generator(idea : str, keywords : str, language='En', creativity='Original', model_name='Google Palm 2') -> str:
|
14 |
|
15 |
'''
|
16 |
Description:
|
|
|
24 |
|
25 |
idea (str): The main idea or topic of the article for which you want to generate an outline.
|
26 |
keywords (str): A set of keywords or topic-related terms that will be used as section headings in the outline. These headings help organize the content and provide a structure for the article.
|
27 |
+
language (str): Opitonal Parameter -> The language of the model.
|
28 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
29 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
30 |
+
|
31 |
'''
|
32 |
|
33 |
'''
|
|
|
36 |
outlines (str): The generated outline for the article, including section headings and placeholders for content under each heading.
|
37 |
'''
|
38 |
|
39 |
+
temp = 0
|
40 |
+
|
41 |
+
if creativity == 'Original':
|
42 |
+
temp = 0
|
43 |
+
elif creativity == 'Balanced':
|
44 |
+
temp = 0.25
|
45 |
+
elif creativity == 'Creative':
|
46 |
+
temp = 0.5
|
47 |
+
elif creativity == 'Spirited':
|
48 |
+
temp = 0.75
|
49 |
+
elif creativity == 'Visionary':
|
50 |
+
temp = 1
|
51 |
+
|
52 |
+
|
53 |
+
if model_name == 'Google Palm 2':
|
54 |
+
llm = call_palm(google_api_key, temperature=temp)
|
55 |
+
|
56 |
+
elif model_name == 'GPT-3.5':
|
57 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
58 |
+
|
59 |
+
elif model_name == 'GPT-4':
|
60 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
61 |
+
|
62 |
+
|
63 |
+
if language == 'En':
|
64 |
+
outlines_prompt = f"Generate an outline with at least 10 main points for an article on {idea}. Include key points related to {keywords}.\nBe creative and innovation in each main topic"
|
65 |
+
|
66 |
+
outlines_promptTemp = PromptTemplate(
|
67 |
+
input_variables=["text_input"],
|
68 |
+
template="You are a professional writer\n\n{text_input}\n\nOutline (number each main point with roman numerals):")
|
69 |
+
|
70 |
+
elif language == 'Ar':
|
71 |
+
outlines_prompt = f"قم بتوليد مخطط تفصيلي يحتوي على ما لا يقل عن ١٠ نقاط رئيسية لمقال حول {idea}. وضمّن النقاط الرئيسية المتعلقة بـ {keywords}.\nكن مبدعًا ومبتكرًا في كل موضوع رئيسي."
|
72 |
+
|
73 |
+
outlines_promptTemp = PromptTemplate(
|
74 |
+
input_variables=["text_input"],
|
75 |
+
template="أنت كاتب محترف\n\n{text_input}\n\nالخطوط العريضة (عد كل نقطة رئيسية بأرقام رومانية):")
|
76 |
+
|
77 |
outlines_extraction_chain = LLMChain(llm=llm, prompt=outlines_promptTemp)
|
78 |
outlines = outlines_extraction_chain.run(outlines_prompt)
|
79 |
|
80 |
return outlines
|
81 |
|
82 |
|
83 |
+
def filtered_outlines(outline : str) -> List[str]:
|
|
|
84 |
'''
|
85 |
Description:
|
86 |
+
This function processes an outline text by splitting it into sections based on Roman numeral patterns followed by a dot and space. It then generates a list of formatted sections.
|
87 |
+
|
|
|
|
|
88 |
Parameters:
|
89 |
+
`outline` -> Required: (str) The input outline text to be processed.
|
90 |
+
|
91 |
Return:
|
92 |
+
`sections`: (list) A list containing sections of the outline formatted with Arabic numerals (1, 2, 3, ...) and concatenated with their corresponding section content.
|
93 |
'''
|
94 |
+
|
95 |
+
sections = re.split(r'\b[IVXL]+\.\s', outline)[1:]
|
96 |
sections = [f"{i}. {section}" for i, section in enumerate(sections, start=1)]
|
97 |
|
98 |
+
return sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
product_description_generation.py
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
'''
|
7 |
Description:
|
@@ -14,19 +18,54 @@ def product_description_gen(product_name, product_desc, tone_of_voice, llm):
|
|
14 |
product_name (str) -> Required: The name of the product for which the description is generated.
|
15 |
product_desc (str) -> Required: A brief description of the product.
|
16 |
tone_of_voice (str) -> Required: The intended tone of the product description (e.g., professional, friendly, persuasive).
|
17 |
-
|
|
|
|
|
18 |
'''
|
19 |
|
20 |
'''
|
21 |
Return Value:
|
22 |
product_desc (str): The generated Amazon product description.
|
23 |
'''
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
productDesc_extraction_chain = LLMChain(llm=llm, prompt=productDesc_promptTemp)
|
31 |
product_desc = productDesc_extraction_chain.run(productDesc_prompt)
|
32 |
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
7 |
+
|
8 |
+
def product_description_gen(product_name:str, product_desc:str, tone_of_voice:str, language='En', model_name = 'Google Palm 2', creativity = 'Original') -> str:
|
9 |
|
10 |
'''
|
11 |
Description:
|
|
|
18 |
product_name (str) -> Required: The name of the product for which the description is generated.
|
19 |
product_desc (str) -> Required: A brief description of the product.
|
20 |
tone_of_voice (str) -> Required: The intended tone of the product description (e.g., professional, friendly, persuasive).
|
21 |
+
language (str): Opitonal Parameter -> The language of the model.
|
22 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
23 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
24 |
'''
|
25 |
|
26 |
'''
|
27 |
Return Value:
|
28 |
product_desc (str): The generated Amazon product description.
|
29 |
'''
|
30 |
+
|
31 |
+
temp = 0
|
32 |
+
|
33 |
+
if creativity == 'Original':
|
34 |
+
temp = 0
|
35 |
+
elif creativity == 'Balanced':
|
36 |
+
temp = 0.25
|
37 |
+
elif creativity == 'Creative':
|
38 |
+
temp = 0.5
|
39 |
+
elif creativity == 'Spirited':
|
40 |
+
temp = 0.75
|
41 |
+
elif creativity == 'Visionary':
|
42 |
+
temp = 1
|
43 |
+
|
44 |
+
|
45 |
+
if model_name == 'Google Palm 2':
|
46 |
+
llm = call_palm(google_api_key, temperature=temp)
|
47 |
+
|
48 |
+
elif model_name == 'GPT-3.5':
|
49 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
50 |
+
|
51 |
+
elif model_name == 'GPT-4':
|
52 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
53 |
+
|
54 |
+
|
55 |
+
if language == 'En':
|
56 |
|
57 |
+
productDesc_prompt = f"Write an engagging and {tone_of_voice} Amazon product description of {product_name} Product here is a short description of my product:\n\n{product_desc}\n"
|
58 |
+
productDesc_promptTemp = PromptTemplate(
|
59 |
+
input_variables=["text_input"],
|
60 |
+
template="You are a content creator and product description writer who helps clients to write their product description on amazon:\n{text_input}\nAmazon Product Description:")
|
61 |
+
|
62 |
+
elif language == 'Ar':
|
63 |
+
|
64 |
+
productDesc_prompt = f"اكتب وصفًا جذابًا و{tone_of_voice} عن منتج {product_name} في أمازون. هنا وصف قصير لمنتجي:\n\n{product_desc}\n"
|
65 |
+
productDesc_promptTemp = PromptTemplate(
|
66 |
+
input_variables=["text_input"],
|
67 |
+
template="أنت كاتب محتوى وكاتب وصف المنتجات الذي يساعد العملاء في كتابة وصف منتجاتهم على أمازون:\n{text_input}\nوصف منتج أمازون:")
|
68 |
+
|
69 |
productDesc_extraction_chain = LLMChain(llm=llm, prompt=productDesc_promptTemp)
|
70 |
product_desc = productDesc_extraction_chain.run(productDesc_prompt)
|
71 |
|
workout_plan_generation.py
CHANGED
@@ -1,25 +1,88 @@
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
* Health Considerations: I'm in the {helth_cosnd}.
|
16 |
-
* Preferred Routine: I like to follow {routine} routine.\nWorkout Plan:"""
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
workout_plan_extraction_chain = LLMChain(llm=llm, prompt=workout_plan_promptTemp)
|
24 |
workout_plan = workout_plan_extraction_chain.run(workout_plan_prompt)
|
25 |
|
|
|
1 |
from langchain.prompts import PromptTemplate
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.llms import OpenAI
|
4 |
|
5 |
+
from load_model import call_palm
|
6 |
+
from calling_apis import google_api_key, openai_api_key
|
|
|
|
|
7 |
|
8 |
+
def workout_plan_gen(my_goals:str, fitness_level:str, days:int, hours:int, helth_cosnd:str, routine:str, language='En', model_name='Google Palm 2', creativity='Original')->str:
|
9 |
+
|
10 |
+
"""
|
11 |
+
Generates a Gym Workout Plan based on user's goal, fiteness_level, days and hours avaliable, his routine and health considiration.
|
12 |
+
|
13 |
+
Parameters:
|
|
|
|
|
14 |
|
15 |
+
my_goals (str): Trainee Goal from the Gym Workout.
|
16 |
+
fitness_level (str): Level of the trainee Fitness.
|
17 |
+
days (int): Avaliable Days.
|
18 |
+
hours (int): Avaliable Hours.
|
19 |
+
helth_cosnd (str): Health Considiration.
|
20 |
+
routine (str): Trainee Routine.
|
21 |
+
language (str): the language of the generated content (optional, default value is 'EN').
|
22 |
+
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
|
23 |
+
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
|
24 |
+
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
workout_plan (str): Generated Workout Plan.
|
28 |
+
|
29 |
+
"""
|
30 |
+
|
31 |
+
temp = 0
|
32 |
+
|
33 |
+
if creativity == 'Original':
|
34 |
+
temp = 0
|
35 |
+
elif creativity == 'Balanced':
|
36 |
+
temp = 0.25
|
37 |
+
elif creativity == 'Creative':
|
38 |
+
temp = 0.5
|
39 |
+
elif creativity == 'Spirited':
|
40 |
+
temp = 0.75
|
41 |
+
elif creativity == 'Visionary':
|
42 |
+
temp = 1
|
43 |
+
|
44 |
+
|
45 |
+
if model_name == 'Google Palm 2':
|
46 |
+
llm = call_palm(google_api_key, temperature=temp)
|
47 |
|
48 |
+
elif model_name == 'GPT-3.5':
|
49 |
+
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
|
50 |
+
|
51 |
+
elif model_name == 'GPT-4':
|
52 |
+
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
if language == 'En':
|
57 |
+
|
58 |
+
workout_plan_prompt = f"""Generate a workout plan with diversity and creative exercises.
|
59 |
+
Please note the following details:
|
60 |
+
* My Goals: I'm looking to {my_goals}
|
61 |
+
* Fitness Level: {fitness_level}.
|
62 |
+
* Available Equipment: I have access to a gym with various equipment.
|
63 |
+
* Time Commitment: I'm dedicated to working out {days} days a week, and I have {hours} hours a day I can spend during each session.
|
64 |
+
* Health Considerations: I'm in the {helth_cosnd}.
|
65 |
+
* Preferred Routine: I like to follow {routine} routine.\nWorkout Plan:"""
|
66 |
+
workout_plan_promptTemp = PromptTemplate(
|
67 |
+
input_variables=["text_input"],
|
68 |
+
template="You are a Professional Fitness Trainer:\n{text_input}")
|
69 |
+
|
70 |
+
elif language == 'Ar':
|
71 |
+
|
72 |
+
workout_plan_prompt = f"""قم بإنشاء خطة تمارين رياضية متنوعة ومبتكرة.
|
73 |
+
يرجى مراعاة التفاصيل التالية:
|
74 |
+
* أهدافي: أنا أسعى لـ {my_goals}.
|
75 |
+
* مستوى اللياقة: {fitness_level}.
|
76 |
+
* المعدات المتاحة: لدي الوصول إلى صالة ألعاب رياضية بها معدات متنوعة.
|
77 |
+
* الالتزام الزمني: أنا ملتزم بممارسة التمارين {days} أيام في الأسبوع، ولدي {hours} ساعة يوميًا يمكنني قضائها خلال كل جلسة.
|
78 |
+
* اعتبارات الصحة: أنا في حالة {helth_cosnd}.
|
79 |
+
* الروتين المفضل: أحب اتباع الروتين {routine}.\nخطة التمارين:"""
|
80 |
+
|
81 |
+
workout_plan_promptTemp = PromptTemplate(
|
82 |
+
input_variables=["text_input"],
|
83 |
+
template="أنت مدرب لياقة مهني:\n{text_input}")
|
84 |
+
|
85 |
+
|
86 |
workout_plan_extraction_chain = LLMChain(llm=llm, prompt=workout_plan_promptTemp)
|
87 |
workout_plan = workout_plan_extraction_chain.run(workout_plan_prompt)
|
88 |
|