OppaAI commited on
Commit
bf33900
·
verified ·
1 Parent(s): 653582c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -28
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: 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=[
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"),