riteshkokam commited on
Commit
0166fac
·
verified ·
1 Parent(s): 13aabb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -12
app.py CHANGED
@@ -44,7 +44,7 @@ def fetch_arbeitnow(keywords):
44
  return []
45
 
46
  def fetch_remotive(keywords):
47
- resp = requests.get("https://remotive.io/api/remote-jobs", params={"search": " ".join(keywords)})
48
  print("Remotive", resp)
49
  if resp.ok:
50
  return resp.json().get("jobs", [])
@@ -86,24 +86,44 @@ def find_jobs(file, added_kw, use_ai):
86
  keywords = [kw.strip() for kw in added_kw.split(",") if kw.strip()] or extracted
87
  print("Keywords", keywords)
88
  jobs = fetch_arbeitnow(keywords) + fetch_remotive(keywords) + fetch_remoteok(keywords)
 
89
  ranked = rank_jobs(resume, jobs)
 
90
 
91
  table = []
92
- for j, score in ranked:
93
- raw_date = j.get("publication_date") or j.get("created_at") or j.get("date")
94
- posted = str(raw_date)[:10] if raw_date is not None else ""
 
 
 
 
 
95
  table.append({
96
- "Role": j.get("title","N/A") or j.get("position","N/A"),
97
- "Company": j.get("company","N/A") or j.get("company_name","N/A"),
98
- "Location": j.get("location","N/A"),
99
- "Posted": posted,
100
  "Score": f"{score*100:.1f}%",
101
- "Apply": j.get("url") or j.get("joblink") or j.get("apply_url") or ""
102
  })
103
 
104
  explanation = refine_with_ai(ranked, resume) if use_ai else ""
105
  return table, explanation
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  # 7️⃣ Gradio UI
109
  with gr.Blocks() as demo:
@@ -113,9 +133,12 @@ with gr.Blocks() as demo:
113
  added = gr.Textbox(label="Add keywords (comma-separated)", placeholder="e.g. Python, ML")
114
  use_ai = gr.Checkbox(label="Use AI to refine explanation", value=False)
115
  btn = gr.Button("Find Jobs")
116
- result = gr.Dataframe(headers=["Role","Company","Location","Posted","Score","Apply"], row_count=(1,5))
117
- ai_out = gr.Markdown()
118
- btn.click(find_jobs, [resume, added, use_ai], [result, ai_out])
 
 
 
119
 
120
  if __name__ == "__main__":
121
  demo.launch()
 
44
  return []
45
 
46
  def fetch_remotive(keywords):
47
+ resp = requests.get("https://remotive.com/api/remote-jobs", params={"search": " ".join(keywords)})
48
  print("Remotive", resp)
49
  if resp.ok:
50
  return resp.json().get("jobs", [])
 
86
  keywords = [kw.strip() for kw in added_kw.split(",") if kw.strip()] or extracted
87
  print("Keywords", keywords)
88
  jobs = fetch_arbeitnow(keywords) + fetch_remotive(keywords) + fetch_remoteok(keywords)
89
+ print("Jobs", jobs)
90
  ranked = rank_jobs(resume, jobs)
91
+ print("Rank_jobs", rank_jobs)
92
 
93
  table = []
94
+ for job, score in ranked:
95
+ role = job.get("title") or job.get("position", "")
96
+ company = job.get("company") or job.get("company_name", "")
97
+ location = job.get("location", "")
98
+ # Normalize date (as we did before)
99
+ posted = format_posted(job)
100
+ apply_url= job.get("url") or job.get("apply_url","") or ""
101
+ # Make sure none of these are dicts/lists
102
  table.append({
103
+ "Role": str(role),
104
+ "Company": str(company),
105
+ "Location": str(location),
106
+ "Posted": str(posted),
107
  "Score": f"{score*100:.1f}%",
108
+ "Apply": str(apply_url)
109
  })
110
 
111
  explanation = refine_with_ai(ranked, resume) if use_ai else ""
112
  return table, explanation
113
 
114
+ # 7️⃣ Jobs in Markdown
115
+ def jobs_to_markdown(table):
116
+ md = "| Role | Company | Location | Posted | Score | Apply |\n"
117
+ md += "| --- | ------- | -------- | ------ | ----- | ----- |\n"
118
+ for row in table:
119
+ link = f"[Apply]({row['Apply']})" if row['Apply'] else ""
120
+ md += (
121
+ f"| {row['Role']} | {row['Company']} "
122
+ f"| {row['Location']} | {row['Posted']} "
123
+ f"| {row['Score']} | {link} |\n"
124
+ )
125
+ return md
126
+
127
 
128
  # 7️⃣ Gradio UI
129
  with gr.Blocks() as demo:
 
133
  added = gr.Textbox(label="Add keywords (comma-separated)", placeholder="e.g. Python, ML")
134
  use_ai = gr.Checkbox(label="Use AI to refine explanation", value=False)
135
  btn = gr.Button("Find Jobs")
136
+ jobs_md = gr.Markdown()
137
+ btn.click(
138
+ fn=lambda f,k,ai: jobs_to_markdown(*find_jobs(f,k,ai)),
139
+ inputs=[resume, added, use_ai],
140
+ outputs=[jobs_md]
141
+ )
142
 
143
  if __name__ == "__main__":
144
  demo.launch()