Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,61 +2,46 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from semantic_search import CVSemanticSearch
|
| 4 |
import logging
|
| 5 |
-
import PyPDF2
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
# Set up logging
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
-
# Google Drive
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
# Global variable to store the search system
|
| 16 |
cv_search = None
|
|
|
|
| 17 |
|
| 18 |
def initialize_database():
|
| 19 |
"""
|
| 20 |
Initialize the database by loading CVs from Google Drive folder
|
| 21 |
This runs once when the space starts
|
| 22 |
"""
|
| 23 |
-
global cv_search
|
| 24 |
-
|
| 25 |
-
logger.info("Initializing CV Semantic Search system...")
|
| 26 |
-
cv_search = CVSemanticSearch()
|
| 27 |
-
|
| 28 |
-
logger.info("Loading CVs from Google Drive folder...")
|
| 29 |
-
successful, total = cv_search.load_cvs_from_google_drive(GOOGLE_DRIVE_FOLDER_URL)
|
| 30 |
-
|
| 31 |
-
if successful > 0:
|
| 32 |
-
logger.info(f"Successfully loaded {successful}/{total} CVs into database")
|
| 33 |
-
return f"β
Database initialized with {successful}/{total} CVs"
|
| 34 |
-
else:
|
| 35 |
-
logger.error("Failed to load any CVs from Google Drive")
|
| 36 |
-
return "β Failed to load CVs from Google Drive. Check the folder URL and permissions."
|
| 37 |
-
|
| 38 |
-
def extract_text_from_jd_file(file) -> str:
|
| 39 |
-
"""
|
| 40 |
-
Extract text from uploaded JD PDF file
|
| 41 |
|
| 42 |
-
Args:
|
| 43 |
-
file: Gradio file object
|
| 44 |
-
|
| 45 |
-
Returns:
|
| 46 |
-
Extracted text
|
| 47 |
-
"""
|
| 48 |
try:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
with open(file.name, 'rb') as f:
|
| 53 |
-
pdf_content = f.read()
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
def process_job_description(jd_text, jd_file):
|
| 62 |
"""
|
|
@@ -71,9 +56,15 @@ def process_job_description(jd_text, jd_file):
|
|
| 71 |
"""
|
| 72 |
# Priority: PDF file over text input
|
| 73 |
if jd_file is not None:
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Fallback to text input
|
| 79 |
if jd_text and jd_text.strip():
|
|
@@ -96,7 +87,7 @@ def search_matching_cvs(jd_text, jd_file, num_results):
|
|
| 96 |
global cv_search
|
| 97 |
|
| 98 |
if cv_search is None:
|
| 99 |
-
return "β System not initialized.
|
| 100 |
|
| 101 |
# Process job description
|
| 102 |
job_description = process_job_description(jd_text, jd_file)
|
|
@@ -108,41 +99,58 @@ def search_matching_cvs(jd_text, jd_file, num_results):
|
|
| 108 |
db_info = cv_search.get_database_info()
|
| 109 |
|
| 110 |
if db_info['unique_cvs'] == 0:
|
| 111 |
-
return "β No CVs in database.
|
| 112 |
|
| 113 |
# Perform search
|
| 114 |
results = cv_search.search_cvs(job_description, top_k=num_results)
|
| 115 |
|
| 116 |
if not results:
|
| 117 |
-
return "β No matching CVs found. Try
|
| 118 |
|
| 119 |
# Format results
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
for i, cv in enumerate(results, 1):
|
| 124 |
similarity_percentage = cv['weighted_score'] * 100
|
| 125 |
|
| 126 |
-
# Determine match quality
|
| 127 |
if similarity_percentage >= 80:
|
| 128 |
match_quality = "π’ Excellent Match"
|
|
|
|
| 129 |
elif similarity_percentage >= 65:
|
| 130 |
match_quality = "π‘ Good Match"
|
|
|
|
| 131 |
elif similarity_percentage >= 50:
|
| 132 |
match_quality = "π Fair Match"
|
|
|
|
| 133 |
else:
|
| 134 |
match_quality = "π΄ Weak Match"
|
|
|
|
| 135 |
|
| 136 |
output += f"""
|
| 137 |
-
### {i}. {cv['filename']}
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
**
|
| 140 |
-
- **Best Match Score**: {cv['max_similarity']*100:.1f}%
|
| 141 |
-
- **Average Score**: {cv['avg_similarity']*100:.1f}%
|
| 142 |
-
- **Sections Analyzed**: {cv['chunk_count']} parts
|
| 143 |
|
| 144 |
-
**
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
---
|
| 148 |
"""
|
|
@@ -156,32 +164,46 @@ def get_system_status():
|
|
| 156 |
Returns:
|
| 157 |
System information as formatted string
|
| 158 |
"""
|
| 159 |
-
global cv_search
|
| 160 |
|
| 161 |
if cv_search is None:
|
| 162 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
db_info = cv_search.get_database_info()
|
| 165 |
|
| 166 |
if db_info['unique_cvs'] == 0:
|
| 167 |
-
return """
|
| 168 |
-
β οΈ
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
Please
|
| 171 |
-
- Google Drive folder
|
| 172 |
-
- Folder is
|
| 173 |
-
-
|
| 174 |
"""
|
| 175 |
|
| 176 |
return f"""
|
| 177 |
-
β
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
|
| 180 |
-
- **Total CVs Loaded**: {db_info['unique_cvs']}
|
| 181 |
-
- **Total Chunks**: {db_info['total_chunks']}
|
| 182 |
-
- **Average Chunks per CV**: {db_info['total_chunks'] / db_info['unique_cvs']:.1f}
|
| 183 |
|
| 184 |
-
π **
|
| 185 |
"""
|
| 186 |
|
| 187 |
# Create Gradio interface
|
|
@@ -192,94 +214,124 @@ def create_interface():
|
|
| 192 |
title="CV Semantic Search - Auto-loaded from Google Drive",
|
| 193 |
theme=gr.themes.Soft(),
|
| 194 |
css="""
|
| 195 |
-
.container { max-width:
|
| 196 |
-
.search-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
"""
|
| 204 |
) as demo:
|
| 205 |
|
| 206 |
-
gr.
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
with gr.
|
| 227 |
-
gr.
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
| 233 |
|
| 234 |
Example:
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
)
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
"""
|
| 270 |
-
## π Instructions:
|
| 271 |
-
1. **Enter Job Description**: Use text input or upload a PDF
|
| 272 |
-
2. **Click Search**: Find the best matching CVs from the database
|
| 273 |
-
3. **Review Results**: See ranked CVs with similarity scores
|
| 274 |
-
|
| 275 |
-
The system automatically analyzes semantic meaning, not just keywords!
|
| 276 |
-
""",
|
| 277 |
-
elem_classes=["results-section"]
|
| 278 |
-
)
|
| 279 |
-
|
| 280 |
-
# Refresh button for status
|
| 281 |
-
with gr.Row():
|
| 282 |
-
refresh_btn = gr.Button("π Refresh Status", size="sm")
|
| 283 |
|
| 284 |
# Event handlers
|
| 285 |
search_btn.click(
|
|
@@ -293,33 +345,35 @@ We are looking for a Senior Software Engineer with:
|
|
| 293 |
outputs=[status_display]
|
| 294 |
)
|
| 295 |
|
| 296 |
-
# Clear
|
| 297 |
jd_file.change(
|
| 298 |
-
fn=lambda: "",
|
| 299 |
outputs=[jd_text]
|
| 300 |
)
|
| 301 |
|
| 302 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
gr.Markdown("""
|
| 304 |
---
|
| 305 |
-
##
|
| 306 |
|
| 307 |
-
- **
|
| 308 |
-
- **
|
| 309 |
-
- **
|
| 310 |
-
- **
|
|
|
|
| 311 |
|
| 312 |
-
###
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
### π‘ Pro Tips:
|
| 319 |
-
- Be specific about required skills and experience
|
| 320 |
-
- Include both technical and soft skill requirements
|
| 321 |
-
- Mention specific tools, technologies, or frameworks
|
| 322 |
-
- The more detailed your JD, the better the matching accuracy
|
| 323 |
""")
|
| 324 |
|
| 325 |
return demo
|
|
@@ -327,10 +381,13 @@ We are looking for a Senior Software Engineer with:
|
|
| 327 |
def main():
|
| 328 |
"""Main function to initialize and run the app"""
|
| 329 |
|
| 330 |
-
# Initialize database at startup
|
| 331 |
logger.info("Starting CV Semantic Search application...")
|
| 332 |
-
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
# Create and launch interface
|
| 336 |
demo = create_interface()
|
|
|
|
| 2 |
import os
|
| 3 |
from semantic_search import CVSemanticSearch
|
| 4 |
import logging
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Set up logging
|
| 7 |
logging.basicConfig(level=logging.INFO)
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
+
# Google Drive Configuration - UPDATE THESE VALUES
|
| 11 |
+
FOLDER_ID = "1j1faOlXxoYfPLdzDfGvDbtkENsRoDxXN" # Replace with your folder ID
|
| 12 |
+
API_KEY = os.getenv("YOUR_GOOGLE_DRIVE_API_KEY") # Replace with your API key
|
| 13 |
|
| 14 |
# Global variable to store the search system
|
| 15 |
cv_search = None
|
| 16 |
+
initialization_status = "Initializing..."
|
| 17 |
|
| 18 |
def initialize_database():
|
| 19 |
"""
|
| 20 |
Initialize the database by loading CVs from Google Drive folder
|
| 21 |
This runs once when the space starts
|
| 22 |
"""
|
| 23 |
+
global cv_search, initialization_status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
+
logger.info("Initializing CV Semantic Search system...")
|
| 27 |
+
cv_search = CVSemanticSearch()
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
logger.info("Loading CVs from Google Drive folder...")
|
| 30 |
+
successful, total = cv_search.load_cvs_from_google_drive(FOLDER_ID, API_KEY)
|
| 31 |
|
| 32 |
+
if successful > 0:
|
| 33 |
+
initialization_status = f"β
Successfully loaded {successful}/{total} CVs into database"
|
| 34 |
+
logger.info(initialization_status)
|
| 35 |
+
return True
|
| 36 |
+
else:
|
| 37 |
+
initialization_status = "β Failed to load any CVs from Google Drive. Check API key and folder ID."
|
| 38 |
+
logger.error(initialization_status)
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
except Exception as e:
|
| 42 |
+
initialization_status = f"β Error during initialization: {str(e)}"
|
| 43 |
+
logger.error(initialization_status)
|
| 44 |
+
return False
|
| 45 |
|
| 46 |
def process_job_description(jd_text, jd_file):
|
| 47 |
"""
|
|
|
|
| 56 |
"""
|
| 57 |
# Priority: PDF file over text input
|
| 58 |
if jd_file is not None:
|
| 59 |
+
try:
|
| 60 |
+
with open(jd_file.name, 'rb') as f:
|
| 61 |
+
pdf_content = f.read()
|
| 62 |
+
|
| 63 |
+
extracted_text = cv_search.extract_text_from_pdf_bytes(pdf_content)
|
| 64 |
+
if extracted_text.strip():
|
| 65 |
+
return extracted_text.strip()
|
| 66 |
+
except Exception as e:
|
| 67 |
+
logger.error(f"Error processing JD PDF: {str(e)}")
|
| 68 |
|
| 69 |
# Fallback to text input
|
| 70 |
if jd_text and jd_text.strip():
|
|
|
|
| 87 |
global cv_search
|
| 88 |
|
| 89 |
if cv_search is None:
|
| 90 |
+
return f"β System not initialized properly.\n\n{initialization_status}\n\nPlease refresh the page or check the configuration."
|
| 91 |
|
| 92 |
# Process job description
|
| 93 |
job_description = process_job_description(jd_text, jd_file)
|
|
|
|
| 99 |
db_info = cv_search.get_database_info()
|
| 100 |
|
| 101 |
if db_info['unique_cvs'] == 0:
|
| 102 |
+
return f"β No CVs in database.\n\n{initialization_status}"
|
| 103 |
|
| 104 |
# Perform search
|
| 105 |
results = cv_search.search_cvs(job_description, top_k=num_results)
|
| 106 |
|
| 107 |
if not results:
|
| 108 |
+
return "β No matching CVs found. Try using different keywords or requirements in your job description."
|
| 109 |
|
| 110 |
# Format results
|
| 111 |
+
jd_preview = job_description[:150] + "..." if len(job_description) > 150 else job_description
|
| 112 |
+
|
| 113 |
+
output = f"""## π― Top {len(results)} Matching CVs
|
| 114 |
+
|
| 115 |
+
**Job Description**: {jd_preview}
|
| 116 |
+
|
| 117 |
+
**Search Results**:
|
| 118 |
+
|
| 119 |
+
"""
|
| 120 |
|
| 121 |
for i, cv in enumerate(results, 1):
|
| 122 |
similarity_percentage = cv['weighted_score'] * 100
|
| 123 |
|
| 124 |
+
# Determine match quality and emoji
|
| 125 |
if similarity_percentage >= 80:
|
| 126 |
match_quality = "π’ Excellent Match"
|
| 127 |
+
quality_color = "#28a745"
|
| 128 |
elif similarity_percentage >= 65:
|
| 129 |
match_quality = "π‘ Good Match"
|
| 130 |
+
quality_color = "#ffc107"
|
| 131 |
elif similarity_percentage >= 50:
|
| 132 |
match_quality = "π Fair Match"
|
| 133 |
+
quality_color = "#fd7e14"
|
| 134 |
else:
|
| 135 |
match_quality = "π΄ Weak Match"
|
| 136 |
+
quality_color = "#dc3545"
|
| 137 |
|
| 138 |
output += f"""
|
| 139 |
+
### {i}. **{cv['filename']}**
|
| 140 |
+
|
| 141 |
+
<div style="background: linear-gradient(90deg, {quality_color}22, transparent); padding: 15px; border-radius: 8px; border-left: 4px solid {quality_color};">
|
| 142 |
|
| 143 |
+
**{match_quality}** - **{similarity_percentage:.1f}% Overall Match**
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
π **Detailed Scores:**
|
| 146 |
+
- Best Section Match: {cv['max_similarity']*100:.1f}%
|
| 147 |
+
- Average Match: {cv['avg_similarity']*100:.1f}%
|
| 148 |
+
- CV Sections Analyzed: {cv['chunk_count']}
|
| 149 |
+
|
| 150 |
+
π‘ **Why This CV Matches:**
|
| 151 |
+
*"{cv['best_match_text']}"*
|
| 152 |
+
|
| 153 |
+
</div>
|
| 154 |
|
| 155 |
---
|
| 156 |
"""
|
|
|
|
| 164 |
Returns:
|
| 165 |
System information as formatted string
|
| 166 |
"""
|
| 167 |
+
global cv_search, initialization_status
|
| 168 |
|
| 169 |
if cv_search is None:
|
| 170 |
+
return f"""
|
| 171 |
+
## β οΈ System Status: Not Ready
|
| 172 |
+
|
| 173 |
+
{initialization_status}
|
| 174 |
+
|
| 175 |
+
**Possible Issues:**
|
| 176 |
+
- Invalid Google Drive API key
|
| 177 |
+
- Incorrect folder ID
|
| 178 |
+
- Folder is not public
|
| 179 |
+
- No PDF files in the folder
|
| 180 |
+
"""
|
| 181 |
|
| 182 |
db_info = cv_search.get_database_info()
|
| 183 |
|
| 184 |
if db_info['unique_cvs'] == 0:
|
| 185 |
+
return f"""
|
| 186 |
+
## β οΈ System Status: No CVs Loaded
|
| 187 |
+
|
| 188 |
+
{initialization_status}
|
| 189 |
|
| 190 |
+
**Please Check:**
|
| 191 |
+
- Google Drive folder contains PDF files
|
| 192 |
+
- Folder is publicly accessible
|
| 193 |
+
- API key has proper permissions
|
| 194 |
"""
|
| 195 |
|
| 196 |
return f"""
|
| 197 |
+
## β
System Status: Ready for Search
|
| 198 |
+
|
| 199 |
+
π **Database Statistics:**
|
| 200 |
+
- **CVs Loaded**: {db_info['unique_cvs']} resumes
|
| 201 |
+
- **Text Chunks**: {db_info['total_chunks']} searchable segments
|
| 202 |
+
- **Avg Chunks per CV**: {db_info['total_chunks'] / db_info['unique_cvs']:.1f}
|
| 203 |
|
| 204 |
+
π€ **AI Model**: Sentence Transformers (all-MiniLM-L6-v2)
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
π **Sample CVs**: {', '.join(db_info['cv_filenames'][:3])}{'...' if len(db_info['cv_filenames']) > 3 else ''}
|
| 207 |
"""
|
| 208 |
|
| 209 |
# Create Gradio interface
|
|
|
|
| 214 |
title="CV Semantic Search - Auto-loaded from Google Drive",
|
| 215 |
theme=gr.themes.Soft(),
|
| 216 |
css="""
|
| 217 |
+
.main-container { max-width: 1200px; margin: auto; padding: 20px; }
|
| 218 |
+
.search-container {
|
| 219 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 220 |
+
color: white; padding: 30px; border-radius: 20px; margin: 20px 0;
|
| 221 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
| 222 |
+
}
|
| 223 |
+
.status-container {
|
| 224 |
+
background: #f8f9fa; padding: 25px; border-radius: 15px; margin: 20px 0;
|
| 225 |
+
border-left: 5px solid #007bff; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
| 226 |
+
}
|
| 227 |
+
.results-container {
|
| 228 |
+
background: #ffffff; padding: 25px; border-radius: 15px;
|
| 229 |
+
border: 1px solid #dee2e6; margin: 20px 0; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
| 230 |
+
}
|
| 231 |
+
.header { text-align: center; padding: 30px; background: linear-gradient(135deg, #74b9ff, #0984e3);
|
| 232 |
+
color: white; margin: -20px -20px 20px -20px; border-radius: 15px 15px 0 0; }
|
| 233 |
+
.tab-content { padding: 15px; }
|
| 234 |
"""
|
| 235 |
) as demo:
|
| 236 |
|
| 237 |
+
with gr.Column(elem_classes=["main-container"]):
|
| 238 |
+
|
| 239 |
+
gr.Markdown("""
|
| 240 |
+
<div class="header">
|
| 241 |
+
|
| 242 |
+
# π CV Semantic Search System
|
| 243 |
+
## AI-Powered Resume Matching
|
| 244 |
+
### *Automatically synced with Google Drive*
|
| 245 |
+
|
| 246 |
+
</div>
|
| 247 |
+
""")
|
| 248 |
+
|
| 249 |
+
# System Status Display
|
| 250 |
+
with gr.Row():
|
| 251 |
+
status_display = gr.Markdown(
|
| 252 |
+
get_system_status(),
|
| 253 |
+
elem_classes=["status-container"]
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# Main Search Interface
|
| 257 |
+
with gr.Row():
|
| 258 |
+
with gr.Column():
|
| 259 |
+
with gr.Group(elem_classes=["search-container"]):
|
| 260 |
+
gr.Markdown("## π Job Description Input")
|
| 261 |
+
|
| 262 |
+
with gr.Tab("π Text Input") as text_tab:
|
| 263 |
+
jd_text = gr.Textbox(
|
| 264 |
+
label="Paste Job Description",
|
| 265 |
+
placeholder="""Paste your job description here...
|
| 266 |
|
| 267 |
Example:
|
| 268 |
+
Senior Software Engineer Position
|
| 269 |
+
|
| 270 |
+
Requirements:
|
| 271 |
+
β’ 5+ years of experience in Python, JavaScript, and React
|
| 272 |
+
β’ Strong background in machine learning and AI
|
| 273 |
+
β’ Experience with cloud platforms (AWS, Azure, GCP)
|
| 274 |
+
β’ Knowledge of microservices and API development
|
| 275 |
+
β’ Bachelor's degree in Computer Science or related field
|
| 276 |
+
β’ Excellent problem-solving and communication skills
|
| 277 |
+
|
| 278 |
+
Responsibilities:
|
| 279 |
+
β’ Design and develop scalable web applications
|
| 280 |
+
β’ Lead technical projects and mentor junior developers
|
| 281 |
+
β’ Collaborate with cross-functional teams
|
| 282 |
+
β’ Implement best practices for code quality and testing""",
|
| 283 |
+
lines=12,
|
| 284 |
+
max_lines=20,
|
| 285 |
+
elem_classes=["tab-content"]
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
with gr.Tab("π PDF Upload") as pdf_tab:
|
| 289 |
+
jd_file = gr.File(
|
| 290 |
+
label="Upload Job Description PDF",
|
| 291 |
+
file_types=[".pdf"],
|
| 292 |
+
file_count="single",
|
| 293 |
+
elem_classes=["tab-content"]
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
with gr.Row():
|
| 297 |
+
num_results = gr.Slider(
|
| 298 |
+
label="Number of Top CVs to Return",
|
| 299 |
+
minimum=1,
|
| 300 |
+
maximum=10,
|
| 301 |
+
value=5,
|
| 302 |
+
step=1
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
search_btn = gr.Button(
|
| 306 |
+
"π Find Best Matching CVs",
|
| 307 |
+
variant="primary",
|
| 308 |
+
size="lg"
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
# Search Results
|
| 312 |
+
with gr.Row():
|
| 313 |
+
search_output = gr.Markdown(
|
| 314 |
+
"""
|
| 315 |
+
## π How to Use This System:
|
| 316 |
+
|
| 317 |
+
1. **Enter Job Requirements**: Use the text box or upload a PDF with your job description
|
| 318 |
+
2. **Click Search**: The AI will analyze semantic meaning and find the best matches
|
| 319 |
+
3. **Review Results**: See ranked CVs with detailed similarity scores and explanations
|
| 320 |
+
|
| 321 |
+
### π― What Makes This Special:
|
| 322 |
+
- **Semantic Understanding**: Finds relevant CVs even if they don't use exact keywords
|
| 323 |
+
- **Automatic Sync**: CVs are always up-to-date from your Google Drive folder
|
| 324 |
+
- **Smart Ranking**: Combines multiple similarity metrics for accurate results
|
| 325 |
+
- **Detailed Analysis**: Shows why each CV matches your requirements
|
| 326 |
+
|
| 327 |
+
*Enter a job description above to get started!*
|
| 328 |
+
""",
|
| 329 |
+
elem_classes=["results-container"]
|
| 330 |
)
|
| 331 |
+
|
| 332 |
+
# Refresh Status Button
|
| 333 |
+
with gr.Row():
|
| 334 |
+
refresh_btn = gr.Button("π Refresh System Status", size="sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
# Event handlers
|
| 337 |
search_btn.click(
|
|
|
|
| 345 |
outputs=[status_display]
|
| 346 |
)
|
| 347 |
|
| 348 |
+
# Clear text input when PDF is uploaded
|
| 349 |
jd_file.change(
|
| 350 |
+
fn=lambda: "",
|
| 351 |
outputs=[jd_text]
|
| 352 |
)
|
| 353 |
|
| 354 |
+
# Clear file input when text is entered
|
| 355 |
+
jd_text.change(
|
| 356 |
+
fn=lambda x: None if x.strip() else None,
|
| 357 |
+
inputs=[jd_text],
|
| 358 |
+
outputs=[jd_file]
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
# Footer
|
| 362 |
gr.Markdown("""
|
| 363 |
---
|
| 364 |
+
## π οΈ Technical Details
|
| 365 |
|
| 366 |
+
- **Vector Database**: ChromaDB (rebuilt on each restart)
|
| 367 |
+
- **Embedding Model**: SentenceTransformers all-MiniLM-L6-v2
|
| 368 |
+
- **Text Extraction**: pdfplumber + OCR fallback for scanned documents
|
| 369 |
+
- **CV Source**: Google Drive folder (automatically synced)
|
| 370 |
+
- **Search Algorithm**: Cosine similarity with chunk aggregation
|
| 371 |
|
| 372 |
+
### π Support
|
| 373 |
+
If no results appear, check that:
|
| 374 |
+
- Your Google Drive folder is public
|
| 375 |
+
- The folder contains PDF files
|
| 376 |
+
- Your API key is valid and has Drive API access
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
""")
|
| 378 |
|
| 379 |
return demo
|
|
|
|
| 381 |
def main():
|
| 382 |
"""Main function to initialize and run the app"""
|
| 383 |
|
|
|
|
| 384 |
logger.info("Starting CV Semantic Search application...")
|
| 385 |
+
|
| 386 |
+
# Initialize database at startup
|
| 387 |
+
if initialize_database():
|
| 388 |
+
logger.info("β
Database initialization successful")
|
| 389 |
+
else:
|
| 390 |
+
logger.error("β Database initialization failed")
|
| 391 |
|
| 392 |
# Create and launch interface
|
| 393 |
demo = create_interface()
|