Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,7 @@ 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 |
|
| 9 |
# Global storage
|
| 10 |
cv_texts = []
|
|
@@ -12,43 +11,54 @@ cv_names = []
|
|
| 12 |
cv_vectors = []
|
| 13 |
faiss_index = None
|
| 14 |
|
| 15 |
-
|
| 16 |
def upload_cvs(files):
|
| 17 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
| 18 |
-
|
| 19 |
-
cv_texts = [extract_text_from_file(f.name) for f in files]
|
| 20 |
-
cv_names = [f.name for f in files]
|
| 21 |
-
cv_vectors = get_embeddings(cv_texts)
|
| 22 |
-
faiss_index = create_faiss_index(cv_vectors)
|
| 23 |
-
|
| 24 |
-
return f"Uploaded and indexed {len(files)} CVs."
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def match_jd(jd_text):
|
| 28 |
-
|
| 29 |
-
return "Please upload CVs first."
|
| 30 |
-
|
| 31 |
-
jd_vector = get_embeddings([jd_text])[0]
|
| 32 |
-
top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def clear_data():
|
| 42 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
| 43 |
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
|
| 44 |
-
return "Data cleared."
|
| 45 |
-
|
| 46 |
|
|
|
|
| 47 |
iface = gr.Interface(
|
| 48 |
fn=match_jd,
|
| 49 |
-
inputs=[
|
| 50 |
-
gr.Textbox(lines=10, label="Paste Job Description"),
|
| 51 |
-
],
|
| 52 |
outputs="text",
|
| 53 |
title="CV Matcher with Groq",
|
| 54 |
description="Upload CVs, enter a Job Description, and get top matches and summary."
|
|
|
|
| 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 # β
FIXED: was 'get_summary'
|
|
|
|
| 7 |
|
| 8 |
# Global storage
|
| 9 |
cv_texts = []
|
|
|
|
| 11 |
cv_vectors = []
|
| 12 |
faiss_index = None
|
| 13 |
|
|
|
|
| 14 |
def upload_cvs(files):
|
| 15 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
cv_texts = [extract_text_from_file(f.name) for f in files]
|
| 19 |
+
cv_names = [f.name for f in files]
|
| 20 |
+
cv_vectors = get_embeddings(cv_texts)
|
| 21 |
+
|
| 22 |
+
if not cv_vectors or len(cv_vectors) == 0:
|
| 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 |
def match_jd(jd_text):
|
| 32 |
+
global faiss_index
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
try:
|
| 35 |
+
if not faiss_index:
|
| 36 |
+
return "β Please upload CVs first."
|
| 37 |
|
| 38 |
+
if not jd_text.strip():
|
| 39 |
+
return "β Job description is empty."
|
| 40 |
|
| 41 |
+
jd_vector = get_embeddings([jd_text])[0]
|
| 42 |
+
top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)
|
| 43 |
+
|
| 44 |
+
matched_names = [cv_names[i] for i in top_k_indices]
|
| 45 |
+
matched_texts = [cv_texts[i] for i in top_k_indices]
|
| 46 |
+
|
| 47 |
+
summary = summarize_match(jd_text, matched_names)
|
| 48 |
+
return f"β
Top Matches:\n{matched_names}\n\nπ Summary:\n{summary}"
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return f"β Error during matching: {e}"
|
| 52 |
|
| 53 |
def clear_data():
|
| 54 |
global cv_texts, cv_names, cv_vectors, faiss_index
|
| 55 |
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
|
| 56 |
+
return "π§Ή Data cleared."
|
|
|
|
| 57 |
|
| 58 |
+
# Gradio Interfaces
|
| 59 |
iface = gr.Interface(
|
| 60 |
fn=match_jd,
|
| 61 |
+
inputs=[gr.Textbox(lines=10, label="Paste Job Description")],
|
|
|
|
|
|
|
| 62 |
outputs="text",
|
| 63 |
title="CV Matcher with Groq",
|
| 64 |
description="Upload CVs, enter a Job Description, and get top matches and summary."
|