Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,34 +3,34 @@ import requests
|
|
| 3 |
from fastmcp import FastMCP
|
| 4 |
|
| 5 |
# Initialize FastMCP agent
|
| 6 |
-
mcp = FastMCP("
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@mcp.tool(name="search_jobs")
|
| 9 |
def search_jobs_tool(query: str, location: str, date_created: str = None, salary: str = None, job_type: str = None):
|
| 10 |
"""
|
| 11 |
-
Search jobs from
|
| 12 |
"""
|
| 13 |
-
url = "https://employers.indeed.com/api/v2/jobs"
|
| 14 |
params = {
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
"limit": 5,
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"jobType": job_type,
|
| 21 |
-
"sort": "DATECREATED",
|
| 22 |
-
"order": "DESC",
|
| 23 |
-
"statuses": "ACTIVE",
|
| 24 |
-
"fields": "title,id,company,location,url"
|
| 25 |
}
|
|
|
|
| 26 |
params = {k: v for k, v in params.items() if v}
|
| 27 |
|
| 28 |
headers = {
|
|
|
|
|
|
|
| 29 |
"Accept": "application/json"
|
| 30 |
}
|
| 31 |
|
| 32 |
try:
|
| 33 |
-
response = requests.get(
|
| 34 |
response.raise_for_status()
|
| 35 |
return response.json()
|
| 36 |
except requests.RequestException as e:
|
|
@@ -38,16 +38,17 @@ def search_jobs_tool(query: str, location: str, date_created: str = None, salary
|
|
| 38 |
|
| 39 |
def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 40 |
"""
|
| 41 |
-
UI handler for searching jobs using FastMCP +
|
| 42 |
"""
|
| 43 |
try:
|
| 44 |
-
# 直接調用工具函數,唔用 async client
|
| 45 |
result = search_jobs_tool(query, location, date_created, salary, job_type)
|
| 46 |
|
| 47 |
if "error" in result:
|
| 48 |
return f"❌ Error: {result['error']}"
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
if not jobs:
|
| 52 |
return "No jobs found for your search."
|
| 53 |
|
|
@@ -74,8 +75,8 @@ app = gr.Interface(
|
|
| 74 |
gr.Textbox(label="Job Type (optional: fulltime, parttime, contract)")
|
| 75 |
],
|
| 76 |
outputs="markdown",
|
| 77 |
-
title="
|
| 78 |
-
description="Search jobs using
|
| 79 |
)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from fastmcp import FastMCP
|
| 4 |
|
| 5 |
# Initialize FastMCP agent
|
| 6 |
+
mcp = FastMCP("RapidAPI Job Search Agent")
|
| 7 |
+
|
| 8 |
+
RAPIDAPI_URL = "https://indeed-indeed.p.rapidapi.com/apisearch?v=2&format=json&q=java&l=austin%2C%20tx&radius=25"
|
| 9 |
+
RAPIDAPI_HOST = "indeed-indeed.p.rapidapi.com"
|
| 10 |
|
| 11 |
@mcp.tool(name="search_jobs")
|
| 12 |
def search_jobs_tool(query: str, location: str, date_created: str = None, salary: str = None, job_type: str = None):
|
| 13 |
"""
|
| 14 |
+
Search jobs from a RapidAPI job search API based on query, location, and optional filters.
|
| 15 |
"""
|
|
|
|
| 16 |
params = {
|
| 17 |
+
"query": query,
|
| 18 |
+
"location": location,
|
| 19 |
"limit": 5,
|
| 20 |
+
# The actual API might use different param names or filters
|
| 21 |
+
# You can add more params here depending on the API spec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
# Clean params
|
| 24 |
params = {k: v for k, v in params.items() if v}
|
| 25 |
|
| 26 |
headers = {
|
| 27 |
+
"X-RapidAPI-Host": RAPIDAPI_HOST,
|
| 28 |
+
"X-RapidAPI-Key": RAPIDAPI_KEY,
|
| 29 |
"Accept": "application/json"
|
| 30 |
}
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
response = requests.get(RAPIDAPI_URL, params=params, headers=headers)
|
| 34 |
response.raise_for_status()
|
| 35 |
return response.json()
|
| 36 |
except requests.RequestException as e:
|
|
|
|
| 38 |
|
| 39 |
def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 40 |
"""
|
| 41 |
+
UI handler for searching jobs using FastMCP + RapidAPI job API (sync).
|
| 42 |
"""
|
| 43 |
try:
|
|
|
|
| 44 |
result = search_jobs_tool(query, location, date_created, salary, job_type)
|
| 45 |
|
| 46 |
if "error" in result:
|
| 47 |
return f"❌ Error: {result['error']}"
|
| 48 |
|
| 49 |
+
# Adapt based on actual response structure from the RapidAPI job API
|
| 50 |
+
jobs = result.get("jobs", []) # often APIs return jobs under 'jobs' or 'data'
|
| 51 |
+
|
| 52 |
if not jobs:
|
| 53 |
return "No jobs found for your search."
|
| 54 |
|
|
|
|
| 75 |
gr.Textbox(label="Job Type (optional: fulltime, parttime, contract)")
|
| 76 |
],
|
| 77 |
outputs="markdown",
|
| 78 |
+
title="Job Search with RapidAPI + FastMCP",
|
| 79 |
+
description="Search jobs using a RapidAPI job search API with filtering options."
|
| 80 |
)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|