Spaces:
Sleeping
Sleeping
| import requests | |
| import os | |
| HF_API_KEY = os.getenv("HF_API_KEY") | |
| HF_MODEL = "google/flan-t5-small" | |
| HF_API_URL = f"https://api-inference.huggingface.co/models/{HF_MODEL}" | |
| HEADERS = { | |
| "Authorization": f"Bearer {HF_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| def call_llm(prompt: str) -> str: | |
| response = requests.post( | |
| HF_API_URL, | |
| headers=HEADERS, | |
| json={"inputs": prompt} | |
| ) | |
| if response.status_code != 200: | |
| raise Exception(f"Hugging Face API Error {response.status_code}: {response.text}") | |
| try: | |
| return response.json()[0]["generated_text"] | |
| except Exception as e: | |
| raise Exception(f"Error parsing Hugging Face response: {response.text}") | |
| def get_certification_suggestions(text: str) -> str: | |
| prompt = f"Suggest 5 certifications for this resume: {text}" | |
| return call_llm(prompt) | |
| def get_higher_education_suggestions(text: str) -> str: | |
| prompt = f"Suggest higher education programs for this resume: {text}" | |
| return call_llm(prompt) | |
| def get_visa_recommendations(text: str) -> str: | |
| prompt = f"Suggest visa opportunities in top countries based on this resume: {text}" | |
| return call_llm(prompt) | |
| def get_career_advice(text: str) -> str: | |
| prompt = f"Give career counseling advice based on this resume: {text}" | |
| return call_llm(prompt) | |
| def get_job_listings(text: str): | |
| ADZUNA_API_KEY = os.getenv("ADZUNA_API_KEY") | |
| ADZUNA_APP_ID = os.getenv("ADZUNA_APP_ID") | |
| if not ADZUNA_API_KEY or not ADZUNA_APP_ID: | |
| return ["Adzuna API credentials missing."] | |
| params = { | |
| "app_id": ADZUNA_APP_ID, | |
| "app_key": ADZUNA_API_KEY, | |
| "what": "engineer", | |
| "results_per_page": 5 | |
| } | |
| url = "https://api.adzuna.com/v1/api/jobs/us/search/1" | |
| response = requests.get(url, params=params) | |
| if response.status_code == 200: | |
| try: | |
| jobs = response.json()["results"] | |
| return [f"{j['title']} - {j['location']['display_name']}" for j in jobs] | |
| except: | |
| return ["Error parsing Adzuna job data."] | |
| return [f"Job API Error {response.status_code}: {response.text}"] | |