Spaces:
Running
Running
Update app.py
Browse files
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
|
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"
|
55 |
-
|
|
|
|
|
56 |
except Exception as e:
|
57 |
-
return f"
|
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.
|
63 |
-
|
64 |
-
#
|
65 |
-
with gr.Blocks(
|
66 |
-
gr
|
67 |
-
gr
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
with gr.Row():
|
70 |
-
cv_upload = gr.File(label="π€ Upload CVs
|
71 |
-
upload_button = gr.Button("π Upload & Index
|
72 |
upload_status = gr.Textbox(label="Upload Status", interactive=False)
|
73 |
|
74 |
with gr.Row():
|
75 |
-
jd_input = gr.Textbox(label="π
|
76 |
match_button = gr.Button("π Match CVs")
|
77 |
-
|
78 |
-
match_result = gr.
|
79 |
|
80 |
with gr.Row():
|
81 |
clear_button = gr.Button("π§Ή Clear All")
|
82 |
clear_output = gr.Textbox(label="Status", interactive=False)
|
83 |
|
84 |
-
#
|
85 |
-
upload_button.click(
|
86 |
-
match_button.click(
|
87 |
-
clear_button.click(
|
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()
|