Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,11 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import fitz # PyMuPDF
|
| 4 |
import docx
|
| 5 |
-
import requests
|
| 6 |
import numpy as np
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
}
|
| 12 |
|
| 13 |
|
| 14 |
# ---- Text extraction ----
|
|
@@ -25,16 +23,11 @@ def extract_text(file):
|
|
| 25 |
return ""
|
| 26 |
|
| 27 |
|
| 28 |
-
# ----
|
| 29 |
def get_embedding(text):
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
if isinstance(data, list) and "embedding" in data[0]:
|
| 34 |
-
return np.array(data[0]["embedding"])
|
| 35 |
-
elif isinstance(data, list) and isinstance(data[0], list):
|
| 36 |
-
return np.array(data[0])
|
| 37 |
-
return np.zeros(384)
|
| 38 |
|
| 39 |
|
| 40 |
# ---- CV ranking ----
|
|
@@ -71,11 +64,9 @@ demo = gr.Interface(
|
|
| 71 |
gr.File(label="π Upload CVs (PDF/DOCX)", file_count="multiple", type="binary"),
|
| 72 |
],
|
| 73 |
outputs=gr.Markdown(),
|
| 74 |
-
title="π AI CV Ranker (
|
| 75 |
-
description="Ranks uploaded CVs based on job relevance using
|
| 76 |
)
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
-
demo.launch()
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import fitz # PyMuPDF
|
| 4 |
import docx
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
+
from sentence_transformers import SentenceTransformer
|
| 7 |
+
|
| 8 |
+
# 1. Load a pretrained Sentence Transformer model locally
|
| 9 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
# ---- Text extraction ----
|
|
|
|
| 23 |
return ""
|
| 24 |
|
| 25 |
|
| 26 |
+
# ---- Local embedding helper ----
|
| 27 |
def get_embedding(text):
|
| 28 |
+
# Use the locally loaded model to generate embeddings
|
| 29 |
+
embedding = model.encode(text)
|
| 30 |
+
return np.array(embedding)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
# ---- CV ranking ----
|
|
|
|
| 64 |
gr.File(label="π Upload CVs (PDF/DOCX)", file_count="multiple", type="binary"),
|
| 65 |
],
|
| 66 |
outputs=gr.Markdown(),
|
| 67 |
+
title="π AI CV Ranker (Local Model)",
|
| 68 |
+
description="Ranks uploaded CVs based on job relevance using local SentenceTransformer model.",
|
| 69 |
)
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
+
demo.launch()
|
|
|
|
|
|