Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from fastmcp import FastMCP
|
| 4 |
|
|
|
|
| 5 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 6 |
|
| 7 |
@mcp.tool(name="search_jobs")
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
url = "https://employers.indeed.com/api/v2/jobs"
|
| 10 |
params = {
|
| 11 |
"q": query,
|
|
@@ -19,45 +33,55 @@ async def search_jobs_tool(query: str, location: str, date_created: str = None,
|
|
| 19 |
"statuses": "ACTIVE",
|
| 20 |
"fields": "title,id,company,location,url"
|
| 21 |
}
|
| 22 |
-
params = {k: v for k, v in params.items() if v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
try:
|
| 35 |
-
result = await client.call_tool("search_jobs", {
|
| 36 |
-
"query": query,
|
| 37 |
-
"location": location,
|
| 38 |
-
"date_created": date_created,
|
| 39 |
-
"salary": salary,
|
| 40 |
-
"job_type": job_type
|
| 41 |
-
})
|
| 42 |
-
if "error" in result:
|
| 43 |
-
return f"❌ Error: {result['error']}"
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
|
|
|
| 61 |
app = gr.Interface(
|
| 62 |
fn=search_jobs_ui,
|
| 63 |
inputs=[
|
|
@@ -69,7 +93,7 @@ app = gr.Interface(
|
|
| 69 |
],
|
| 70 |
outputs="markdown",
|
| 71 |
title="Indeed Job Search with FastMCP",
|
| 72 |
-
description="Search jobs using Indeed
|
| 73 |
)
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from fastmcp import FastMCP
|
| 4 |
|
| 5 |
+
# Initialize FastMCP agent
|
| 6 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 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 Indeed API based on query, location and optional filters.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
query (str): Job title or keyword to search.
|
| 15 |
+
location (str): City or region to search in.
|
| 16 |
+
date_created (str, optional): Filter by creation date (e.g. "2024-06-01").
|
| 17 |
+
salary (str, optional): Minimum salary filter.
|
| 18 |
+
job_type (str, optional): Type of job (e.g. "fulltime", "parttime").
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
dict: Job search results or error message.
|
| 22 |
+
"""
|
| 23 |
url = "https://employers.indeed.com/api/v2/jobs"
|
| 24 |
params = {
|
| 25 |
"q": query,
|
|
|
|
| 33 |
"statuses": "ACTIVE",
|
| 34 |
"fields": "title,id,company,location,url"
|
| 35 |
}
|
| 36 |
+
params = {k: v for k, v in params.items() if v}
|
| 37 |
+
|
| 38 |
+
headers = {
|
| 39 |
+
"Accept": "application/json"
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
response = requests.get(url, params=params, headers=headers)
|
| 44 |
+
response.raise_for_status()
|
| 45 |
+
return response.json()
|
| 46 |
+
except requests.RequestException as e:
|
| 47 |
+
return {"error": str(e)}
|
| 48 |
+
|
| 49 |
+
def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 50 |
+
"""
|
| 51 |
+
UI handler for searching jobs using FastMCP + Indeed API.
|
| 52 |
|
| 53 |
+
Returns:
|
| 54 |
+
str: Formatted Markdown output with job listings or error message.
|
| 55 |
+
"""
|
| 56 |
+
try:
|
| 57 |
+
result = mcp.run("search_jobs", inputs={
|
| 58 |
+
"query": query,
|
| 59 |
+
"location": location,
|
| 60 |
+
"date_created": date_created,
|
| 61 |
+
"salary": salary,
|
| 62 |
+
"job_type": job_type
|
| 63 |
+
})
|
| 64 |
|
| 65 |
+
if "error" in result:
|
| 66 |
+
return f"❌ Error: {result['error']}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
jobs = result.get("results", [])
|
| 69 |
+
if not jobs:
|
| 70 |
+
return "No jobs found for your search."
|
| 71 |
|
| 72 |
+
output = ""
|
| 73 |
+
for job in jobs:
|
| 74 |
+
title = job.get("title", "No Title")
|
| 75 |
+
company = job.get("company", "Unknown Company")
|
| 76 |
+
job_location = job.get("location", "Unknown Location")
|
| 77 |
+
job_url = job.get("url", "#")
|
| 78 |
+
output += f"**{title}** at *{company}*\n📍 {job_location}\n[Apply Here]({job_url})\n\n"
|
| 79 |
|
| 80 |
+
return output
|
| 81 |
+
except Exception as e:
|
| 82 |
+
return f"❌ An error occurred: {str(e)}"
|
| 83 |
|
| 84 |
+
# Gradio Interface
|
| 85 |
app = gr.Interface(
|
| 86 |
fn=search_jobs_ui,
|
| 87 |
inputs=[
|
|
|
|
| 93 |
],
|
| 94 |
outputs="markdown",
|
| 95 |
title="Indeed Job Search with FastMCP",
|
| 96 |
+
description="Search jobs using the Indeed API with filtering options."
|
| 97 |
)
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|