DevNumb commited on
Commit
c519b34
Β·
verified Β·
1 Parent(s): 8b313a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
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
- HF_TOKEN = os.getenv("HF_TOKEN")
8
- API_URL = "https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2/pipeline/sentence-similarity"
9
- headers = {
10
- "Authorization": f"Bearer {os.environ['HF_TOKEN']}",
11
- }
12
 
13
 
14
  # ---- Text extraction ----
@@ -25,16 +23,11 @@ def extract_text(file):
25
  return ""
26
 
27
 
28
- # ---- API embedding helper ----
29
  def get_embedding(text):
30
- payload = {"inputs": text}
31
- resp = requests.post(API_URL, headers=headers, json=payload, timeout=60)
32
- data = resp.json()
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 (API-powered)",
75
- description="Ranks uploaded CVs based on job relevance using Hugging Face API.",
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()