Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 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")
|
|
@@ -9,7 +9,7 @@ mcp = FastMCP("Indeed Job Search Agent")
|
|
| 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.
|
|
@@ -46,44 +46,52 @@ def search_jobs_tool(query: str, location: str, date_created: str = None, salary
|
|
| 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:
|
| 55 |
"""
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
# Gradio Interface
|
| 85 |
app = gr.Interface(
|
| 86 |
-
fn=search_jobs_ui,
|
| 87 |
inputs=[
|
| 88 |
gr.Textbox(label="Job Title / Keyword"),
|
| 89 |
gr.Textbox(label="Location"),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
from fastmcp import FastMCP, Client
|
| 4 |
|
| 5 |
# Initialize FastMCP agent
|
| 6 |
mcp = FastMCP("Indeed Job Search Agent")
|
|
|
|
| 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.
|
|
|
|
| 46 |
except requests.RequestException as e:
|
| 47 |
return {"error": str(e)}
|
| 48 |
|
| 49 |
+
async 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 |
+
Args:
|
| 54 |
+
query (str): Job title or keyword to search.
|
| 55 |
+
location (str): Job location.
|
| 56 |
+
date_created (str, optional): Date filter (YYYY-MM-DD).
|
| 57 |
+
salary (str, optional): Salary filter.
|
| 58 |
+
job_type (str, optional): Job type filter.
|
| 59 |
+
|
| 60 |
Returns:
|
| 61 |
+
str: Markdown-formatted job list or error message.
|
| 62 |
"""
|
| 63 |
+
async with Client(mcp) as client:
|
| 64 |
+
try:
|
| 65 |
+
result = await client.call_tool("search_jobs", {
|
| 66 |
+
"query": query,
|
| 67 |
+
"location": location,
|
| 68 |
+
"date_created": date_created,
|
| 69 |
+
"salary": salary,
|
| 70 |
+
"job_type": job_type
|
| 71 |
+
})
|
| 72 |
|
| 73 |
+
if "error" in result:
|
| 74 |
+
return f"❌ Error: {result['error']}"
|
| 75 |
|
| 76 |
+
jobs = result.get("results", [])
|
| 77 |
+
if not jobs:
|
| 78 |
+
return "No jobs found for your search."
|
| 79 |
|
| 80 |
+
output = ""
|
| 81 |
+
for job in jobs:
|
| 82 |
+
title = job.get("title", "No Title")
|
| 83 |
+
company = job.get("company", "Unknown Company")
|
| 84 |
+
job_location = job.get("location", "Unknown Location")
|
| 85 |
+
job_url = job.get("url", "#")
|
| 86 |
+
output += f"**{title}** at *{company}*\n📍 {job_location}\n[Apply Here]({job_url})\n\n"
|
| 87 |
|
| 88 |
+
return output
|
| 89 |
+
except Exception as e:
|
| 90 |
+
return f"❌ An error occurred: {str(e)}"
|
| 91 |
|
| 92 |
# Gradio Interface
|
| 93 |
app = gr.Interface(
|
| 94 |
+
fn=gr.async_function(search_jobs_ui), # Important to wrap async functions
|
| 95 |
inputs=[
|
| 96 |
gr.Textbox(label="Job Title / Keyword"),
|
| 97 |
gr.Textbox(label="Location"),
|