Spaces:
Running
Running
File size: 2,580 Bytes
94516ce 0ab97c7 94516ce 9480219 94516ce 0ab97c7 94516ce e92236a 8d505f4 e92236a 8d505f4 c045a8c 0ab97c7 e92236a 8d505f4 e92236a 8d505f4 94516ce 0ab97c7 e92236a 0ab97c7 51f6b7b e92236a 0af8062 0ab97c7 e92236a 0ab97c7 e92236a 0ab97c7 94516ce e92236a 8467e1e 0ab97c7 8467e1e 0ab97c7 e92236a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import gradio as gr
import numpy as np
from text_extractor import extract_text_from_file
from embedder import get_embeddings
from vector_store import create_faiss_index, search_similar_cvs
from groq_api import summarize_match
# Global storage
cv_texts = []
cv_names = []
cv_vectors = []
faiss_index = None
def upload_cvs(files):
global cv_texts, cv_names, cv_vectors, faiss_index
try:
cv_texts = [extract_text_from_file(f) for f in files]
cv_names = [f.name for f in files]
cv_vectors = get_embeddings(cv_texts)
if cv_vectors is None or np.array(cv_vectors).size == 0:
return "β No valid CVs."
faiss_index = create_faiss_index(cv_vectors)
return f"β
Uploaded and indexed {len(files)} CVs."
except Exception as e:
return f"β Error during upload: {e}"
def match_jd(jd_text):
if faiss_index is None:
return "β Please upload CVs first."
if not jd_text.strip():
return "β οΈ Job description is empty."
try:
jd_vector = get_embeddings([jd_text])[0]
indices = search_similar_cvs(jd_vector, faiss_index, k=3)
matched = [cv_names[i] for i in indices]
texts = [cv_texts[i] for i in indices]
summary = summarize_match(jd_text, matched, texts)
return f"β
Top Matches:\n\n" + "\n".join(matched) + f"\n\nπ Summary:\n{summary}"
except Exception as e:
return f"β Error during matching: {e}"
def clear_data():
global cv_texts, cv_names, cv_vectors, faiss_index
cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
return "π§Ή Cleared."
with gr.Blocks() as app:
gr.Markdown("## π CV Matcher with Groq API")
# Upload
file_input = gr.File(file_types=[".pdf", ".docx"], file_count="multiple", label="π€ Upload CVs")
upload_button = gr.Button("π Upload & Index")
upload_status = gr.Textbox(label="Upload Status")
# Job Description Matching
jd_input = gr.Textbox(label="π Paste Job Description", lines=8, placeholder="Paste job description here...")
match_button = gr.Button("π Match CVs")
result_output = gr.Textbox(label="Match Results", lines=15)
# Clear Session
clear_button = gr.Button("π§Ή Clear All")
clear_status = gr.Textbox(label="Clear Status")
# Actions
upload_button.click(upload_cvs, inputs=[file_input], outputs=[upload_status])
match_button.click(match_jd, inputs=[jd_input], outputs=[result_output])
clear_button.click(clear_data, inputs=[], outputs=[clear_status])
app.launch()
|