Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,49 +3,38 @@ from fastmcp import FastMCP
|
|
| 3 |
import logging
|
| 4 |
import requests
|
| 5 |
|
| 6 |
-
# Set up logging
|
| 7 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
-
# Initialize FastMCP server
|
| 11 |
mcp = FastMCP("Jobicy Canada Remote Jobs Agent")
|
| 12 |
|
| 13 |
@mcp.tool(name="search_jobs")
|
| 14 |
def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None) -> dict:
|
| 15 |
-
"""
|
| 16 |
-
Use Jobicy's Remote Jobs API to search remote jobs in Canada.
|
| 17 |
-
|
| 18 |
-
Args:
|
| 19 |
-
query (str): Keyword or job title to search for.
|
| 20 |
-
location (str): Location filter (ignored since it's remote, but kept for API compatibility).
|
| 21 |
-
limit (int): Max number of jobs to return (max 50).
|
| 22 |
-
salary (str): Ignored (for compatibility).
|
| 23 |
-
job_type (str): Ignored (for compatibility).
|
| 24 |
-
|
| 25 |
-
Returns:
|
| 26 |
-
dict: Contains 'jobs' list or 'error' message.
|
| 27 |
-
"""
|
| 28 |
base_url = "https://jobicy.com/api/v2/remote-jobs"
|
| 29 |
-
params = {
|
| 30 |
-
"count": min(max(1, limit), 50), # ensure between 1 and 50
|
| 31 |
-
"geo": "canada",
|
| 32 |
-
}
|
| 33 |
if query.strip():
|
| 34 |
params["tag"] = query.strip()
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
logger.info(f"Requesting Jobicy API with params: {params}")
|
| 38 |
-
response = requests.get(base_url, params=params, timeout=10)
|
| 39 |
response.raise_for_status()
|
| 40 |
data = response.json()
|
| 41 |
|
| 42 |
jobs_raw = data.get("jobs", [])
|
| 43 |
jobs = []
|
| 44 |
-
for job in jobs_raw:
|
| 45 |
salary_min = job.get("annualSalaryMin")
|
| 46 |
salary_max = job.get("annualSalaryMax")
|
| 47 |
currency = job.get("salaryCurrency", "")
|
| 48 |
-
|
|
|
|
| 49 |
salary_str = f"{salary_min} - {salary_max} {currency}".strip()
|
| 50 |
else:
|
| 51 |
salary_str = "Not specified"
|
|
@@ -76,9 +65,6 @@ def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = N
|
|
| 76 |
return {"error": f"Unexpected error: {str(e)}"}
|
| 77 |
|
| 78 |
def search_jobs_ui(query, location, limit=10, salary=None, job_type=None):
|
| 79 |
-
"""
|
| 80 |
-
Gradio UI function for displaying job search results.
|
| 81 |
-
"""
|
| 82 |
if not query:
|
| 83 |
return "❌ Please provide a job title or keyword to search for."
|
| 84 |
|
|
@@ -105,7 +91,6 @@ def search_jobs_ui(query, location, limit=10, salary=None, job_type=None):
|
|
| 105 |
|
| 106 |
return output
|
| 107 |
|
| 108 |
-
# Gradio Interface
|
| 109 |
app = gr.Interface(
|
| 110 |
fn=search_jobs_ui,
|
| 111 |
inputs=[
|
|
|
|
| 3 |
import logging
|
| 4 |
import requests
|
| 5 |
|
|
|
|
| 6 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
|
|
|
| 9 |
mcp = FastMCP("Jobicy Canada Remote Jobs Agent")
|
| 10 |
|
| 11 |
@mcp.tool(name="search_jobs")
|
| 12 |
def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
base_url = "https://jobicy.com/api/v2/remote-jobs"
|
| 14 |
+
params = {}
|
|
|
|
|
|
|
|
|
|
| 15 |
if query.strip():
|
| 16 |
params["tag"] = query.strip()
|
| 17 |
|
| 18 |
+
headers = {
|
| 19 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
| 20 |
+
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
| 21 |
+
"Chrome/126.0.0.0 Safari/537.36"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
try:
|
| 25 |
logger.info(f"Requesting Jobicy API with params: {params}")
|
| 26 |
+
response = requests.get(base_url, params=params, headers=headers, timeout=10)
|
| 27 |
response.raise_for_status()
|
| 28 |
data = response.json()
|
| 29 |
|
| 30 |
jobs_raw = data.get("jobs", [])
|
| 31 |
jobs = []
|
| 32 |
+
for job in jobs_raw[:limit]:
|
| 33 |
salary_min = job.get("annualSalaryMin")
|
| 34 |
salary_max = job.get("annualSalaryMax")
|
| 35 |
currency = job.get("salaryCurrency", "")
|
| 36 |
+
# 判斷salary有無實際數值(排除0或None)
|
| 37 |
+
if salary_min and salary_min != 0 and salary_max and salary_max != 0:
|
| 38 |
salary_str = f"{salary_min} - {salary_max} {currency}".strip()
|
| 39 |
else:
|
| 40 |
salary_str = "Not specified"
|
|
|
|
| 65 |
return {"error": f"Unexpected error: {str(e)}"}
|
| 66 |
|
| 67 |
def search_jobs_ui(query, location, limit=10, salary=None, job_type=None):
|
|
|
|
|
|
|
|
|
|
| 68 |
if not query:
|
| 69 |
return "❌ Please provide a job title or keyword to search for."
|
| 70 |
|
|
|
|
| 91 |
|
| 92 |
return output
|
| 93 |
|
|
|
|
| 94 |
app = gr.Interface(
|
| 95 |
fn=search_jobs_ui,
|
| 96 |
inputs=[
|