saherPervaiz commited on
Commit
0ab97c7
Β·
verified Β·
1 Parent(s): 8467e1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -21
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import gradio as gr
 
2
  from text_extractor import extract_text_from_file
3
  from embedder import get_embeddings
4
  from vector_store import create_faiss_index, search_similar_cvs
5
  from groq_api import summarize_match
6
 
 
7
  cv_texts = []
8
  cv_names = []
9
  cv_vectors = []
@@ -17,7 +19,7 @@ def upload_cvs(files):
17
  cv_names = [f.name for f in files]
18
  cv_vectors = get_embeddings(cv_texts)
19
 
20
- if not cv_vectors:
21
  return "❌ No valid CVs."
22
 
23
  faiss_index = create_faiss_index(cv_vectors)
@@ -27,20 +29,24 @@ def upload_cvs(files):
27
  return f"❌ Error during upload: {e}"
28
 
29
  def match_jd(jd_text):
30
- if not faiss_index:
31
  return "❌ Please upload CVs first."
32
  if not jd_text.strip():
33
  return "⚠️ Job description is empty."
34
 
35
- jd_vector = get_embeddings([jd_text])[0]
36
- indices = search_similar_cvs(jd_vector, faiss_index, k=3)
 
 
 
 
37
 
38
- matched = [cv_names[i] for i in indices]
39
- texts = [cv_texts[i][:400] for i in indices]
40
 
41
- summary = summarize_match(jd_text, matched, texts)
42
 
43
- return f"βœ… Top Matches:\n{matched}\n\nπŸ“ Summary:\n{summary}"
 
44
 
45
  def clear_data():
46
  global cv_texts, cv_names, cv_vectors, faiss_index
@@ -50,19 +56,23 @@ def clear_data():
50
  with gr.Blocks() as app:
51
  gr.Markdown("## πŸ“„ CV Matcher with Groq API")
52
 
 
53
  file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="πŸ“€ Upload CVs")
54
- upload_btn = gr.Button("πŸ“ Upload & Index")
55
- upload_output = gr.Textbox(label="Upload Status")
56
-
57
- jd_input = gr.Textbox(label="πŸ“‹ Paste Job Description", lines=8)
58
- match_btn = gr.Button("πŸ” Match CVs")
59
- result_output = gr.Textbox(label="Results", lines=12)
60
-
61
- clear_btn = gr.Button("🧹 Clear All")
62
- clear_output = gr.Textbox(label="Reset Status")
63
-
64
- upload_btn.click(upload_cvs, inputs=[file_input], outputs=[upload_output])
65
- match_btn.click(match_jd, inputs=[jd_input], outputs=[result_output])
66
- clear_btn.click(clear_data, inputs=[], outputs=[clear_output])
 
 
 
67
 
68
  app.launch()
 
1
  import gradio as gr
2
+ import numpy as np
3
  from text_extractor import extract_text_from_file
4
  from embedder import get_embeddings
5
  from vector_store import create_faiss_index, search_similar_cvs
6
  from groq_api import summarize_match
7
 
8
+ # Global storage
9
  cv_texts = []
10
  cv_names = []
11
  cv_vectors = []
 
19
  cv_names = [f.name for f in files]
20
  cv_vectors = get_embeddings(cv_texts)
21
 
22
+ if cv_vectors is None or np.array(cv_vectors).size == 0:
23
  return "❌ No valid CVs."
24
 
25
  faiss_index = create_faiss_index(cv_vectors)
 
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():
35
  return "⚠️ Job description is empty."
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][:400] for i in indices]
43
 
44
+ summary = summarize_match(jd_text, matched, texts)
 
45
 
46
+ return f"βœ… Top Matches:\n\n" + "\n".join(matched) + f"\n\nπŸ“ Summary:\n{summary}"
47
 
48
+ except Exception as e:
49
+ return f"❌ Error during matching: {e}"
50
 
51
  def clear_data():
52
  global cv_texts, cv_names, cv_vectors, faiss_index
 
56
  with gr.Blocks() as app:
57
  gr.Markdown("## πŸ“„ CV Matcher with Groq API")
58
 
59
+ # Upload
60
  file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="πŸ“€ Upload CVs")
61
+ upload_button = gr.Button("πŸ“ Upload & Index")
62
+ upload_status = gr.Textbox(label="Upload Status")
63
+
64
+ # Job Description Matching
65
+ jd_input = gr.Textbox(label="πŸ“‹ Paste Job Description", lines=8, placeholder="Paste job description here...")
66
+ match_button = gr.Button("πŸ” Match CVs")
67
+ result_output = gr.Textbox(label="Match Results", lines=15)
68
+
69
+ # Clear Session
70
+ clear_button = gr.Button("🧹 Clear All")
71
+ clear_status = gr.Textbox(label="Clear Status")
72
+
73
+ # Actions
74
+ upload_button.click(upload_cvs, inputs=[file_input], outputs=[upload_status])
75
+ match_button.click(match_jd, inputs=[jd_input], outputs=[result_output])
76
+ clear_button.click(clear_data, inputs=[], outputs=[clear_status])
77
 
78
  app.launch()