rivapereira123 commited on
Commit
0e43481
ยท
verified ยท
1 Parent(s): 2ce5428

Update modules/analysis.py

Browse files
Files changed (1) hide show
  1. modules/analysis.py +105 -0
modules/analysis.py CHANGED
@@ -5,6 +5,111 @@ import requests
5
  import time
6
  import os
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def render_text_roadmap(goal, steps, completed_tasks=None):
10
  if completed_tasks is None:
 
5
  import time
6
  import os
7
 
8
+ #----
9
+ import openai
10
+ import os
11
+
12
+ # Main function to combine static feedback and GPT-based feedback
13
+ def analyze_linkedin_profile(row):
14
+ feedback = []
15
+
16
+ # Call the existing static feedback functions (reuse your original functions)
17
+
18
+ # Static advice from the name and headline section
19
+ name_headline_feedback, name_headline_debug = clean_name_headline_section(row.get("headline", ""))
20
+ feedback.append(f"### ๐Ÿงพ Name & Headline Feedback\n{name_headline_feedback}")
21
+ feedback.append(f"<details><summary>Debug</summary>\n{name_headline_debug}\n</details>")
22
+
23
+ # Static advice for the about section
24
+ about_feedback, about_debug = clean_about_section(row.get("about", ""))
25
+ feedback.append(f"### ๐Ÿ“˜ About Section\n{about_feedback}")
26
+ feedback.append(f"<details><summary>Debug</summary>\n{about_debug}\n</details>")
27
+
28
+ # Static advice for the experience section
29
+ experience_feedback, experience_debug, experience_skills = analyze_experience_section(row.get("experience", ""))
30
+ feedback.append(f"### ๐Ÿ’ผ Experience Section\n{experience_feedback}")
31
+ feedback.append(f"<details><summary>Debug</summary>\n{experience_debug}\n</details>")
32
+
33
+ # Static advice for the education section
34
+ education_feedback = analyze_education_section(row.get("education", ""))
35
+ feedback.append(f"### ๐ŸŽ“ Education Section\n{education_feedback}")
36
+
37
+ # Static advice for the skills section
38
+ skills_feedback, skills_debug = analyze_skills_section(row.get("skills", ""))
39
+ feedback.append(f"### ๐Ÿง  Skills Section\n{skills_feedback}")
40
+ feedback.append(f"<details><summary>Debug</summary>\n{skills_debug}\n</details>")
41
+
42
+ # Separator between static and dynamic feedback
43
+ feedback.append("\n---\n")
44
+
45
+ # Collect profile data for GPT-based analysis
46
+ profile_data = {
47
+ "fullName": row.get("fullName", ""),
48
+ "headline": row.get("headline", ""),
49
+ "about": row.get("about", ""),
50
+ "experience": row.get("experience", ""),
51
+ "education": row.get("education", ""),
52
+ "skills": row.get("skills", ""),
53
+ "career_goals": row.get("career_goals", "Data Science") # Default career goal if not provided
54
+ }
55
+
56
+ # Dynamic feedback via GPT (calling `analyze_linkedin_profile_enriched()` for in-depth analysis)
57
+ gpt_feedback = analyze_linkedin_profile_enriched(profile_data)
58
+ feedback.append("### ๐Ÿง  GPT-based Suggestions:\n")
59
+ feedback.append(gpt_feedback)
60
+
61
+ return "\n".join(feedback)
62
+
63
+
64
+ # Function to generate feedback using GPT (enriched suggestions for the entire profile)
65
+ def analyze_linkedin_profile_enriched(profile_data):
66
+ openai.api_key = os.getenv("OPENAI_API_KEY") # Ensure API key is securely loaded
67
+
68
+ # Prepare GPT prompt
69
+ prompt = f"""
70
+ Here is the LinkedIn profile data for {profile_data['fullName']}:
71
+ - Current Headline: {profile_data['headline']}
72
+ - Career Goals: {profile_data['career_goals']}
73
+ - About: {profile_data['about']}
74
+ - Experience: {profile_data['experience']}
75
+ - Education: {profile_data['education']}
76
+ - Skills: {profile_data['skills']}
77
+
78
+ Based on this, generate the following:
79
+ 1. Suggest 3 ways to improve the headline, focusing on including keywords, making it more compelling, and aligning with the user's career goals.
80
+ 2. Provide feedback on how the 'About' section can be expanded for better engagement.
81
+ 3. Review the experience section and suggest how to reword it for stronger impact, including achievements.
82
+ 4. Recommend adding missing skills or certifications.
83
+ """
84
+
85
+ # Request GPT for feedback
86
+ response = openai.Completion.create(
87
+ engine="text-davinci-003", # Can use GPT-4 if available
88
+ prompt=prompt,
89
+ max_tokens=500,
90
+ temperature=0.7
91
+ )
92
+
93
+ # Return GPT-generated feedback
94
+ return response.choices[0].text.strip()
95
+
96
+
97
+ # Example usage with a mock profile
98
+ example_profile = {
99
+ "fullName": "John Doe",
100
+ "headline": "Software Engineer at XYZ",
101
+ "about": "Passionate about software development, machine learning, and data science.",
102
+ "experience": "Software Engineer at XYZ Company",
103
+ "education": "BSc in Computer Science from University Y",
104
+ "skills": "Python, Java, C++",
105
+ "career_goals": "Data Scientist specializing in machine learning"
106
+ }
107
+
108
+ profile_analysis = analyze_linkedin_profile(example_profile)
109
+ print(profile_analysis)
110
+
111
+
112
+ #------------
113
 
114
  def render_text_roadmap(goal, steps, completed_tasks=None):
115
  if completed_tasks is None: