saherPervaiz commited on
Commit
94516ce
·
verified ·
1 Parent(s): 3fe47fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py CHANGED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 get_summary
7
+
8
+ # Global storage
9
+ cv_texts = []
10
+ cv_names = []
11
+ cv_vectors = []
12
+ faiss_index = None
13
+
14
+
15
+ def upload_cvs(files):
16
+ global cv_texts, cv_names, cv_vectors, faiss_index
17
+
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
+ faiss_index = create_faiss_index(cv_vectors)
22
+
23
+ return f"Uploaded and indexed {len(files)} CVs."
24
+
25
+
26
+ def match_jd(jd_text):
27
+ if not faiss_index:
28
+ return "Please upload CVs first."
29
+
30
+ jd_vector = get_embeddings([jd_text])[0]
31
+ top_k_indices = search_similar_cvs(jd_vector, faiss_index, k=3)
32
+
33
+ matched_names = [cv_names[i] for i in top_k_indices]
34
+ matched_texts = [cv_texts[i] for i in top_k_indices]
35
+ summary = get_summary(jd_text, matched_texts)
36
+
37
+ return f"Top Matches: {matched_names}\n\nSummary: {summary}"
38
+
39
+
40
+ def clear_data():
41
+ global cv_texts, cv_names, cv_vectors, faiss_index
42
+ cv_texts, cv_names, cv_vectors, faiss_index = [], [], [], None
43
+ return "Data cleared."
44
+
45
+
46
+ iface = gr.Interface(
47
+ fn=match_jd,
48
+ inputs=[
49
+ gr.Textbox(lines=10, label="Paste Job Description"),
50
+ ],
51
+ outputs="text",
52
+ title="CV Matcher with Groq",
53
+ description="Upload CVs, enter a Job Description, and get top matches and summary."
54
+ )
55
+
56
+ upload = gr.Interface(
57
+ fn=upload_cvs,
58
+ inputs=gr.File(file_types=[".pdf", ".docx"], file_count="multiple"),
59
+ outputs="text",
60
+ title="Upload CVs"
61
+ )
62
+
63
+ clear = gr.Interface(fn=clear_data, inputs=[], outputs="text", title="Reset Data")
64
+
65
+ app = gr.TabbedInterface([upload, iface, clear], ["Upload CVs", "Match JD", "Clear Data"])
66
+
67
+ if __name__ == "__main__":
68
+ app.launch()