Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import httpx
|
| 3 |
-
from fastmcp import FastMCP
|
| 4 |
|
| 5 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 6 |
|
|
@@ -29,32 +29,34 @@ async def search_jobs_tool(query: str, location: str, date_created: str = None,
|
|
| 29 |
except httpx.RequestError as e:
|
| 30 |
return {"error": str(e)}
|
| 31 |
|
| 32 |
-
def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
app = gr.Interface(
|
| 60 |
fn=search_jobs_ui,
|
|
@@ -71,4 +73,4 @@ app = gr.Interface(
|
|
| 71 |
)
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
-
app.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import httpx
|
| 3 |
+
from fastmcp import FastMCP, Client
|
| 4 |
|
| 5 |
mcp = FastMCP("Indeed Job Search Agent")
|
| 6 |
|
|
|
|
| 29 |
except httpx.RequestError as e:
|
| 30 |
return {"error": str(e)}
|
| 31 |
|
| 32 |
+
async def search_jobs_ui(query, location, date_created=None, salary=None, job_type=None):
|
| 33 |
+
async with Client(mcp) as client:
|
| 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 |
+
jobs = result.get("results", [])
|
| 46 |
+
if not jobs:
|
| 47 |
+
return "No jobs found for your search."
|
| 48 |
|
| 49 |
+
output = ""
|
| 50 |
+
for job in jobs:
|
| 51 |
+
title = job.get("title", "No Title")
|
| 52 |
+
company = job.get("company", "Unknown Company")
|
| 53 |
+
job_location = job.get("location", "Unknown Location")
|
| 54 |
+
job_url = job.get("url", "#")
|
| 55 |
+
output += f"**{title}** at *{company}*\n📍 {job_location}\n[Apply Here]({job_url})\n\n"
|
| 56 |
|
| 57 |
+
return output
|
| 58 |
+
except Exception as e:
|
| 59 |
+
return f"❌ An error occurred: {str(e)}"
|
| 60 |
|
| 61 |
app = gr.Interface(
|
| 62 |
fn=search_jobs_ui,
|
|
|
|
| 73 |
)
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
+
app.launch(mcp_server=True)
|