saherPervaiz commited on
Commit
e693c99
Β·
verified Β·
1 Parent(s): 9089c56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -15,6 +15,9 @@ def upload_cvs(files):
15
  global cv_texts, cv_names, cv_vectors, faiss_index
16
 
17
  try:
 
 
 
18
  cv_texts = [extract_text_from_file(f) for f in files]
19
  cv_names = [f.name for f in files]
20
  cv_vectors = get_embeddings(cv_texts)
@@ -28,7 +31,7 @@ def upload_cvs(files):
28
  except Exception as e:
29
  return f"❌ Error during upload: {e}"
30
 
31
- def match_jd(jd_text):
32
  if faiss_index is None:
33
  return "❌ Please upload CVs first."
34
  if not jd_text.strip():
@@ -36,15 +39,18 @@ def match_jd(jd_text):
36
 
37
  try:
38
  jd_vector = get_embeddings([jd_text])[0]
39
- indices = search_similar_cvs(jd_vector, faiss_index, k=3)
 
 
 
 
40
 
41
  matched = [cv_names[i] for i in indices]
42
  texts = [cv_texts[i] for i in indices]
43
 
44
-
45
  summary = summarize_match(jd_text, matched, texts)
46
 
47
- return f"βœ… Top Matches:\n\n" + "\n".join(matched) + f"\n\nπŸ“ Summary:\n{summary}"
48
 
49
  except Exception as e:
50
  return f"❌ Error during matching: {e}"
@@ -55,17 +61,20 @@ def clear_data():
55
  return "🧹 Cleared."
56
 
57
  with gr.Blocks() as app:
58
- gr.Markdown("## πŸ“„ CV Matcher with Groq API")
59
 
60
  # Upload
61
- file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="πŸ“€ Upload CVs")
62
  upload_button = gr.Button("πŸ“ Upload & Index")
63
  upload_status = gr.Textbox(label="Upload Status")
64
 
65
- # Job Description Matching
66
  jd_input = gr.Textbox(label="πŸ“‹ Paste Job Description", lines=8, placeholder="Paste job description here...")
 
 
 
67
  match_button = gr.Button("πŸ” Match CVs")
68
- result_output = gr.Textbox(label="Match Results", lines=15)
69
 
70
  # Clear Session
71
  clear_button = gr.Button("🧹 Clear All")
@@ -73,7 +82,7 @@ with gr.Blocks() as app:
73
 
74
  # Actions
75
  upload_button.click(upload_cvs, inputs=[file_input], outputs=[upload_status])
76
- match_button.click(match_jd, inputs=[jd_input], outputs=[result_output])
77
  clear_button.click(clear_data, inputs=[], outputs=[clear_status])
78
 
79
  app.launch()
 
15
  global cv_texts, cv_names, cv_vectors, faiss_index
16
 
17
  try:
18
+ if len(files) > 10:
19
+ return "❌ Limit exceeded: Upload a maximum of 10 CVs."
20
+
21
  cv_texts = [extract_text_from_file(f) for f in files]
22
  cv_names = [f.name for f in files]
23
  cv_vectors = get_embeddings(cv_texts)
 
31
  except Exception as e:
32
  return f"❌ Error during upload: {e}"
33
 
34
+ def match_jd(jd_text, match_mode):
35
  if faiss_index is None:
36
  return "❌ Please upload CVs first."
37
  if not jd_text.strip():
 
39
 
40
  try:
41
  jd_vector = get_embeddings([jd_text])[0]
42
+
43
+ if match_mode == "Top 3 Matches":
44
+ indices = search_similar_cvs(jd_vector, faiss_index, k=3)
45
+ else: # All CVs
46
+ indices = list(range(len(cv_names)))
47
 
48
  matched = [cv_names[i] for i in indices]
49
  texts = [cv_texts[i] for i in indices]
50
 
 
51
  summary = summarize_match(jd_text, matched, texts)
52
 
53
+ return f"βœ… {match_mode}:\n\n" + "\n".join(matched) + f"\n\nπŸ“ Summary:\n{summary}"
54
 
55
  except Exception as e:
56
  return f"❌ Error during matching: {e}"
 
61
  return "🧹 Cleared."
62
 
63
  with gr.Blocks() as app:
64
+ gr.Markdown("## πŸ“„ CV Matcher with Groq API (Flexible Matching Mode)")
65
 
66
  # Upload
67
+ file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="πŸ“€ Upload CVs (Max 10)")
68
  upload_button = gr.Button("πŸ“ Upload & Index")
69
  upload_status = gr.Textbox(label="Upload Status")
70
 
71
+ # Job Description & Matching
72
  jd_input = gr.Textbox(label="πŸ“‹ Paste Job Description", lines=8, placeholder="Paste job description here...")
73
+
74
+ match_mode = gr.Radio(["Top 3 Matches", "All Uploaded CVs"], value="Top 3 Matches", label="Matching Mode")
75
+
76
  match_button = gr.Button("πŸ” Match CVs")
77
+ result_output = gr.Textbox(label="Match Results", lines=20)
78
 
79
  # Clear Session
80
  clear_button = gr.Button("🧹 Clear All")
 
82
 
83
  # Actions
84
  upload_button.click(upload_cvs, inputs=[file_input], outputs=[upload_status])
85
+ match_button.click(match_jd, inputs=[jd_input, match_mode], outputs=[result_output])
86
  clear_button.click(clear_data, inputs=[], outputs=[clear_status])
87
 
88
  app.launch()