Spaces:
Sleeping
Sleeping
Update utils/suggestions.py
Browse files- utils/suggestions.py +24 -23
utils/suggestions.py
CHANGED
|
@@ -2,10 +2,8 @@ import requests
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
HF_API_URL = "https://api-inference.huggingface.co/models/bigscience/T0pp"
|
| 9 |
|
| 10 |
HEADERS = {
|
| 11 |
"Authorization": f"Bearer {HF_API_KEY}",
|
|
@@ -13,45 +11,49 @@ HEADERS = {
|
|
| 13 |
}
|
| 14 |
|
| 15 |
def call_llm(prompt: str) -> str:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
if response.status_code != 200:
|
| 21 |
raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}")
|
| 22 |
|
| 23 |
try:
|
| 24 |
return response.json()[0]["generated_text"]
|
| 25 |
-
except
|
| 26 |
raise Exception(f"Error parsing Hugging Face response: {response.text}")
|
| 27 |
|
|
|
|
| 28 |
def get_certification_suggestions(text: str) -> str:
|
| 29 |
-
prompt = f"Suggest 5 professional certifications
|
| 30 |
return call_llm(prompt)
|
| 31 |
|
| 32 |
def get_higher_education_suggestions(text: str) -> str:
|
| 33 |
-
prompt = f"Suggest suitable higher education programs
|
| 34 |
return call_llm(prompt)
|
| 35 |
|
| 36 |
def get_visa_recommendations(text: str) -> str:
|
| 37 |
-
prompt = f"Suggest visa
|
| 38 |
return call_llm(prompt)
|
| 39 |
|
| 40 |
def get_career_advice(text: str) -> str:
|
| 41 |
-
prompt = f"
|
| 42 |
return call_llm(prompt)
|
| 43 |
|
|
|
|
| 44 |
def get_job_listings(text: str):
|
|
|
|
|
|
|
|
|
|
| 45 |
if not ADZUNA_API_KEY or not ADZUNA_APP_ID:
|
| 46 |
-
return ["Adzuna API credentials
|
| 47 |
-
|
| 48 |
-
keyword = "engineer" if "engineer" in text.lower() else "professional"
|
| 49 |
|
| 50 |
params = {
|
| 51 |
"app_id": ADZUNA_APP_ID,
|
| 52 |
"app_key": ADZUNA_API_KEY,
|
| 53 |
-
"what":
|
| 54 |
-
"results_per_page": 5
|
| 55 |
}
|
| 56 |
|
| 57 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
|
@@ -59,9 +61,8 @@ def get_job_listings(text: str):
|
|
| 59 |
|
| 60 |
if response.status_code == 200:
|
| 61 |
try:
|
| 62 |
-
|
| 63 |
-
return [f"{
|
| 64 |
except:
|
| 65 |
-
return ["Error parsing job data."]
|
| 66 |
-
|
| 67 |
-
return [f"Job API Error {response.status_code}: {response.text}"]
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 5 |
+
HF_MODEL = "mrm8488/t5-base-finetuned-question-generation-ap"
|
| 6 |
+
HF_API_URL = f"https://api-inference.huggingface.co/models/{HF_MODEL}"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
HEADERS = {
|
| 9 |
"Authorization": f"Bearer {HF_API_KEY}",
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
def call_llm(prompt: str) -> str:
|
| 14 |
+
response = requests.post(
|
| 15 |
+
HF_API_URL,
|
| 16 |
+
headers=HEADERS,
|
| 17 |
+
json={"inputs": prompt}
|
| 18 |
+
)
|
| 19 |
if response.status_code != 200:
|
| 20 |
raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}")
|
| 21 |
|
| 22 |
try:
|
| 23 |
return response.json()[0]["generated_text"]
|
| 24 |
+
except:
|
| 25 |
raise Exception(f"Error parsing Hugging Face response: {response.text}")
|
| 26 |
|
| 27 |
+
|
| 28 |
def get_certification_suggestions(text: str) -> str:
|
| 29 |
+
prompt = f"Suggest 5 professional certifications for this profile:\n{text}"
|
| 30 |
return call_llm(prompt)
|
| 31 |
|
| 32 |
def get_higher_education_suggestions(text: str) -> str:
|
| 33 |
+
prompt = f"Suggest suitable higher education programs for this profile:\n{text}"
|
| 34 |
return call_llm(prompt)
|
| 35 |
|
| 36 |
def get_visa_recommendations(text: str) -> str:
|
| 37 |
+
prompt = f"Suggest visa options in top countries for this CV:\n{text}"
|
| 38 |
return call_llm(prompt)
|
| 39 |
|
| 40 |
def get_career_advice(text: str) -> str:
|
| 41 |
+
prompt = f"Give career advice like a counselor for the following profile:\n{text}"
|
| 42 |
return call_llm(prompt)
|
| 43 |
|
| 44 |
+
|
| 45 |
def get_job_listings(text: str):
|
| 46 |
+
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 47 |
+
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 48 |
+
|
| 49 |
if not ADZUNA_API_KEY or not ADZUNA_APP_ID:
|
| 50 |
+
return ["Adzuna API credentials missing."]
|
|
|
|
|
|
|
| 51 |
|
| 52 |
params = {
|
| 53 |
"app_id": ADZUNA_APP_ID,
|
| 54 |
"app_key": ADZUNA_API_KEY,
|
| 55 |
+
"what": "engineer",
|
| 56 |
+
"results_per_page": 5
|
| 57 |
}
|
| 58 |
|
| 59 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
|
|
|
| 61 |
|
| 62 |
if response.status_code == 200:
|
| 63 |
try:
|
| 64 |
+
jobs = response.json()["results"]
|
| 65 |
+
return [f"{j['title']} - {j['location']['display_name']}" for j in jobs]
|
| 66 |
except:
|
| 67 |
+
return ["Error parsing Adzuna job data."]
|
| 68 |
+
return [f"Job API Error {response.status_code}: {response.text}"]
|
|
|