DrishtiSharma
commited on
Update post_generator.py
Browse files- post_generator.py +39 -189
post_generator.py
CHANGED
@@ -12,202 +12,52 @@ def get_length_str(length):
|
|
12 |
return "11 to 15 lines"
|
13 |
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def generate_post(length, language, tag, selected_tone=None):
|
16 |
"""
|
17 |
-
Generate a LinkedIn post
|
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 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
"
|
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 |
|
|
|
12 |
return "11 to 15 lines"
|
13 |
|
14 |
|
15 |
+
def generate_closing_line(language, tag, tone):
|
16 |
+
"""
|
17 |
+
Generate a closing line using the LLM based on language, tag, and tone.
|
18 |
+
"""
|
19 |
+
closing_prompt = f"""
|
20 |
+
You are writing a LinkedIn post. Create a concise and engaging closing line.
|
21 |
+
- The closing line should reflect the topic: "{tag}".
|
22 |
+
- Use the tone/style: "{tone}".
|
23 |
+
- The closing line must encourage engagement or provide a call to action, relevant to the topic.
|
24 |
+
- Use the language: "{language}" (Hinglish means Hindi phrases written in English script).
|
25 |
+
|
26 |
+
Examples:
|
27 |
+
- Topic: "Job Search", Tone: "Motivational", Language: "English"
|
28 |
+
Closing Line: "Your dream job is closer than you think. Stay determined! π"
|
29 |
+
|
30 |
+
- Topic: "Mental Health", Tone: "Professional", Language: "English"
|
31 |
+
Closing Line: "Your mental well-being is essential. Letβs discuss ways to manage stress. π‘"
|
32 |
+
|
33 |
+
- Topic: "Dating", Tone: "Informal", Language: "Hinglish"
|
34 |
+
Closing Line: "Apka perfect date idea kya hai? Neeche share karein! π"
|
35 |
+
|
36 |
+
Now, write a relevant closing line for the following inputs:
|
37 |
+
Topic: "{tag}"
|
38 |
+
Tone: "{tone}"
|
39 |
+
Language: "{language}"
|
40 |
+
"""
|
41 |
+
response = llm.invoke(closing_prompt)
|
42 |
+
return response.content.strip()
|
43 |
+
|
44 |
+
|
45 |
def generate_post(length, language, tag, selected_tone=None):
|
46 |
"""
|
47 |
+
Generate a LinkedIn post dynamically with LLM including a generated closing line.
|
48 |
"""
|
|
|
49 |
prompt = get_prompt(length, language, tag)
|
50 |
response = llm.invoke(prompt)
|
51 |
post_content = response.content
|
52 |
|
53 |
+
# Generate a dynamic closing line using LLM
|
54 |
+
if selected_tone and tag:
|
55 |
+
try:
|
56 |
+
closing_line = generate_closing_line(language, tag, selected_tone)
|
57 |
+
post_content += f"\n\n{closing_line}"
|
58 |
+
except Exception as e:
|
59 |
+
# Fallback in case of LLM failure
|
60 |
+
post_content += f"\n\nThank you for reading. Your feedback is valued! π"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
return post_content
|
63 |
|