saherPervaiz commited on
Commit
863e40a
Β·
verified Β·
1 Parent(s): d64f98a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -7,7 +7,7 @@ from embedder import get_embeddings
7
  from vector_store import create_faiss_index, search_similar_cvs
8
  from groq_api import summarize_match
9
 
10
- # Global storage
11
  cv_texts = []
12
  cv_names = []
13
  cv_vectors = []
@@ -15,7 +15,6 @@ faiss_index = None
15
 
16
  def upload_cvs(files):
17
  global cv_texts, cv_names, cv_vectors, faiss_index
18
-
19
  try:
20
  cv_texts = [extract_text_from_file(f.name) for f in files]
21
  cv_names = [f.name for f in files]
@@ -32,11 +31,9 @@ def upload_cvs(files):
32
 
33
  def match_jd(jd_text):
34
  global faiss_index
35
-
36
  try:
37
  if not faiss_index:
38
  return "❌ Please upload CVs first."
39
-
40
  if not jd_text.strip():
41
  return "❌ Job description is empty."
42
 
@@ -51,40 +48,48 @@ def match_jd(jd_text):
51
  ]
52
 
53
  summary = summarize_match(jd_text, matched_names, matched_texts)
54
- return f"βœ… Top Matches:\n{matched_names}\n\nπŸ“ Summary:\n{summary}"
55
-
 
 
56
  except Exception as e:
57
- return f"❌ Error during matching: {e}"
58
 
59
  def clear_data():
60
  global cv_texts, cv_names, cv_vectors, faiss_index
61
  cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
62
- return "🧹 All data cleared. You can now start fresh."
63
-
64
- # 🌟 Redesigned Gradio Interface with Blocks
65
- with gr.Blocks() as app:
66
- gr.Markdown("## πŸ“„ CV Matcher App")
67
- gr.Markdown("Upload candidate CVs, enter a job description, and let AI find the top matches using Groq + FAISS.")
 
 
 
 
 
 
68
 
69
  with gr.Row():
70
- cv_upload = gr.File(label="πŸ“€ Upload CVs (PDF/DOCX)", file_types=[".pdf", ".docx"], file_count="multiple")
71
- upload_button = gr.Button("πŸ“ Upload & Index CVs")
72
  upload_status = gr.Textbox(label="Upload Status", interactive=False)
73
 
74
  with gr.Row():
75
- jd_input = gr.Textbox(label="πŸ“‹ Paste Job Description", lines=8, placeholder="Enter the job description here...")
76
  match_button = gr.Button("πŸ” Match CVs")
77
-
78
- match_result = gr.Textbox(label="πŸ“Š Matching Result & Summary", lines=12, interactive=False)
79
 
80
  with gr.Row():
81
  clear_button = gr.Button("🧹 Clear All")
82
  clear_output = gr.Textbox(label="Status", interactive=False)
83
 
84
- # Function bindings
85
- upload_button.click(fn=upload_cvs, inputs=[cv_upload], outputs=[upload_status])
86
- match_button.click(fn=match_jd, inputs=[jd_input], outputs=[match_result])
87
- clear_button.click(fn=clear_data, inputs=[], outputs=[clear_output])
88
 
89
  if __name__ == "__main__":
90
  app.launch()
 
7
  from vector_store import create_faiss_index, search_similar_cvs
8
  from groq_api import summarize_match
9
 
10
+ # Global state
11
  cv_texts = []
12
  cv_names = []
13
  cv_vectors = []
 
15
 
16
  def upload_cvs(files):
17
  global cv_texts, cv_names, cv_vectors, faiss_index
 
18
  try:
19
  cv_texts = [extract_text_from_file(f.name) for f in files]
20
  cv_names = [f.name for f in files]
 
31
 
32
  def match_jd(jd_text):
33
  global faiss_index
 
34
  try:
35
  if not faiss_index:
36
  return "❌ Please upload CVs first."
 
37
  if not jd_text.strip():
38
  return "❌ Job description is empty."
39
 
 
48
  ]
49
 
50
  summary = summarize_match(jd_text, matched_names, matched_texts)
51
+ return f"""
52
+ βœ… <span style='color:#16a34a; font-weight:bold;'>Top Matches:</span><br>{matched_names}<br><br>
53
+ πŸ“ <span style='color:#3b82f6; font-weight:bold;'>Summary:</span><br>{summary}
54
+ """
55
  except Exception as e:
56
+ return f"<span style='color:red;'>❌ Error during matching: {e}</span>"
57
 
58
  def clear_data():
59
  global cv_texts, cv_names, cv_vectors, faiss_index
60
  cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
61
+ return "🧹 All data cleared."
62
+
63
+ # 🌈 Interface with color styling
64
+ with gr.Blocks(css="""
65
+ .gr-button { background-color: #2563eb; color: white; font-weight: bold; }
66
+ .gr-button:hover { background-color: #1d4ed8; }
67
+ textarea, input[type='file'] { border: 2px solid #3b82f6 !important; }
68
+ .gr-textbox label { color: #111827; font-weight: 600; }
69
+ """) as app:
70
+
71
+ gr.HTML("<h2 style='color:#2563eb;'>πŸ“„ CV Filter App (Styled)</h2>")
72
+ gr.Markdown("Upload CVs, paste a job description, and match using Groq + FAISS.")
73
 
74
  with gr.Row():
75
+ cv_upload = gr.File(label="πŸ“€ Upload CVs", file_types=[".pdf", ".docx"], file_count="multiple")
76
+ upload_button = gr.Button("πŸ“ Upload & Index")
77
  upload_status = gr.Textbox(label="Upload Status", interactive=False)
78
 
79
  with gr.Row():
80
+ jd_input = gr.Textbox(label="πŸ“‹ Job Description", lines=8, placeholder="Paste job description...")
81
  match_button = gr.Button("πŸ” Match CVs")
82
+
83
+ match_result = gr.HTML(label="πŸ“Š Result")
84
 
85
  with gr.Row():
86
  clear_button = gr.Button("🧹 Clear All")
87
  clear_output = gr.Textbox(label="Status", interactive=False)
88
 
89
+ # Button actions
90
+ upload_button.click(upload_cvs, inputs=[cv_upload], outputs=[upload_status])
91
+ match_button.click(match_jd, inputs=[jd_input], outputs=[match_result])
92
+ clear_button.click(clear_data, inputs=[], outputs=[clear_output])
93
 
94
  if __name__ == "__main__":
95
  app.launch()