Danial7 commited on
Commit
f6dde4f
·
verified ·
1 Parent(s): 96a6e08

Update utils/suggestions.py

Browse files
Files changed (1) hide show
  1. utils/suggestions.py +28 -18
utils/suggestions.py CHANGED
@@ -1,36 +1,46 @@
1
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
- import torch
3
 
4
- # Load once at start
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
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True).to(model.device)
10
- with torch.no_grad():
11
- outputs = model.generate(**inputs, max_new_tokens=256)
12
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def get_certification_suggestions(text: str) -> str:
15
- prompt = f"Suggest relevant professional certifications based on this CV:\n{text}"
16
  return call_llm(prompt)
17
 
18
  def get_higher_education_suggestions(text: str) -> str:
19
- prompt = f"Suggest suitable higher education programs based on this CV:\n{text}"
20
  return call_llm(prompt)
21
 
22
  def get_visa_recommendations(text: str) -> str:
23
- prompt = f"Suggest top work or study visa opportunities for this CV:\n{text}"
24
  return call_llm(prompt)
25
 
26
  def get_career_advice(text: str) -> str:
27
- prompt = f"Act like a professional career counselor. Give detailed advice based on this CV:\n{text}"
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", # You can extract better keywords later
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"