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"))