OppaAI commited on
Commit
a928af0
·
verified ·
1 Parent(s): 826029c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
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
- # Use call_tool to call the async MCP tool synchronously
34
- result = mcp.call_tool("search_jobs", {
35
- "query": query,
36
- "location": location,
37
- "date_created": date_created,
38
- "salary": salary,
39
- "job_type": job_type
40
- })
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
 
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(share=True, mcp_server=True)
 
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)