Spaces:
Sleeping
Sleeping
Commit
·
ea93bfe
1
Parent(s):
36315d5
fix & cleanup
Browse files- JobDescription.py +37 -9
- ai_manager.py +5 -21
- app.py +1 -1
JobDescription.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from datetime import datetime
|
|
|
2 |
|
3 |
class JobDescription:
|
4 |
def __init__(self, title, company, url, company_url, job_description):
|
@@ -9,17 +10,17 @@ class JobDescription:
|
|
9 |
self.published_at = None # Initialize to None or a default value
|
10 |
self.job_description = job_description
|
11 |
self.organization_logo_url = ""
|
12 |
-
self.ai_result =
|
13 |
self.salary_range = ""
|
14 |
|
15 |
-
def format_should_apply(self, should_apply):
|
16 |
if should_apply:
|
17 |
return "⭐ "
|
18 |
return ""
|
19 |
|
20 |
def get_salary(self):
|
21 |
-
if self.ai_result
|
22 |
-
return self.ai_result
|
23 |
return self.salary_range
|
24 |
|
25 |
def format_str_or_list(self, input):
|
@@ -43,14 +44,41 @@ class JobDescription:
|
|
43 |
result.append("<div class='logobox'><img src='{}' alt='No logo' class='logo'></div>".format(self.organization_logo_url))
|
44 |
#text part
|
45 |
result.append("<div style='flex: 5; padding: 10px;'>")
|
46 |
-
result.append("<h3><a href='{}' target='_blank'>{}{}</a></h3>".format(self.url, self.format_should_apply(self.ai_result
|
47 |
-
result.append("<p><a href='{}' target='_blank'>{}</a> ({}) - published at {}</p>".format(self.company_url, self.company, self.ai_result
|
48 |
-
result.append("<p><h4>Position: {}</h4>{}</p>".format(self.get_salary(), self.format_str_or_list(self.ai_result
|
49 |
-
result.append("<p><h4>Language:</h4>{}</p>".format(self.format_str_or_list(self.ai_result
|
50 |
-
result.append("<p><h4>Experience:</h4>{}</p>".format(self.format_str_or_list(self.ai_result
|
51 |
#close text part
|
52 |
result.append("</div>")
|
53 |
#close box
|
54 |
result.append("</div>")
|
55 |
return " ".join(result)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from datetime import datetime
|
2 |
+
import json
|
3 |
|
4 |
class JobDescription:
|
5 |
def __init__(self, title, company, url, company_url, job_description):
|
|
|
10 |
self.published_at = None # Initialize to None or a default value
|
11 |
self.job_description = job_description
|
12 |
self.organization_logo_url = ""
|
13 |
+
self.ai_result : AIInformation = None
|
14 |
self.salary_range = ""
|
15 |
|
16 |
+
def format_should_apply(self, should_apply : bool):
|
17 |
if should_apply:
|
18 |
return "⭐ "
|
19 |
return ""
|
20 |
|
21 |
def get_salary(self):
|
22 |
+
if self.ai_result.salary_range.lower() not in ["", "unknown"]:
|
23 |
+
return self.ai_result.salary_range
|
24 |
return self.salary_range
|
25 |
|
26 |
def format_str_or_list(self, input):
|
|
|
44 |
result.append("<div class='logobox'><img src='{}' alt='No logo' class='logo'></div>".format(self.organization_logo_url))
|
45 |
#text part
|
46 |
result.append("<div style='flex: 5; padding: 10px;'>")
|
47 |
+
result.append("<h3><a href='{}' target='_blank'>{}{}</a></h3>".format(self.url, self.format_should_apply(self.ai_result.should_apply), self.title))
|
48 |
+
result.append("<p><a href='{}' target='_blank'>{}</a> ({}) - published at {}</p>".format(self.company_url, self.company, self.ai_result.company_description, self.format_posted_date(self.published_at)))
|
49 |
+
result.append("<p><h4>Position: {}</h4>{}</p>".format(self.get_salary(), self.format_str_or_list(self.ai_result.position_summary)))
|
50 |
+
result.append("<p><h4>Language:</h4>{}</p>".format(self.format_str_or_list(self.ai_result.language_requirements)))
|
51 |
+
result.append("<p><h4>Experience:</h4>{}</p>".format(self.format_str_or_list(self.ai_result.experience_requirements)))
|
52 |
#close text part
|
53 |
result.append("</div>")
|
54 |
#close box
|
55 |
result.append("</div>")
|
56 |
return " ".join(result)
|
57 |
|
58 |
+
class AIInformation:
|
59 |
+
def __init__(self, json_dump):
|
60 |
+
obj = json.loads(json_dump)
|
61 |
+
print(obj)
|
62 |
+
#Check result
|
63 |
+
if not "company_description" in obj:
|
64 |
+
obj["company_description"] = ""
|
65 |
+
if not "position_summary" in obj:
|
66 |
+
obj["position_summary"] = ""
|
67 |
+
if not "language_requirements" in obj:
|
68 |
+
obj["language_requirements"] = ""
|
69 |
+
if not "experience_requirements" in obj:
|
70 |
+
obj["experience_requirements"] = ""
|
71 |
+
if not "is_an_internship" in obj:
|
72 |
+
obj["is_an_internship"] = False
|
73 |
+
if not "salary_range" in obj:
|
74 |
+
obj["salary_range"] = ""
|
75 |
+
if not "should_apply" in obj:
|
76 |
+
obj["should_apply"] = True
|
77 |
+
|
78 |
+
self.company_description = obj["company_description"]
|
79 |
+
self.position_summary = obj["position_summary"]
|
80 |
+
self.language_requirements = obj["language_requirements"]
|
81 |
+
self.experience_requirements = obj["experience_requirements"]
|
82 |
+
self.is_an_internship = obj["is_an_internship"]
|
83 |
+
self.salary_range = obj["salary_range"]
|
84 |
+
self.should_apply : bool = obj["should_apply"]
|
ai_manager.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from mistralai import Mistral, SDKError
|
2 |
from time import sleep
|
|
|
3 |
import json
|
4 |
import os
|
5 |
|
@@ -41,7 +42,7 @@ def _call_ai(prompt, json_mode):
|
|
41 |
|
42 |
return chat_response.choices[0].message.content
|
43 |
|
44 |
-
def get_extra_information(company, offer):
|
45 |
try:
|
46 |
return _get_extra_information(company, offer)
|
47 |
except json.decoder.JSONDecodeError as e:
|
@@ -51,7 +52,7 @@ def get_extra_information(company, offer):
|
|
51 |
# Throw the error if it's not an SDKError
|
52 |
raise
|
53 |
|
54 |
-
def _get_extra_information(company, offer):
|
55 |
prompt = """This is a job offer from the company '{}', make a JSON with this information:
|
56 |
- company_description (string): a description of the company in less than 15 words.
|
57 |
- position_summary (string): a summary of the role in 3 bullet points
|
@@ -77,22 +78,5 @@ Example:
|
|
77 |
Offer:
|
78 |
{}""".format(company, offer)
|
79 |
result = call_ai(prompt, True)
|
80 |
-
|
81 |
-
|
82 |
-
#Check result
|
83 |
-
if not "company_description" in obj:
|
84 |
-
obj["company_description"] = ""
|
85 |
-
if not "position_summary" in obj:
|
86 |
-
obj["position_summary"] = ""
|
87 |
-
if not "language_requirements" in obj:
|
88 |
-
obj["language_requirements"] = ""
|
89 |
-
if not "experience_requirements" in obj:
|
90 |
-
obj["experience_requirements"] = ""
|
91 |
-
if not "is_an_internship" in obj:
|
92 |
-
obj["is_an_internship"] = False
|
93 |
-
if not "salary_range" in obj:
|
94 |
-
obj["salary_range"] = ""
|
95 |
-
if not "should_apply" in obj:
|
96 |
-
obj["should_apply"] = True
|
97 |
-
|
98 |
-
return obj
|
|
|
1 |
from mistralai import Mistral, SDKError
|
2 |
from time import sleep
|
3 |
+
from JobDescription import AIInformation
|
4 |
import json
|
5 |
import os
|
6 |
|
|
|
42 |
|
43 |
return chat_response.choices[0].message.content
|
44 |
|
45 |
+
def get_extra_information(company, offer) -> AIInformation:
|
46 |
try:
|
47 |
return _get_extra_information(company, offer)
|
48 |
except json.decoder.JSONDecodeError as e:
|
|
|
52 |
# Throw the error if it's not an SDKError
|
53 |
raise
|
54 |
|
55 |
+
def _get_extra_information(company, offer) -> AIInformation:
|
56 |
prompt = """This is a job offer from the company '{}', make a JSON with this information:
|
57 |
- company_description (string): a description of the company in less than 15 words.
|
58 |
- position_summary (string): a summary of the role in 3 bullet points
|
|
|
78 |
Offer:
|
79 |
{}""".format(company, offer)
|
80 |
result = call_ai(prompt, True)
|
81 |
+
return AIInformation(json_dump=result)
|
82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -12,7 +12,7 @@ def html_format_page(jobs : List[JobDescription]):
|
|
12 |
result = ["<html><head><style>.job{display: flex;width:70%;margin: 5px auto;border: 1px solid;border-radius: 5px;}.logobox{flex: 1;display: flex;align-items: center;justify-content: center;}.logo{width:100px;height:100px}h4{margin: 2px;}</style></head><body>"]
|
13 |
if len(jobs) > 0:
|
14 |
for job in jobs:
|
15 |
-
if
|
16 |
result.append(job.to_html())
|
17 |
else:
|
18 |
result.append("No job found")
|
|
|
12 |
result = ["<html><head><style>.job{display: flex;width:70%;margin: 5px auto;border: 1px solid;border-radius: 5px;}.logobox{flex: 1;display: flex;align-items: center;justify-content: center;}.logo{width:100px;height:100px}h4{margin: 2px;}</style></head><body>"]
|
13 |
if len(jobs) > 0:
|
14 |
for job in jobs:
|
15 |
+
if job.ai_result.is_an_internship == False:
|
16 |
result.append(job.to_html())
|
17 |
else:
|
18 |
result.append("No job found")
|