Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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
|
31 |
return "β Please upload CVs first."
|
32 |
if not jd_text.strip():
|
33 |
return "β οΈ Job description is empty."
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
texts = [cv_texts[i][:400] for i in indices]
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
|
|
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 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
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()
|