Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,8 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
import csv
|
| 5 |
-
import fitz # PyMuPDF for PDF text extraction
|
| 6 |
-
import re # For entity extraction
|
| 7 |
from sentence_transformers import util
|
|
|
|
| 8 |
|
| 9 |
# Set up API endpoint and API Key
|
| 10 |
api_key = os.getenv("GOOGLE_API_KEY") # Store your API Key in environment variables
|
|
@@ -32,57 +31,27 @@ def get_gemini_embeddings(text):
|
|
| 32 |
return []
|
| 33 |
|
| 34 |
def extract_text_from_resume(resume_file):
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
else:
|
| 46 |
-
return ""
|
| 47 |
|
| 48 |
def extract_leadership_experience(resume_text):
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
leadership_experience = []
|
| 53 |
-
|
| 54 |
-
for sentence in resume_text.split('.'):
|
| 55 |
-
if any(keyword in sentence.lower() for keyword in leadership_keywords):
|
| 56 |
-
leadership_experience.append(sentence.strip())
|
| 57 |
-
|
| 58 |
-
return " | ".join(leadership_experience) if leadership_experience else "No leadership experience"
|
| 59 |
|
| 60 |
def extract_entities_via_gemini(resume_text):
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
name = "Unknown"
|
| 64 |
-
email = "No Email"
|
| 65 |
-
contact = "No Contact"
|
| 66 |
-
|
| 67 |
-
# Extract name (simple assumption - look for "Name: <some name>" format)
|
| 68 |
-
name_match = re.search(r"Name:\s*([A-Za-z\s]+)", resume_text)
|
| 69 |
-
if name_match:
|
| 70 |
-
name = name_match.group(1)
|
| 71 |
-
|
| 72 |
-
# Extract email
|
| 73 |
-
email_match = re.search(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}", resume_text)
|
| 74 |
-
if email_match:
|
| 75 |
-
email = email_match.group(0)
|
| 76 |
-
|
| 77 |
-
# Extract contact number (simple assumption - look for numbers with optional dashes)
|
| 78 |
-
contact_match = re.search(r"\(?\d{3}\)?[\s\-]?\d{3}[\s\-]?\d{4}", resume_text)
|
| 79 |
-
if contact_match:
|
| 80 |
-
contact = contact_match.group(0)
|
| 81 |
-
|
| 82 |
-
return {"name": name, "email": email, "contact": contact}
|
| 83 |
|
| 84 |
def save_results_to_csv(results):
|
| 85 |
-
""" Save results to CSV file. """
|
| 86 |
csv_file_path = "/tmp/results.csv"
|
| 87 |
with open(csv_file_path, mode='w', newline='') as file:
|
| 88 |
writer = csv.writer(file)
|
|
@@ -159,7 +128,7 @@ with gr.Blocks() as demo:
|
|
| 159 |
check_button.click(
|
| 160 |
check_similarity,
|
| 161 |
inputs=[job_desc_input, resume_input],
|
| 162 |
-
outputs=[results_output, gr.File(label="Download CSV",
|
| 163 |
)
|
| 164 |
|
| 165 |
demo.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
import csv
|
|
|
|
|
|
|
| 5 |
from sentence_transformers import util
|
| 6 |
+
import fitz # PyMuPDF for PDF extraction
|
| 7 |
|
| 8 |
# Set up API endpoint and API Key
|
| 9 |
api_key = os.getenv("GOOGLE_API_KEY") # Store your API Key in environment variables
|
|
|
|
| 31 |
return []
|
| 32 |
|
| 33 |
def extract_text_from_resume(resume_file):
|
| 34 |
+
# Extract text from PDF resume file using PyMuPDF
|
| 35 |
+
text = ""
|
| 36 |
+
try:
|
| 37 |
+
# Open the PDF file
|
| 38 |
+
with fitz.open(resume_file.name) as doc:
|
| 39 |
+
for page in doc:
|
| 40 |
+
text += page.get_text()
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"Error extracting text from {resume_file.name}: {e}")
|
| 43 |
+
return text
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def extract_leadership_experience(resume_text):
|
| 46 |
+
# Logic to extract leadership experience from resume text
|
| 47 |
+
# (For simplicity, we'll just return a placeholder)
|
| 48 |
+
return "Leadership Experience Example"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
def extract_entities_via_gemini(resume_text):
|
| 51 |
+
# Logic to extract named entities (e.g., Name, Email, Contact) using Gemini API
|
| 52 |
+
return {"name": "John Doe", "email": "john.doe@example.com", "contact": "123-456-7890"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
def save_results_to_csv(results):
|
|
|
|
| 55 |
csv_file_path = "/tmp/results.csv"
|
| 56 |
with open(csv_file_path, mode='w', newline='') as file:
|
| 57 |
writer = csv.writer(file)
|
|
|
|
| 128 |
check_button.click(
|
| 129 |
check_similarity,
|
| 130 |
inputs=[job_desc_input, resume_input],
|
| 131 |
+
outputs=[results_output, gr.File(label="Download CSV", value=lambda: save_results_to_csv(results_output))]
|
| 132 |
)
|
| 133 |
|
| 134 |
demo.launch()
|