File size: 1,886 Bytes
94516ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
import gradio as gr
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 get_summary

# Global storage
cv_texts = []
cv_names = []
cv_vectors = []
faiss_index = None


def upload_cvs(files):
    global cv_texts, cv_names, cv_vectors, faiss_index
    
    cv_texts = [extract_text_from_file(f.name) for f in files]
    cv_names = [f.name for f in files]
    cv_vectors = get_embeddings(cv_texts)
    faiss_index = create_faiss_index(cv_vectors)
    
    return f"Uploaded and indexed {len(files)} CVs."


def match_jd(jd_text):
    if not faiss_index:
        return "Please upload CVs first."
    
    jd_vector = get_embeddings([jd_text])[0]
    top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)

    matched_names = [cv_names[i] for i in top_k_indices]
    matched_texts = [cv_texts[i] for i in top_k_indices]
    summary = get_summary(jd_text, matched_texts)

    return f"Top Matches: {matched_names}\n\nSummary: {summary}"


def clear_data():
    global cv_texts, cv_names, cv_vectors, faiss_index
    cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
    return "Data cleared."


iface = gr.Interface(
    fn=match_jd,
    inputs=[
        gr.Textbox(lines=10, label="Paste Job Description"),
    ],
    outputs="text",
    title="CV Matcher with Groq",
    description="Upload CVs, enter a Job Description, and get top matches and summary."
)

upload = gr.Interface(
    fn=upload_cvs,
    inputs=gr.File(file_types=[".pdf", ".docx"], file_count="multiple"),
    outputs="text",
    title="Upload CVs"
)

clear = gr.Interface(fn=clear_data, inputs=[], outputs="text", title="Reset Data")

app = gr.TabbedInterface([upload, iface, clear], ["Upload CVs", "Match JD", "Clear Data"])

if __name__ == "__main__":
    app.launch()