Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,9 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
-
import os
|
4 |
import gradio as gr
|
5 |
from text_extractor import extract_text_from_file
|
6 |
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 state
|
11 |
cv_texts = []
|
12 |
cv_names = []
|
13 |
cv_vectors = []
|
@@ -15,86 +11,63 @@ faiss_index = None
|
|
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
|
20 |
cv_names = [f.name for f in files]
|
21 |
cv_vectors = get_embeddings(cv_texts)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
return "β No valid CVs extracted or embedded."
|
26 |
|
27 |
faiss_index = create_faiss_index(cv_vectors)
|
28 |
return f"β
Uploaded and indexed {len(files)} CVs."
|
|
|
29 |
except Exception as e:
|
30 |
return f"β Error during upload: {e}"
|
31 |
|
32 |
def match_jd(jd_text):
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
for i in top_k_indices
|
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 "π§Ή
|
62 |
-
|
63 |
-
|
64 |
-
#
|
65 |
-
|
66 |
-
with gr.
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
gr.
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
gr.Markdown("## π§Ή Clear All Data")
|
88 |
-
gr.Markdown("Click below to reset the app and upload new CVs.")
|
89 |
-
clear_button = gr.Button("Reset App")
|
90 |
-
clear_output = gr.Textbox(label="Reset Status", interactive=False)
|
91 |
-
clear_button.click(clear_data, inputs=[], outputs=[clear_output])
|
92 |
-
|
93 |
-
# Menu Bar Style Tabs
|
94 |
-
app = gr.TabbedInterface(
|
95 |
-
interface_list=[upload_tab, match_tab, reset_tab],
|
96 |
-
tab_names=["π€ Upload CVs", "π Match JD", "π§Ή Reset"]
|
97 |
-
)
|
98 |
-
|
99 |
-
if __name__ == "__main__":
|
100 |
-
app.launch()
|
|
|
|
|
|
|
|
|
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 = []
|
|
|
11 |
|
12 |
def upload_cvs(files):
|
13 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
14 |
+
|
15 |
try:
|
16 |
+
cv_texts = [extract_text_from_file(f) for f in 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)
|
24 |
return f"β
Uploaded and indexed {len(files)} CVs."
|
25 |
+
|
26 |
except Exception as e:
|
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
|
47 |
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
|
48 |
+
return "π§Ή Cleared."
|
49 |
+
|
50 |
+
with gr.Blocks(css=".gr-box {max-width: none !important;}") as app:
|
51 |
+
gr.Markdown("# π CV Matcher with Groq API")
|
52 |
+
|
53 |
+
with gr.Box():
|
54 |
+
gr.Markdown("## π€ Upload CVs")
|
55 |
+
file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="Select CVs")
|
56 |
+
upload_btn = gr.Button("π Upload & Index")
|
57 |
+
upload_output = gr.Textbox(label="Status")
|
58 |
+
|
59 |
+
with gr.Box():
|
60 |
+
gr.Markdown("## π Match Job Description")
|
61 |
+
jd_input = gr.Textbox(label="Paste Job Description", lines=8, max_lines=12)
|
62 |
+
match_btn = gr.Button("π Match CVs")
|
63 |
+
result_output = gr.Textbox(label="Results", lines=12, interactive=False)
|
64 |
+
|
65 |
+
with gr.Row():
|
66 |
+
clear_btn = gr.Button("π§Ή Clear All")
|
67 |
+
clear_output = gr.Textbox(label="Status")
|
68 |
+
|
69 |
+
upload_btn.click(upload_cvs, inputs=[file_input], outputs=[upload_output])
|
70 |
+
match_btn.click(match_jd, inputs=[jd_input], outputs=[result_output])
|
71 |
+
clear_btn.click(clear_data, inputs=[], outputs=[clear_output])
|
72 |
+
|
73 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|