OppaAI commited on
Commit
10adf53
·
verified ·
1 Parent(s): dadf535

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -44
app.py CHANGED
@@ -8,52 +8,41 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
8
  logger = logging.getLogger(__name__)
9
  mcp = FastMCP("Jobicy Remote Jobs Agent")
10
 
11
- # Jobicy 官方欄位選項
12
- JOB_CATEGORIES = [
13
- "", "Business & Management", "Content & Editorial", "Customer Service",
14
- "Creative & Design", "DevOps & SysAdmin", "Software Engineering",
15
- "Finance & Accounting", "HR & Recruiting", "Product & Operations",
16
- "Programming", "Sales & Marketing"
17
- ]
18
 
19
- JOB_TYPES = [
20
- "", "Remote Full Time Jobs", "Remote Part Time Jobs", "Remote Contract Jobs"
21
- ]
22
 
23
- COMPANY_INDUSTRIES = [
24
- "", "Technology", "Finance & Accounting", "Health, Wellness & Fitness",
25
- "Internet & Online Media"
26
- ]
27
 
28
- COUNTRY_CHOICES = [
29
- "Anywhere", "usa", "canada", "uk", "europe", "latam", "apac"
30
- ]
31
 
32
 
33
  @mcp.tool(name="search_jobs")
34
- def search_jobs_tool(
35
- category: str = "",
36
- job_type: str = "",
37
- industry: str = "",
38
- country: str = "",
39
- limit: int = 20
40
- ) -> dict:
41
  """
42
- Search for remote jobs from the Jobicy API using optional filters.
43
 
44
  Args:
45
- category (str): Job Category (e.g., "Software Engineering").
46
- job_type (str): Job Type (e.g., "Remote Full Time Jobs").
47
- industry (str): Company Industry (e.g., "Technology").
48
- country (str): Country or region (e.g., "canada", "uk", or "Anywhere").
49
- limit (int): Maximum number of job results to return (1–200).
50
 
51
  Returns:
52
- dict: A dictionary containing a list of jobs under the "jobs" key or an error message under "error".
53
  """
54
- base_url = "https://jobicy.com/api/v2/remote-jobs"
55
  params = {"count": max(1, min(limit, 200))}
56
-
57
  if category:
58
  params["industry"] = category.lower().replace(" & ", "-").replace(" ", "-")
59
  if job_type:
@@ -63,15 +52,15 @@ def search_jobs_tool(
63
  if country and country.lower() != "anywhere":
64
  params["geo"] = country.lower()
65
 
66
- logger.info(f"Requesting Jobicy with params: {params}")
67
  try:
68
- resp = requests.get(base_url, params=params, headers={"User-Agent": "Mozilla/5.0"}, timeout=10)
69
  resp.raise_for_status()
70
  jobs_raw = resp.json().get("jobs", [])
71
  except Exception as e:
72
  return {"error": f"Fetch error: {e}"}
73
 
74
- def format_job(j):
75
  posted = j.get("pubDate", "")[:10]
76
  sal_min = j.get("annualSalaryMin")
77
  sal_max = j.get("annualSalaryMax")
@@ -87,19 +76,16 @@ def search_jobs_tool(
87
  }
88
 
89
  sorted_jobs = sorted(jobs_raw, key=lambda x: x.get("pubDate", ""), reverse=True)[:params["count"]]
90
- return {"jobs": [format_job(j) for j in sorted_jobs]}
91
 
92
 
93
  def search_jobs_ui(category, job_type, industry, country, limit):
94
- """
95
- Format and display search results as Markdown for the Gradio interface.
96
- """
97
  res = search_jobs_tool(category, job_type, industry, country, limit)
98
  if "error" in res:
99
  return f"❌ {res['error']}"
100
  if not res["jobs"]:
101
- return "No jobs found."
102
-
103
  md = "# Remote Jobs Results\n\n"
104
  for i, j in enumerate(res["jobs"], 1):
105
  md += (
@@ -113,7 +99,6 @@ def search_jobs_ui(category, job_type, industry, country, limit):
113
  return md
114
 
115
 
116
- # 🎨 Gradio UI Components
117
  app = gr.Interface(
118
  fn=search_jobs_ui,
119
  inputs=[
@@ -125,7 +110,7 @@ app = gr.Interface(
125
  ],
126
  outputs=gr.Markdown(),
127
  title="Jobicy Remote Job Search",
128
- description="Search remote jobs using filters from Jobicy: job category, job type, company industry, and region.",
129
  theme="huggingface"
130
  )
131
 
 
8
  logger = logging.getLogger(__name__)
9
  mcp = FastMCP("Jobicy Remote Jobs Agent")
10
 
11
+ # 🧩 官方选项
12
+ JOB_CATEGORIES = ["", "Business & Management", "Content & Editorial", "Customer Service",
13
+ "Creative & Design", "DevOps & SysAdmin", "Software Engineering",
14
+ "Finance & Accounting", "HR & Recruiting", "Product & Operations",
15
+ "Programming", "Sales & Marketing"]
 
 
16
 
17
+ JOB_TYPES = ["", "Remote Full Time Jobs", "Remote Part Time Jobs", "Remote Contract Jobs"]
 
 
18
 
19
+ COMPANY_INDUSTRIES = ["", "Technology", "Finance & Accounting", "Health, Wellness & Fitness",
20
+ "Internet & Online Media"]
 
 
21
 
22
+ COUNTRY_CHOICES = ["Anywhere", "usa", "canada", "uk", "europe", "latam", "apac"]
 
 
23
 
24
 
25
  @mcp.tool(name="search_jobs")
26
+ def search_jobs_tool(category: str = "",
27
+ job_type: str = "",
28
+ industry: str = "",
29
+ country: str = "",
30
+ limit: int = 20) -> dict:
 
 
31
  """
32
+ Search remote jobs via Jobicy API, supports filters.
33
 
34
  Args:
35
+ category (str): A Jobicy job category.
36
+ job_type (str): One of Job Types.
37
+ industry (str): Company industry filter.
38
+ country (str): Region filter (e.g., usa, canada, ...).
39
+ limit (int): Number of results (1–200).
40
 
41
  Returns:
42
+ dict: {"jobs": [...]} or {"error": "..." }
43
  """
44
+ base = "https://jobicy.com/api/v2/remote-jobs"
45
  params = {"count": max(1, min(limit, 200))}
 
46
  if category:
47
  params["industry"] = category.lower().replace(" & ", "-").replace(" ", "-")
48
  if job_type:
 
52
  if country and country.lower() != "anywhere":
53
  params["geo"] = country.lower()
54
 
55
+ logger.info(f"Requesting Jobicy API with params: {params}")
56
  try:
57
+ resp = requests.get(base, params=params, headers={"User-Agent": "Mozilla/5.0"}, timeout=10)
58
  resp.raise_for_status()
59
  jobs_raw = resp.json().get("jobs", [])
60
  except Exception as e:
61
  return {"error": f"Fetch error: {e}"}
62
 
63
+ def fmt(j):
64
  posted = j.get("pubDate", "")[:10]
65
  sal_min = j.get("annualSalaryMin")
66
  sal_max = j.get("annualSalaryMax")
 
76
  }
77
 
78
  sorted_jobs = sorted(jobs_raw, key=lambda x: x.get("pubDate", ""), reverse=True)[:params["count"]]
79
+ return {"jobs": [fmt(j) for j in sorted_jobs]}
80
 
81
 
82
  def search_jobs_ui(category, job_type, industry, country, limit):
 
 
 
83
  res = search_jobs_tool(category, job_type, industry, country, limit)
84
  if "error" in res:
85
  return f"❌ {res['error']}"
86
  if not res["jobs"]:
87
+ return "No jobs found with these filters."
88
+
89
  md = "# Remote Jobs Results\n\n"
90
  for i, j in enumerate(res["jobs"], 1):
91
  md += (
 
99
  return md
100
 
101
 
 
102
  app = gr.Interface(
103
  fn=search_jobs_ui,
104
  inputs=[
 
110
  ],
111
  outputs=gr.Markdown(),
112
  title="Jobicy Remote Job Search",
113
+ description="Filter remote jobs by category, type, industry, and region (as per Jobicy official options), results sorted by recent postings.",
114
  theme="huggingface"
115
  )
116