DrishtiSharma commited on
Commit
45fc613
Β·
verified Β·
1 Parent(s): 7692c8e

Update post_generator.py

Browse files
Files changed (1) hide show
  1. 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 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
 
 
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