Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
# app.py
|
|
|
2 |
import gradio as gr
|
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 = []
|
@@ -19,16 +20,15 @@ def upload_cvs(files):
|
|
19 |
cv_names = [f.name for f in files]
|
20 |
cv_vectors = get_embeddings(cv_texts)
|
21 |
|
22 |
-
|
|
|
23 |
return "β No valid CVs extracted or embedded."
|
24 |
|
25 |
faiss_index = create_faiss_index(cv_vectors)
|
26 |
return f"β
Uploaded and indexed {len(files)} CVs."
|
27 |
-
|
28 |
except Exception as e:
|
29 |
return f"β Error during upload: {e}"
|
30 |
|
31 |
-
|
32 |
def match_jd(jd_text):
|
33 |
global faiss_index
|
34 |
|
@@ -42,16 +42,16 @@ def match_jd(jd_text):
|
|
42 |
jd_vector = get_embeddings([jd_text])[0]
|
43 |
top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)
|
44 |
|
45 |
-
|
46 |
-
|
|
|
47 |
|
48 |
-
summary = summarize_match(jd_text, matched_names)
|
49 |
return f"β
Top Matches:\n{matched_names}\n\nπ Summary:\n{summary}"
|
50 |
|
51 |
except Exception as e:
|
52 |
return f"β Error during matching: {e}"
|
53 |
|
54 |
-
|
55 |
def clear_data():
|
56 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
57 |
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
|
|
|
1 |
# app.py
|
2 |
+
import os
|
3 |
import gradio as gr
|
4 |
from text_extractor import extract_text_from_file
|
5 |
from embedder import get_embeddings
|
6 |
from vector_store import create_faiss_index, search_similar_cvs
|
7 |
+
from groq_api import summarize_match
|
8 |
|
9 |
# Global storage
|
10 |
cv_texts = []
|
|
|
20 |
cv_names = [f.name for f in files]
|
21 |
cv_vectors = get_embeddings(cv_texts)
|
22 |
|
23 |
+
import numpy as np
|
24 |
+
if cv_vectors is None or np.array(cv_vectors).size == 0:
|
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 |
global faiss_index
|
34 |
|
|
|
42 |
jd_vector = get_embeddings([jd_text])[0]
|
43 |
top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)
|
44 |
|
45 |
+
# Get readable file names and snippets of CVs
|
46 |
+
matched_names = [os.path.basename(cv_names[i]) for i in top_k_indices]
|
47 |
+
matched_texts = [cv_texts[i][:500] for i in top_k_indices] # limit for Groq prompt
|
48 |
|
49 |
+
summary = summarize_match(jd_text, matched_names, matched_texts)
|
50 |
return f"β
Top Matches:\n{matched_names}\n\nπ Summary:\n{summary}"
|
51 |
|
52 |
except Exception as e:
|
53 |
return f"β Error during matching: {e}"
|
54 |
|
|
|
55 |
def clear_data():
|
56 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
57 |
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
|