File size: 16,244 Bytes
4c9c33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b55e421
15cbeaa
4c9c33d
8e7c3a6
 
4c9c33d
 
 
 
 
 
 
 
 
 
 
 
8adc62f
4c9c33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21b2ce3
4c9c33d
5447462
16d2117
 
 
 
 
 
4c9c33d
16d2117
8adc62f
 
 
 
 
 
16d2117
8adc62f
16d2117
8adc62f
 
 
 
 
 
16d2117
 
 
 
 
8adc62f
 
 
16d2117
 
 
8adc62f
5447462
8adc62f
16d2117
 
 
8adc62f
 
16d2117
4c9c33d
16d2117
 
 
8cc4721
16d2117
8adc62f
 
 
 
 
16d2117
 
 
 
 
8adc62f
 
16d2117
 
 
 
 
8adc62f
5447462
8adc62f
16d2117
 
 
 
8adc62f
5447462
16d2117
 
 
 
 
 
 
 
 
 
5447462
 
16d2117
 
 
5447462
 
16d2117
 
 
 
5447462
 
 
16d2117
 
 
 
 
5447462
16d2117
 
 
 
 
8adc62f
 
 
 
 
16d2117
8adc62f
16d2117
 
 
 
8adc62f
16d2117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5447462
16d2117
 
 
 
5447462
16d2117
 
 
8adc62f
5447462
8adc62f
4c9c33d
 
 
8adc62f
4c9c33d
 
 
5d964cf
4c9c33d
5d964cf
 
 
 
 
24cd1a9
5711385
24cd1a9
4c9c33d
 
 
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
 
5d964cf
 
4c9c33d
5d964cf
8cc4721
5d964cf
8cc4721
5d964cf
8cc4721
4c9c33d
5d964cf
4c9c33d
5d964cf
4c9c33d
 
 
 
 
 
 
 
 
 
8e7c3a6
5d964cf
 
 
 
 
 
 
4c9c33d
 
 
 
 
 
 
5d964cf
 
 
 
 
 
 
4c9c33d
 
 
5d964cf
4c9c33d
 
 
5d964cf
4c9c33d
5d964cf
 
 
8cc4721
4c9c33d
5d964cf
4c9c33d
 
 
 
 
5d964cf
4c9c33d
 
 
5d964cf
4c9c33d
 
 
5d964cf
4c9c33d
5d964cf
4c9c33d
 
 
 
5d964cf
4c9c33d
5d964cf
8cc4721
4c9c33d
 
5d964cf
4c9c33d
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
 
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
5d964cf
4c9c33d
 
 
 
 
 
5d964cf
4c9c33d
40c605f
 
 
 
ccb80fd
40c605f
bd280c3
ccb80fd
 
 
 
 
bd280c3
4c9c33d
 
40c605f
 
 
ccb80fd
40c605f
 
 
ccb80fd
40c605f
 
 
 
 
ccb80fd
40c605f
4c9c33d
ccb80fd
bd280c3
5d964cf
 
 
 
 
 
 
 
 
 
 
 
c4ff4bb
 
 
 
4c9c33d
b55e421
c4ff4bb
4c9c33d
c4ff4bb
4c9c33d
c4ff4bb
7f54e54
c4ff4bb
4c9c33d
5d964cf
ce5c6a2
5d964cf
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
import gradio as gr
import datetime
import random
from collections import defaultdict

from utils.constants import TASK_DIFFICULTIES
from utils.data_helpers import smart_label_converter, clean_text, extract_actions_from_feedback
from utils.api_clients import initialize_api_clients
from utils.embedding_model import initialize_embedding_model
from utils.summarizer import initialize_summarizer
from utils.constants import course_suggestions
from modules.rag import load_docs, memo_rag_engine, batch_ingest_from_classcentral
from modules.task_management import display_tasks, add_reward, calculate_progress, claim_reward, add_task, add_course_to_memo, mark_step_completed, calculate_visual_progress, reset_weekly_data
from modules.analysis import analyze_linkedin, analyze_github, analyze_scraped_linkedin_profile, analyze_apify_dataset_ui
from modules.analysis import fetch_and_analyze_linkedin
from utils.constants import completed_tasks 
from modules.memory import save_to_memory, recall_from_memory
import textwrap
from modules.analysis import fetch_and_analyze_linkedin  # Import the function for LinkedIn analysis



# ==== Global Variables ====
completed_tasks = set()
memo_data = []
visual_steps = []

# ==== API Clients & Models ====
pc, pine_index, APIFY_TOKEN, OPENAI_API_KEY, TAVILY_API_KEY, client = initialize_api_clients()
embedding_model = initialize_embedding_model()
summarizer = initialize_summarizer()


# ==== Gradio UI Components ====
class RoadmapUnlockManager:
    def __init__(self):
        self.unlocked = False

    def unlock_roadmap(self):
        self.unlocked = True
        return gr.update(visible=True)

    def get_roadmap_visibility(self):
        return gr.update(visible=self.unlocked)


roadmap_unlock = RoadmapUnlockManager()





with gr.Blocks(theme="NoCrypt/[email protected]", css="""

 @import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap');

body {
    font-family: 'Source Sans Pro', sans-serif;
    background-color: #121212;
    color: #f0f0f0;
}

#nickname-box {
    max-width: 300px;
    margin: 0 auto;
    padding: 20px;
    background-color: #1e1e1e;
    border-radius: 12px;
    box-shadow: 0px 0px 10px rgba(0,0,0,0.2);
}

#planner-card {
    max-width: 720px;
    margin: 0 auto;
    padding: 28px;
    background-color: #1e1e1e;
    border-radius: 16px;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
}

#planner-card input,
#planner-card textarea,
#planner-card .gr-button {
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 8px;
}

#planner-card .gr-button {
    background-color: #3a3aff;
    color: #f0f0f0;
    font-weight: bold;
}

#planner-card label {
    font-weight: 600;
    color: #f0f0f0;
}

#planner-card .gr-tab {
    margin-top: 12px;
}

#linky-tab {
    background-color: #1e1e1e !important;
    color: #f0f0f0 !important;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

#linky-tab .gr-block,
#linky-tab .gr-column,
#linky-tab .gr-panel {
    background-color: transparent !important;
    color: inherit;
    box-shadow: none;
}

#linky-tab input,
#linky-tab textarea {
    background-color: #2c2c2c !important;
    color: #f0f0f0 !important;
    border: 1px solid #444 !important;
    border-radius: 6px;
}

#linky-tab .gr-button {
    background-color: #4444aa !important;
    color: #f0f0f0 !important;
    border-radius: 6px;
}

#dds-logo img {
    max-width: 200px;
    display: block;
    margin: 0 auto 15px;
}

#user-card {
    background-color: #2b2b2b;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 24px;
    margin-top: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
}

#user-card input,
#user-card textarea {
    background-color: #3a3a3a !important;
    color: #e0e0e0 !important;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 10px;
}

#user-card label {
    color: #cccccc;
}

@media (max-width: 768px) {
    .gr-row {
        flex-direction: column !important;
    }

    #user-card {
        margin-top: 20px;
    }
}

.gradio-container {
    color: #f0f0f0 !important;
    background-color: #121212 !important;
}

.prose {
    color: #f0f0f0 !important;
}

.gr-textbox,
.gr-markdown,
.gr-markdown div,
.gr-markdown p {
    color: #f0f0f0 !important;
    background: transparent;
}

label {
    color: #cccccc !important;
}

input, textarea {
    background-color: #1e1e1e !important;
    color: #f0f0f0 !important;
    border: 1px solid #444 !important;
}

.gr-button {
    color: #f0f0f0 !important;
    font-weight: bold;
    background-color: #3a3aff !important;
}


""") as app:
    user_id_state = gr.State()
    roadmap_unlock = RoadmapUnlockManager()
    start_date = gr.Textbox(label="πŸ“… Start Date", value=str(datetime.date.today()))

    with gr.Tabs():
        with gr.Tab("✨ Welcome"):
            with gr.Row(equal_height=True):
                # LEFT: Intro
                with gr.Column(scale=2):
                    gr.Markdown("""
                    # πŸ‘‹ Welcome to Career Buddy!
                     **Your AI-powered career planner** for LinkedIn, GitHub, and goal-tracking.**
                    If you enjoy this project and want to help me beat OpenAI costs; support me below
                    """)

                    gr.HTML("""<a href="https://ko-fi.com/wishingonstars" target="_blank"><img src="https://cdn.prod.website-files.com/5c14e387dab576fe667689cf/670f5a0172b90570b1c21dab_kofi_logo.png" alt="Support Me on Ko-fi" style="width: 150px;"></a>""")

                    gr.Markdown("""
                    ### πŸš€ Get Started
                    1. **Enter your nickname** to personalize your journey.
                    2. **Set your weekly goal** to stay on track.
                    3. **Explore the tabs** for LinkedIn/GitHub analysis, smart planning, and more!
                    """)

                # RIGHT: User Input
                with gr.Column(scale=1, elem_id="user-card"):
                    gr.Markdown("## Your Journey Starts Here")
                    nickname_input = gr.Textbox(label="Enter your Nickname", placeholder="e.g., DataScientistPro", interactive=True)
                    weekly_goal_input = gr.Textbox(label="What's your weekly career goal?", placeholder="e.g., Apply to 5 jobs, finish a Python course", interactive=True)
                    with gr.Row():
                        save_btn = gr.Button("Save Profile")
                        load_btn = gr.Button("Load Profile")

                    gr.Markdown("### Your Progress")
                    progress_output = gr.Markdown("", elem_id="progress-output")

                    save_btn.click(
                        fn=lambda nickname, goal: save_user_profile(nickname, goal),
                        inputs=[nickname_input, weekly_goal_input],
                        outputs=progress_output
                    )
                    load_btn.click(
                        fn=lambda: load_user_profile(),
                        inputs=[],
                        outputs=[nickname_input, weekly_goal_input, progress_output]
                    )

        with gr.Tab("πŸ”— Linky (LinkedIn Analyzer)", elem_id="linky-tab"):
            with gr.Row():
                with gr.Column(scale=1):
                    linkedin_url_input = gr.Textbox(label="LinkedIn Profile URL", placeholder="Paste your LinkedIn profile URL here", interactive=True)
                    analyze_linkedin_btn = gr.Button("Analyze LinkedIn Profile")
                with gr.Column(scale=2):
                    linkedin_analysis_output = gr.Markdown("", label="LinkedIn Analysis Results")

            # When the button is clicked, analyze the LinkedIn profile
            analyze_linkedin_btn.click(
                fn=fetch_and_analyze_linkedin,
                inputs=[linkedin_url_input],
                outputs=linkedin_analysis_output
            )

        with gr.Tab("πŸ™ GitGuru (GitHub Reviewer)"):
            with gr.Row():
                with gr.Column(scale=1):
                    github_readme_input = gr.Textbox(label="GitHub README Content", placeholder="Paste your main GitHub README content here", lines=10, interactive=True)
                    analyze_github_btn = gr.Button("Analyze GitHub README")
                with gr.Column(scale=2):
                    github_analysis_output = gr.Markdown("", label="GitHub Analysis Results")

            analyze_github_btn.click(
                fn=analyze_github,
                inputs=[github_readme_input],
                outputs=github_analysis_output
            )

        with gr.Tab("🧠 Smart Planner"):
            with gr.Row():
                with gr.Column(scale=1):
                    planner_goal_input = gr.Textbox(label="Your Goal", placeholder="e.g., Become a Data Scientist", interactive=True)
                    planner_difficulty_input = gr.Dropdown(label="Difficulty", choices=TASK_DIFFICULTIES, value="Medium", interactive=True)
                    planner_generate_btn = gr.Button("Generate Roadmap")
                with gr.Column(scale=2):
                    roadmap_output = gr.Markdown("", label="Career Roadmap")

            planner_generate_btn.click(
                fn=lambda goal, difficulty: generate_roadmap(goal, difficulty, pc, pine_index, client),
                inputs=[planner_goal_input, planner_difficulty_input],
                outputs=roadmap_output
            )

        with gr.Tab("🎯 Task Tracker"):
            with gr.Row():
                with gr.Column(scale=1):
                    task_name_input = gr.Textbox(label="Task Name", placeholder="e.g., Complete Python course", interactive=True)
                    task_type_input = gr.Dropdown(label="Task Type", choices=["Learning", "Networking", "Project", "Application"], value="Learning", interactive=True)
                    task_add_btn = gr.Button("Add Task")

                    gr.Markdown("### Mark Task Steps Completed")
                    task_step_input = gr.Textbox(label="Step to Mark Completed", placeholder="e.g., Chapter 1 of Python course", interactive=True)
                    task_mark_completed_btn = gr.Button("Mark Step Completed")

                    gr.Markdown("### Rewards")
                    reward_amount_input = gr.Number(label="Reward Amount", value=10, interactive=True)
                    reward_claim_btn = gr.Button("Claim Reward")

                    reset_weekly_btn = gr.Button("Reset Weekly Data")

                with gr.Column(scale=2):
                    tasks_display = gr.Markdown("", label="Your Tasks")
                    progress_bar = gr.HTML("", label="Weekly Progress")
                    rewards_display = gr.Markdown("", label="Your Rewards")

            task_add_btn.click(
                fn=lambda user_id, task_name, task_type: add_task(user_id, task_name, task_type, tasks_display, progress_bar, rewards_display),
                inputs=[user_id_state, task_name_input, task_type_input],
                outputs=[tasks_display, progress_bar, rewards_display]
            )

            task_mark_completed_btn.click(
                fn=lambda user_id, step: mark_step_completed(user_id, step, tasks_display, progress_bar, rewards_display),
                inputs=[user_id_state, task_step_input],
                outputs=[tasks_display, progress_bar, rewards_display]
            )

            reward_claim_btn.click(
                fn=lambda user_id, amount: claim_reward(user_id, amount, rewards_display),
                inputs=[user_id_state, reward_amount_input],
                outputs=rewards_display
            )

            reset_weekly_btn.click(
                fn=lambda user_id: reset_weekly_data(user_id, tasks_display, progress_bar, rewards_display),
                inputs=[user_id_state],
                outputs=[tasks_display, progress_bar, rewards_display]
            )

        with gr.Tab("πŸ“š Memo (Course Recommender)"):
            with gr.Row():
                with gr.Column(scale=1):
                    memo_query_input = gr.Textbox(label="Ask about a course or topic", placeholder="e.g., Best Python courses for data science", interactive=True)
                    memo_search_btn = gr.Button("Search Courses")
                    gr.Markdown("### Add Course to Memo")
                    memo_course_name_input = gr.Textbox(label="Course Name", interactive=True)
                    memo_course_url_input = gr.Textbox(label="Course URL", interactive=True)
                    memo_add_course_btn = gr.Button("Add Course")
                with gr.Column(scale=2):
                    memo_output = gr.Markdown("", label="Course Recommendations")

            memo_search_btn.click(
                fn=lambda query: memo_rag_engine(query, pine_index, embedding_model, client, summarizer),
                inputs=[memo_query_input],
                outputs=memo_output
            )
            memo_add_course_btn.click(
                fn=lambda name, url: add_course_to_memo(name, url, pine_index, embedding_model, client, summarizer),
                inputs=[memo_course_name_input, memo_course_url_input],
                outputs=memo_output
            )

        with gr.Tab("πŸ“Š Visualizer"):
            with gr.Row():
                with gr.Column(scale=1):
                    visualizer_goal_input = gr.Textbox(label="Your Goal", placeholder="e.g., Become a Data Scientist", interactive=True)
                    visualizer_generate_btn = gr.Button("Generate Visual Roadmap")
                with gr.Column(scale=2):
                    visualizer_output = gr.Plot(label="Visual Roadmap")

            visualizer_generate_btn.click(
                fn=lambda goal: generate_visual_roadmap(goal, visual_steps),
                inputs=[visualizer_goal_input],
                outputs=visualizer_output
            )


    def save_user_profile(nickname, weekly_goal):
        user_id = nickname.lower().replace(" ", "_")
        summary = f"User profile: {nickname}, goal: {weekly_goal}"
        steps = []  # optional placeholder
        courses = []  # optional placeholder

        success = save_to_memory(user_id, "profile", summary, steps, courses)

        if success:
            user_id_state.value = user_id
            return f"Profile for **{nickname}** saved! Weekly goal: **{weekly_goal}**"
        else:
            return "❌ Failed to save profile."


    def load_user_profile():
        user_id = user_id_state.value
        if not user_id:
            return "", "", "❌ No user loaded."

        profile_result = recall_from_memory(user_id, "profile")
        if "❌ No saved plan" in profile_result:
            return "", "", "❌ Profile not found in memory."

        lines = profile_result.splitlines()
        nickname_line = next((line for line in lines if "nickname" in line.lower()), "")
        goal_line = next((line for line in lines if "goal" in line.lower()), "")
        nickname = nickname_line.split(":")[-1].strip() if nickname_line else ""
        weekly_goal = goal_line.split(":")[-1].strip() if goal_line else ""

        return nickname, weekly_goal, "βœ… Loaded profile from memory."


    
    def generate_roadmap(goal, difficulty, pc, pine_index, client):
        # This function would use the RAG system to generate a roadmap
        # For now, return a placeholder
        steps = [
            "Learn Python Basics",
            "Understand Data Structures & Algorithms",
            "Master SQL",
            "Explore Machine Learning Fundamentals",
            "Build a Portfolio Project",
            "Apply for Jobs"
        ]
        return render_text_roadmap(goal, steps)
        
    import matplotlib.pyplot as plt
    from modules.analysis import render_text_roadmap
    
    def generate_visual_roadmap(goal, steps):
        text_roadmap = render_text_roadmap(goal, steps, completed_tasks)
        print(text_roadmap)  # Optional: for debugging/logging
        fig, ax = plt.subplots()
        ax.barh(range(len(steps)), [1] * len(steps), tick_label=list(reversed(steps)))
        ax.set_title(f"Visual Roadmap for {goal}")
        ax.invert_yaxis()  # So Step 1 is at the top
        return fig



app.launch(debug=True)