File size: 4,506 Bytes
765a4ee f7a52fb 765a4ee f7a52fb 49c324c f7a52fb 49c324c f7a52fb 49c324c f7a52fb 49c324c f7a52fb 765a4ee e1a012a 765a4ee e1a012a 765a4ee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
from llm_helper import llm
from few_shot import FewShotPosts
few_shot = FewShotPosts()
def get_length_str(length):
if length == "Short":
return "1 to 5 lines"
if length == "Medium":
return "6 to 10 lines"
if length == "Long":
return "11 to 15 lines"
def generate_post(length, language, tag, selected_tone=None):
prompt = get_prompt(length, language, tag)
response = llm.invoke(prompt)
post_content = response.content
# Add closing statements dynamically based on tone and language
closing_lines = {
"Motivational": {
"English": [
"Stay inspired and keep moving forward! πͺ",
"Your journey to greatness begins today. π",
"Remember, small steps lead to big achievements. π",
"Keep pushing your boundaries. Youβve got this! π₯"
],
"Hinglish": [
"Dhire dhire aage badho aur safalta pao! πͺ",
"Sapne bade rakho, unhe pura karo. π",
"Chhoti chhoti koshis se bade lakshya hasil hote hain! π",
"Apne boundaries todho, aap kar sakte ho! π₯"
]
},
"Professional": {
"English": [
"Looking forward to hearing your thoughts! π",
"Letβs collaborate and make an impact together. π",
"Feel free to share your perspective below. π’",
"Insights and feedback are always welcome. π‘"
],
"Hinglish": [
"Aapke vichar sunne ka intezaar hai! π",
"Chaliye milkar kuch asar karte hain. π",
"Neeche apne vichar zaroor share karein. π’",
"Aapka feedback hamare liye mahatvapurn hai. π‘"
]
},
"Informal": {
"English": [
"What do you think? Let's chat in the comments! π",
"Drop your thoughts below, would love to hear from you! π¨οΈ",
"Letβs keep the conversation rolling. Share your views! π",
"Got something to add? Donβt hold back! π"
],
"Hinglish": [
"Kya sochte ho? Comments mein baat karte hain! π",
"Apne vichar neeche likho, sunne ke liye excited hoon! π¨οΈ",
"Charcha ko jaari rakhein, apne vichar share karein! π",
"Kuch add karna hai? Sharmana mat, batao! π"
]
},
"Neutral": {
"English": [
"Thank you for reading. Your feedback is valued! π",
"Letβs connect and share ideas. π",
"Looking forward to engaging with you in the comments. π¬",
"Your thoughts are always appreciated. π"
],
"Hinglish": [
"Padhne ke liye dhanyavaad. Aapka feedback mahatvapurn hai! π",
"Chaliye judein aur naye ideas share karein. π",
"Aapke vichar comments mein padhne ka intezaar hai. π¬",
"Aapke sujhav hamesha sarankrit hote hain. π"
]
}
}
if selected_tone and selected_tone in closing_lines:
if language == "Hinglish" and "Hinglish" in closing_lines[selected_tone]:
closing_line = closing_lines[selected_tone]["Hinglish"]
else:
closing_line = closing_lines[selected_tone]["English"]
# Randomly select a closing line
import random
post_content += f"\n\n{random.choice(closing_line)}"
return post_content
def get_prompt(length, language, tag):
length_str = get_length_str(length)
prompt = f'''
Write a professional, engaging LinkedIn post.
1. Topic: "{tag}"
2. Post Length: "{length_str}"
3. Language: "{language}" (Hinglish means Hindi phrases written in English script).
4. Incorporate creativity, enthusiasm, emotional appeal, and actionable advice.
'''
examples = few_shot.get_filtered_posts(length, language, tag)
if examples:
prompt += "\nExamples of great posts:\n"
for i, post in enumerate(examples[:2]): # Limit to 2 examples
post_text = post['text']
prompt += f"Example {i + 1}: {post_text}\n"
prompt += "\nNow write the post."
return prompt
if __name__ == "__main__":
print(generate_post("Medium", "English", "Mental Health")) |