Spaces:
Sleeping
Sleeping
Update utils/suggestions.py
Browse files- utils/suggestions.py +90 -22
utils/suggestions.py
CHANGED
|
@@ -1,38 +1,106 @@
|
|
| 1 |
-
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 7 |
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 8 |
|
| 9 |
-
def call_llm(prompt):
|
| 10 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
| 11 |
json_data = {
|
| 12 |
"inputs": prompt,
|
| 13 |
-
"parameters": {"max_new_tokens":
|
| 14 |
}
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
def get_certification_suggestions(text):
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
def get_higher_education_suggestions(text):
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
def get_visa_recommendations(text):
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
def get_career_advice(text):
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
def get_job_listings(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
return [f"{job['title']} - {job['location']['display_name']}" for job in response.json().get("results", [])]
|
| 38 |
return ["No jobs found"]
|
|
|
|
| 1 |
+
import os
|
| 2 |
import requests
|
| 3 |
+
|
| 4 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 5 |
+
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 6 |
+
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 7 |
+
|
| 8 |
+
def call_llm(prompt: str) -> str:
|
| 9 |
+
headers = {
|
| 10 |
+
"Authorization": f"Bearer {HF_API_KEY}",
|
| 11 |
+
"Content-Type": "application/json"
|
| 12 |
+
}
|
| 13 |
+
json_data = {
|
| 14 |
+
"inputs": prompt,
|
| 15 |
+
"parameters": {"max_new_tokens": 256},
|
| 16 |
+
}
|
| 17 |
+
# Change model URL if needed
|
| 18 |
+
url = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
| 19 |
+
response = requests.post(url, headers=headers, json=json_data)
|
| 20 |
+
if response.status_code != 200:
|
| 21 |
+
raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}")
|
| 22 |
+
return response.json()[0]['generated_text']
|
| 23 |
+
|
| 24 |
+
def get_certification_suggestions(text: str) -> str:
|
| 25 |
+
prompt = f"Suggest professional certifications based on this CV: {text}"
|
| 26 |
+
return call_llm(prompt)
|
| 27 |
+
|
| 28 |
+
def get_higher_education_suggestions(text: str) -> str:
|
| 29 |
+
prompt = f"Suggest suitable higher education programs based on this CV: {text}"
|
| 30 |
+
return call_llm(prompt)
|
| 31 |
+
|
| 32 |
+
def get_visa_recommendations(text: str) -> str:
|
| 33 |
+
prompt = f"Suggest visa opportunities in top countries based on this CV: {text}"
|
| 34 |
+
return call_llm(prompt)
|
| 35 |
+
|
| 36 |
+
def get_career_advice(text: str) -> str:
|
| 37 |
+
prompt = f"Act like a career counselor. Give detailed personalized advice for this CV: {text}"
|
| 38 |
+
return call_llm(prompt)
|
| 39 |
+
|
| 40 |
+
def get_job_listings(text: str):
|
| 41 |
+
headers = {
|
| 42 |
+
"X-RapidAPI-Key": ADZUNA_API_KEY
|
| 43 |
+
}
|
| 44 |
+
params = {
|
| 45 |
+
"app_id": ADZUNA_APP_ID,
|
| 46 |
+
"what": "engineer",
|
| 47 |
+
"results_per_page": 5,
|
| 48 |
+
}
|
| 49 |
+
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
| 50 |
+
res = requests.get(url, headers=headers, params=params)
|
| 51 |
+
if res.status_code == 200:
|
| 52 |
+
return [f"{job['title']} - {job['location']['display_name']}" for job in res.json()["results"]]
|
| 53 |
+
return ["No jobs found"]
|
| 54 |
import os
|
| 55 |
+
import requests
|
| 56 |
|
| 57 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 58 |
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 59 |
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 60 |
|
| 61 |
+
def call_llm(prompt: str) -> str:
|
| 62 |
+
headers = {
|
| 63 |
+
"Authorization": f"Bearer {HF_API_KEY}",
|
| 64 |
+
"Content-Type": "application/json"
|
| 65 |
+
}
|
| 66 |
json_data = {
|
| 67 |
"inputs": prompt,
|
| 68 |
+
"parameters": {"max_new_tokens": 256},
|
| 69 |
}
|
| 70 |
+
# Change model URL if needed
|
| 71 |
+
url = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
| 72 |
+
response = requests.post(url, headers=headers, json=json_data)
|
| 73 |
+
if response.status_code != 200:
|
| 74 |
+
raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}")
|
| 75 |
+
return response.json()[0]['generated_text']
|
| 76 |
|
| 77 |
+
def get_certification_suggestions(text: str) -> str:
|
| 78 |
+
prompt = f"Suggest professional certifications based on this CV: {text}"
|
| 79 |
+
return call_llm(prompt)
|
| 80 |
|
| 81 |
+
def get_higher_education_suggestions(text: str) -> str:
|
| 82 |
+
prompt = f"Suggest suitable higher education programs based on this CV: {text}"
|
| 83 |
+
return call_llm(prompt)
|
| 84 |
|
| 85 |
+
def get_visa_recommendations(text: str) -> str:
|
| 86 |
+
prompt = f"Suggest visa opportunities in top countries based on this CV: {text}"
|
| 87 |
+
return call_llm(prompt)
|
| 88 |
|
| 89 |
+
def get_career_advice(text: str) -> str:
|
| 90 |
+
prompt = f"Act like a career counselor. Give detailed personalized advice for this CV: {text}"
|
| 91 |
+
return call_llm(prompt)
|
| 92 |
|
| 93 |
+
def get_job_listings(text: str):
|
| 94 |
+
headers = {
|
| 95 |
+
"X-RapidAPI-Key": ADZUNA_API_KEY
|
| 96 |
+
}
|
| 97 |
+
params = {
|
| 98 |
+
"app_id": ADZUNA_APP_ID,
|
| 99 |
+
"what": "engineer",
|
| 100 |
+
"results_per_page": 5,
|
| 101 |
+
}
|
| 102 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
| 103 |
+
res = requests.get(url, headers=headers, params=params)
|
| 104 |
+
if res.status_code == 200:
|
| 105 |
+
return [f"{job['title']} - {job['location']['display_name']}" for job in res.json()["results"]]
|
|
|
|
| 106 |
return ["No jobs found"]
|