DrishtiSharma
commited on
Update post_generator.py
Browse files- post_generator.py +175 -53
post_generator.py
CHANGED
@@ -13,79 +13,201 @@ def get_length_str(length):
|
|
13 |
|
14 |
|
15 |
def generate_post(length, language, tag, selected_tone=None):
|
|
|
|
|
|
|
|
|
16 |
prompt = get_prompt(length, language, tag)
|
17 |
response = llm.invoke(prompt)
|
18 |
post_content = response.content
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
21 |
closing_lines = {
|
22 |
"Motivational": {
|
23 |
-
"English":
|
24 |
-
"
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
"
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
},
|
36 |
"Professional": {
|
37 |
-
"English":
|
38 |
-
"
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
"
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
},
|
50 |
"Informal": {
|
51 |
-
"English":
|
52 |
-
"
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
"
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
},
|
64 |
"Neutral": {
|
65 |
-
"English":
|
66 |
-
"
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
"
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
}
|
79 |
|
|
|
80 |
if selected_tone and selected_tone in closing_lines:
|
81 |
-
|
82 |
-
|
|
|
83 |
else:
|
84 |
-
|
85 |
|
86 |
# Randomly select a closing line
|
87 |
import random
|
88 |
-
post_content += f"\n\n{random.choice(
|
89 |
|
90 |
return post_content
|
91 |
|
|
|
13 |
|
14 |
|
15 |
def generate_post(length, language, tag, selected_tone=None):
|
16 |
+
"""
|
17 |
+
Generate a LinkedIn post based on the given length, language, topic (tag), and tone.
|
18 |
+
"""
|
19 |
+
# Prepare the prompt for the LLM
|
20 |
prompt = get_prompt(length, language, tag)
|
21 |
response = llm.invoke(prompt)
|
22 |
post_content = response.content
|
23 |
|
24 |
+
# Fetch all available topics dynamically from FewShotPosts
|
25 |
+
fs = FewShotPosts()
|
26 |
+
all_topics = [topic.lower() for topic in fs.get_tags()]
|
27 |
+
|
28 |
+
# Closing lines structure
|
29 |
closing_lines = {
|
30 |
"Motivational": {
|
31 |
+
"English": {
|
32 |
+
"default": [
|
33 |
+
"Stay inspired and keep moving forward! πͺ",
|
34 |
+
"Your journey to greatness begins today. π",
|
35 |
+
"Remember, small steps lead to big achievements. π",
|
36 |
+
"Keep pushing your boundaries. Youβve got this! π₯"
|
37 |
+
],
|
38 |
+
"dating": [
|
39 |
+
"Love yourself first; the rest will follow! π",
|
40 |
+
"Every journey begins with a spark. Keep believing! β¨",
|
41 |
+
"Trust the process, and love will find its way. π",
|
42 |
+
"Stay true to yourself, and the right person will connect. πΈ"
|
43 |
+
],
|
44 |
+
"mental health": [
|
45 |
+
"Your mental health matters. Take care of yourself! π",
|
46 |
+
"Small steps lead to great mental wellness. πΏ",
|
47 |
+
"Prioritize self-care; itβs your greatest investment. πΌ",
|
48 |
+
"Remember, itβs okay to seek help when needed. π"
|
49 |
+
],
|
50 |
+
"job search": [
|
51 |
+
"Your dream job is closer than you think. Keep going! π",
|
52 |
+
"Stay focused and determined; success is near. π",
|
53 |
+
"Every application is a step toward your goal. β¨",
|
54 |
+
"Believe in your skills; the right opportunity awaits! πΌ"
|
55 |
+
],
|
56 |
+
"technology": [
|
57 |
+
"Innovation starts with curiosity. Explore! π‘",
|
58 |
+
"Stay updated and keep learning in this ever-changing field. π±",
|
59 |
+
"Technology drives the future. Be part of it! π",
|
60 |
+
"Every breakthrough starts with an idea. Whatβs yours? π"
|
61 |
+
],
|
62 |
+
"wellness": [
|
63 |
+
"Health is wealth. Invest in yourself! πͺ",
|
64 |
+
"Take time to nurture your body and soul. πΈ",
|
65 |
+
"Wellness is a journey, not a destination. πΏ",
|
66 |
+
"Small habits lead to a healthier, happier you. πΌ"
|
67 |
+
]
|
68 |
+
},
|
69 |
+
"Hinglish": {
|
70 |
+
"default": [
|
71 |
+
"Dhire dhire aage badho aur safalta pao! πͺ",
|
72 |
+
"Sapne bade rakho, unhe pura karo. π",
|
73 |
+
"Chhoti chhoti koshis se bade lakshya hasil hote hain! π",
|
74 |
+
"Apne boundaries todho, aap kar sakte ho! π₯"
|
75 |
+
],
|
76 |
+
"dating": [
|
77 |
+
"Khud se pyaar karo, baaki sab aasan hoga! π",
|
78 |
+
"Har safar ek chhoti chamak se shuru hoti hai! β¨",
|
79 |
+
"Apne upar bharosa rakho, pyaar apna rasta dhund lega. π",
|
80 |
+
"Apne asli roop mein raho, sahi insaan connect karega. πΈ"
|
81 |
+
],
|
82 |
+
"mental health": [
|
83 |
+
"Aapki mental health mahatvapurn hai. Apna dhyan rakhein! π",
|
84 |
+
"Chhoti chhoti koshis se acchi sehat milti hai. πΏ",
|
85 |
+
"Self-care ko prioritize karein; yeh aapka sabse bada asset hai. πΌ",
|
86 |
+
"Yaad rakhein, zarurat padne par madad lena bilkul sahi hai. π"
|
87 |
+
],
|
88 |
+
"job search": [
|
89 |
+
"Aapka sapno ka naukri aapke kareeb hai. Lage raho! π",
|
90 |
+
"Focus banaye rakhein; safalta paas hai. π",
|
91 |
+
"Har application aapke goal ki taraf ek kadam hai. β¨",
|
92 |
+
"Apni skills par bharosa rakhein; sahi opportunity intezaar kar rahi hai! πΌ"
|
93 |
+
],
|
94 |
+
"technology": [
|
95 |
+
"Innovation curiosity se shuru hoti hai. Khojiye! π‘",
|
96 |
+
"Stay updated, ye field hamesha badal rahi hai. π±",
|
97 |
+
"Technology future ko chalati hai. Hissa baniye! π",
|
98 |
+
"Har breakthrough ek idea se shuru hota hai. Aapka kya hai? π"
|
99 |
+
],
|
100 |
+
"wellness": [
|
101 |
+
"Health hi wealth hai. Khud par invest karein! πͺ",
|
102 |
+
"Apne body aur soul ko nurture karne ka samay nikalien. πΈ",
|
103 |
+
"Wellness ek journey hai, destination nahi. πΏ",
|
104 |
+
"Chhoti aadatein ek healthy aur happy aap banati hain. πΌ"
|
105 |
+
]
|
106 |
+
}
|
107 |
},
|
108 |
"Professional": {
|
109 |
+
"English": {
|
110 |
+
"default": [
|
111 |
+
"Looking forward to hearing your thoughts! π",
|
112 |
+
"Letβs collaborate and make an impact together. π",
|
113 |
+
"Feel free to share your perspective below. π’",
|
114 |
+
"Insights and feedback are always welcome. π‘"
|
115 |
+
],
|
116 |
+
"job search": [
|
117 |
+
"Networking is key to success. Letβs connect! π",
|
118 |
+
"Stay prepared and open to opportunities. π",
|
119 |
+
"Professional growth starts with the right connections. π",
|
120 |
+
"Every step counts in your career journey. Keep moving! πΌ"
|
121 |
+
],
|
122 |
+
"technology": [
|
123 |
+
"Technology thrives on collaboration. Letβs innovate together! π»",
|
124 |
+
"Stay curious and keep challenging the status quo. π",
|
125 |
+
"Your insights can drive the next big breakthrough. Share below! π‘",
|
126 |
+
"Adaptation and growth go hand in hand in tech. Letβs excel! π"
|
127 |
+
]
|
128 |
+
},
|
129 |
+
"Hinglish": {
|
130 |
+
"default": [
|
131 |
+
"Aapke vichar sunne ka intezaar hai! π",
|
132 |
+
"Chaliye milkar kuch asar karte hain. π",
|
133 |
+
"Neeche apne vichar zaroor share karein. π’",
|
134 |
+
"Aapka feedback hamare liye mahatvapurn hai. π‘"
|
135 |
+
],
|
136 |
+
"job search": [
|
137 |
+
"Networking safalta ki kunji hai. Chaliye judte hain! π",
|
138 |
+
"Tayyar rahiye aur naye opportunities ke liye khule rahiye. π",
|
139 |
+
"Professional growth sahi connections se shuru hoti hai. π",
|
140 |
+
"Aapke career journey mein har kadam mahatvapurn hai. Lage raho! πΌ"
|
141 |
+
],
|
142 |
+
"technology": [
|
143 |
+
"Technology collaboration se phalti phoolti hai. Milkar innovate karein! π»",
|
144 |
+
"Curiosity banaye rakhein aur naye challenges ko accept karein. π",
|
145 |
+
"Aapke insights agla bada breakthrough laa sakte hain. Neeche share karein! π‘",
|
146 |
+
"Tech mein adaptation aur growth saath saath chalte hain. Chaliye excellence achieve karein! π"
|
147 |
+
]
|
148 |
+
}
|
149 |
},
|
150 |
"Informal": {
|
151 |
+
"English": {
|
152 |
+
"default": [
|
153 |
+
"What do you think? Let's chat in the comments! π",
|
154 |
+
"Drop your thoughts below, would love to hear from you! π¨οΈ",
|
155 |
+
"Letβs keep the conversation rolling. Share your views! π",
|
156 |
+
"Got something to add? Donβt hold back! π"
|
157 |
+
],
|
158 |
+
"dating": [
|
159 |
+
"Whatβs your idea of a perfect date? Letβs talk! π",
|
160 |
+
"Got a dating tip? Share it below! π«",
|
161 |
+
"Dating stories? Share your fun experiences! β€οΈ",
|
162 |
+
"Letβs chat about love and connections! π"
|
163 |
+
]
|
164 |
+
},
|
165 |
+
"Hinglish": {
|
166 |
+
"default": [
|
167 |
+
"Kya sochte ho? Comments mein baat karte hain! π",
|
168 |
+
"Apne vichar neeche likho, sunne ke liye excited hoon! π¨οΈ",
|
169 |
+
"Charcha ko jaari rakhein, apne vichar share karein! π",
|
170 |
+
"Kuch add karna hai? Sharmana mat, batao! π"
|
171 |
+
],
|
172 |
+
"dating": [
|
173 |
+
"Aapke liye perfect date kya hai? Bataiye! π",
|
174 |
+
"Koi dating tip hai? Share karein! π«",
|
175 |
+
"Dating stories? Apne mazedar anubhav share karein! β€οΈ",
|
176 |
+
"Chaliye pyaar aur connection ke baare mein baat karein! π"
|
177 |
+
]
|
178 |
+
}
|
179 |
},
|
180 |
"Neutral": {
|
181 |
+
"English": {
|
182 |
+
"default": [
|
183 |
+
"Thank you for reading. Your feedback is valued! π",
|
184 |
+
"Letβs connect and share ideas. π",
|
185 |
+
"Looking forward to engaging with you in the comments. π¬",
|
186 |
+
"Your thoughts are always appreciated. π"
|
187 |
+
]
|
188 |
+
},
|
189 |
+
"Hinglish": {
|
190 |
+
"default": [
|
191 |
+
"Padhne ke liye dhanyavaad. Aapka feedback mahatvapurn hai! π",
|
192 |
+
"Chaliye judein aur naye ideas share karein. π",
|
193 |
+
"Aapke vichar comments mein padhne ka intezaar hai. π¬",
|
194 |
+
"Aapke sujhav hamesha sarankrit hote hain. π"
|
195 |
+
]
|
196 |
+
}
|
197 |
}
|
198 |
}
|
199 |
|
200 |
+
# Determine the appropriate closing lines
|
201 |
if selected_tone and selected_tone in closing_lines:
|
202 |
+
tone_lines = closing_lines[selected_tone][language]
|
203 |
+
if tag.lower() in all_topics and tag.lower() in tone_lines:
|
204 |
+
topic_closing = tone_lines[tag.lower()]
|
205 |
else:
|
206 |
+
topic_closing = tone_lines["default"]
|
207 |
|
208 |
# Randomly select a closing line
|
209 |
import random
|
210 |
+
post_content += f"\n\n{random.choice(topic_closing)}"
|
211 |
|
212 |
return post_content
|
213 |
|