Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
location (str): Location for the job search.
|
| 10 |
-
Returns:
|
| 11 |
-
str: Markdown-formatted string of job results or error message.
|
| 12 |
-
"""
|
| 13 |
-
url = "https://indeed-api.services/api/v1/jobs" # Example public endpoint (confirm from docs)
|
| 14 |
params = {
|
| 15 |
"q": query,
|
| 16 |
"l": location,
|
| 17 |
"limit": 5,
|
| 18 |
-
|
| 19 |
-
"salary": salary if salary else None,
|
| 20 |
-
"jobtype": jobtype if jobtype else None,
|
| 21 |
}
|
| 22 |
-
params = {k: v for k, v in params.items() if v is not None}
|
| 23 |
-
|
| 24 |
try:
|
| 25 |
response = requests.get(url, params=params)
|
| 26 |
response.raise_for_status()
|
| 27 |
-
|
| 28 |
-
except requests.
|
| 29 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
jobs = result.get("results", [])
|
| 32 |
if not jobs:
|
|
@@ -38,21 +36,17 @@ def search_jobs_ui(query, location):
|
|
| 38 |
company = job.get("company", "Unknown Company")
|
| 39 |
job_location = job.get("location", "Unknown Location")
|
| 40 |
job_url = job.get("url", "#")
|
| 41 |
-
|
| 42 |
output += f"**{title}** at *{company}*\nπ {job_location}\n[Apply Here]({job_url})\n\n"
|
| 43 |
|
| 44 |
return output
|
| 45 |
|
| 46 |
app = gr.Interface(
|
| 47 |
fn=search_jobs_ui,
|
| 48 |
-
inputs=[
|
| 49 |
-
gr.Textbox(label="Job Title / Keyword"),
|
| 50 |
-
gr.Textbox(label="Location")
|
| 51 |
-
],
|
| 52 |
outputs="markdown",
|
| 53 |
-
title="Indeed Job Search",
|
| 54 |
-
description="Search
|
| 55 |
)
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
-
app.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
from fastmcp import FastMCP
|
| 4 |
|
| 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-api.services/api/v1/jobs"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
params = {
|
| 11 |
"q": query,
|
| 12 |
"l": location,
|
| 13 |
"limit": 5,
|
| 14 |
+
# add optional filters here if needed
|
|
|
|
|
|
|
| 15 |
}
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
response = requests.get(url, params=params)
|
| 18 |
response.raise_for_status()
|
| 19 |
+
return response.json()
|
| 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={"query": query, "location": location})
|
| 25 |
+
|
| 26 |
+
if "error" in result:
|
| 27 |
+
return f"β Error: {result['error']}"
|
| 28 |
|
| 29 |
jobs = result.get("results", [])
|
| 30 |
if not jobs:
|
|
|
|
| 36 |
company = job.get("company", "Unknown Company")
|
| 37 |
job_location = job.get("location", "Unknown Location")
|
| 38 |
job_url = job.get("url", "#")
|
|
|
|
| 39 |
output += f"**{title}** at *{company}*\nπ {job_location}\n[Apply Here]({job_url})\n\n"
|
| 40 |
|
| 41 |
return output
|
| 42 |
|
| 43 |
app = gr.Interface(
|
| 44 |
fn=search_jobs_ui,
|
| 45 |
+
inputs=[gr.Textbox(label="Job Title / Keyword"), gr.Textbox(label="Location")],
|
|
|
|
|
|
|
|
|
|
| 46 |
outputs="markdown",
|
| 47 |
+
title="Indeed Job Search with FastMCP",
|
| 48 |
+
description="Search jobs via FastMCP tool integrated with Gradio UI."
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
+
app.launch(mcp_server=True)
|