Spaces:
Build error
Build error
Update utils/suggestions.py
Browse files- utils/suggestions.py +28 -18
utils/suggestions.py
CHANGED
|
@@ -1,36 +1,46 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
tokenizer = AutoTokenizer.from_pretrained("MBZUAI/LaMini-Flan-T5-783M")
|
| 6 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("MBZUAI/LaMini-Flan-T5-783M")
|
| 7 |
|
|
|
|
| 8 |
def call_llm(prompt: str) -> str:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def get_certification_suggestions(text: str) -> str:
|
| 15 |
-
prompt = f"Suggest
|
| 16 |
return call_llm(prompt)
|
| 17 |
|
| 18 |
def get_higher_education_suggestions(text: str) -> str:
|
| 19 |
-
prompt = f"
|
| 20 |
return call_llm(prompt)
|
| 21 |
|
| 22 |
def get_visa_recommendations(text: str) -> str:
|
| 23 |
-
prompt = f"Suggest
|
| 24 |
return call_llm(prompt)
|
| 25 |
|
| 26 |
def get_career_advice(text: str) -> str:
|
| 27 |
-
prompt = f"Act
|
| 28 |
return call_llm(prompt)
|
| 29 |
|
| 30 |
-
# ---- Job listings (Adzuna) ----
|
| 31 |
-
import os
|
| 32 |
-
import requests
|
| 33 |
-
|
| 34 |
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 35 |
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 36 |
|
|
@@ -40,7 +50,7 @@ def get_job_listings(text: str):
|
|
| 40 |
}
|
| 41 |
params = {
|
| 42 |
"app_id": ADZUNA_APP_ID,
|
| 43 |
-
"what": "engineer", #
|
| 44 |
"results_per_page": 5,
|
| 45 |
}
|
| 46 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
HF_API_KEY = os.getenv("HF_API_KEY") # Store your HF token in Secrets
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Lightweight LLM via Hugging Face Inference API
|
| 7 |
def call_llm(prompt: str) -> str:
|
| 8 |
+
headers = {
|
| 9 |
+
"Authorization": f"Bearer {HF_API_KEY}",
|
| 10 |
+
"Content-Type": "application/json"
|
| 11 |
+
}
|
| 12 |
+
json_data = {
|
| 13 |
+
"inputs": prompt,
|
| 14 |
+
"parameters": {
|
| 15 |
+
"max_new_tokens": 256,
|
| 16 |
+
"temperature": 0.7
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
|
| 20 |
+
response = requests.post(url, headers=headers, json=json_data)
|
| 21 |
+
|
| 22 |
+
if response.status_code != 200:
|
| 23 |
+
raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}")
|
| 24 |
+
|
| 25 |
+
return response.json()[0]["generated_text"]
|
| 26 |
|
| 27 |
def get_certification_suggestions(text: str) -> str:
|
| 28 |
+
prompt = f"Suggest professional certifications for this candidate:\n{text}"
|
| 29 |
return call_llm(prompt)
|
| 30 |
|
| 31 |
def get_higher_education_suggestions(text: str) -> str:
|
| 32 |
+
prompt = f"Based on this resume, recommend suitable higher education programs:\n{text}"
|
| 33 |
return call_llm(prompt)
|
| 34 |
|
| 35 |
def get_visa_recommendations(text: str) -> str:
|
| 36 |
+
prompt = f"Suggest suitable visa options for this candidate to work or study abroad:\n{text}"
|
| 37 |
return call_llm(prompt)
|
| 38 |
|
| 39 |
def get_career_advice(text: str) -> str:
|
| 40 |
+
prompt = f"Act as a career counselor and give personalized guidance for this resume:\n{text}"
|
| 41 |
return call_llm(prompt)
|
| 42 |
|
| 43 |
+
# ---- Job listings (Adzuna API) ----
|
|
|
|
|
|
|
|
|
|
| 44 |
ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID")
|
| 45 |
ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY")
|
| 46 |
|
|
|
|
| 50 |
}
|
| 51 |
params = {
|
| 52 |
"app_id": ADZUNA_APP_ID,
|
| 53 |
+
"what": "engineer", # Optional: extract job keyword from text
|
| 54 |
"results_per_page": 5,
|
| 55 |
}
|
| 56 |
url = "https://api.adzuna.com/v1/api/jobs/us/search/1"
|