Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,23 @@ from fastmcp import FastMCP
|
|
| 5 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 6 |
|
| 7 |
@mcp.tool(name="search_jobs")
|
| 8 |
-
def search_jobs_tool(query: str, location: str):
|
| 9 |
-
url = "https://indeed
|
| 10 |
params = {
|
| 11 |
"q": query,
|
| 12 |
"l": location,
|
| 13 |
"limit": 5,
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
|
|
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
response = requests.get(url, params=params)
|
| 18 |
response.raise_for_status()
|
|
@@ -20,8 +29,14 @@ def search_jobs_tool(query: str, location: str):
|
|
| 20 |
except requests.RequestException as e:
|
| 21 |
return {"error": str(e)}
|
| 22 |
|
| 23 |
-
def search_jobs_ui(query, location):
|
| 24 |
-
result = mcp.run("search_jobs", inputs={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if "error" in result:
|
| 27 |
return f"❌ Error: {result['error']}"
|
|
@@ -42,11 +57,17 @@ def search_jobs_ui(query, location):
|
|
| 42 |
|
| 43 |
app = gr.Interface(
|
| 44 |
fn=search_jobs_ui,
|
| 45 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
outputs="markdown",
|
| 47 |
title="Indeed Job Search with FastMCP",
|
| 48 |
-
description="Search jobs
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
app.launch(mcp_server=True)
|
|
|
|
| 5 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 6 |
|
| 7 |
@mcp.tool(name="search_jobs")
|
| 8 |
+
def search_jobs_tool(query: str, location: str, date_created: str = None, salary: str = None, job_type: str = None):
|
| 9 |
+
url = "https://employers.indeed.com/api/v2/jobs"
|
| 10 |
params = {
|
| 11 |
"q": query,
|
| 12 |
"l": location,
|
| 13 |
"limit": 5,
|
| 14 |
+
"dateCreated": date_created,
|
| 15 |
+
"salary": salary,
|
| 16 |
+
"jobType": job_type,
|
| 17 |
+
"sort": "DATECREATED",
|
| 18 |
+
"order": "DESC",
|
| 19 |
+
"statuses": "ACTIVE",
|
| 20 |
+
"fields": "title,id,company,location,url"
|
| 21 |
}
|
| 22 |
+
# Remove parameters with None values
|
| 23 |
+
params = {k: v for k, v in params.items() if v is not None}
|
| 24 |
+
|
| 25 |
try:
|
| 26 |
response = requests.get(url, params=params)
|
| 27 |
response.raise_for_status()
|
|
|
|
| 29 |
except requests.RequestException as e:
|
| 30 |
return {"error": str(e)}
|
| 31 |
|
| 32 |
+
def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 33 |
+
result = mcp.run("search_jobs", inputs={
|
| 34 |
+
"query": query,
|
| 35 |
+
"location": location,
|
| 36 |
+
"date_created": date_created,
|
| 37 |
+
"salary": salary,
|
| 38 |
+
"job_type": job_type
|
| 39 |
+
})
|
| 40 |
|
| 41 |
if "error" in result:
|
| 42 |
return f"❌ Error: {result['error']}"
|
|
|
|
| 57 |
|
| 58 |
app = gr.Interface(
|
| 59 |
fn=search_jobs_ui,
|
| 60 |
+
inputs=[
|
| 61 |
+
gr.Textbox(label="Job Title / Keyword"),
|
| 62 |
+
gr.Textbox(label="Location"),
|
| 63 |
+
gr.Textbox(label="Date Created (YYYY-MM-DD, optional)"),
|
| 64 |
+
gr.Textbox(label="Salary (optional)"),
|
| 65 |
+
gr.Textbox(label="Job Type (optional: fulltime, parttime, contract)")
|
| 66 |
+
],
|
| 67 |
outputs="markdown",
|
| 68 |
title="Indeed Job Search with FastMCP",
|
| 69 |
+
description="Search jobs using Indeed Jobs API with filters."
|
| 70 |
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
+
app.launch(shared=True, mcp_server=True)
|