Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,11 +7,9 @@ if sys.version_info >= (3, 13):
|
|
| 7 |
try:
|
| 8 |
import audioop
|
| 9 |
except ImportError:
|
| 10 |
-
# Create a dummy audioop module
|
| 11 |
import types
|
| 12 |
audioop = types.ModuleType('audioop')
|
| 13 |
sys.modules['audioop'] = audioop
|
| 14 |
-
# Add minimal required functions
|
| 15 |
for func in ['add', 'adpcm2lin', 'adpcm32lin', 'alaw2lin', 'avg', 'avgpp',
|
| 16 |
'bias', 'cross', 'findfactor', 'findfit', 'findmax', 'getsample',
|
| 17 |
'lin2adpcm', 'lin2alaw', 'lin2ulaw', 'max', 'maxpp', 'mul', 'ratecv',
|
|
@@ -32,11 +30,9 @@ import smtplib
|
|
| 32 |
from email.mime.text import MIMEText
|
| 33 |
from email.mime.multipart import MIMEMultipart
|
| 34 |
from typing import Literal, Tuple, Dict, Optional
|
| 35 |
-
import tempfile
|
| 36 |
import traceback
|
| 37 |
-
from pathlib import Path
|
| 38 |
|
| 39 |
-
# Import Agno components
|
| 40 |
try:
|
| 41 |
from phi.agent import Agent
|
| 42 |
from phi.model.google import Gemini
|
|
@@ -47,7 +43,16 @@ except ImportError:
|
|
| 47 |
from agno.models.google import Gemini
|
| 48 |
from agno.utils.log import logger
|
| 49 |
except ImportError:
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
class CustomZoomTool:
|
| 53 |
def __init__(self, *, account_id: Optional[str] = None, client_id: Optional[str] = None,
|
|
@@ -81,31 +86,22 @@ class CustomZoomTool:
|
|
| 81 |
timeout=30
|
| 82 |
)
|
| 83 |
|
| 84 |
-
logger.info(f"Zoom token request status: {response.status_code}")
|
| 85 |
-
|
| 86 |
if response.status_code != 200:
|
| 87 |
logger.error(f"Zoom token request failed: {response.status_code} - {response.text}")
|
| 88 |
return ""
|
| 89 |
|
| 90 |
response.raise_for_status()
|
| 91 |
-
|
| 92 |
token_info = response.json()
|
| 93 |
self.access_token = token_info["access_token"]
|
| 94 |
expires_in = token_info["expires_in"]
|
| 95 |
self.token_expires_at = time.time() + expires_in - 60
|
| 96 |
-
|
| 97 |
-
logger.info("Zoom access token obtained successfully")
|
| 98 |
return str(self.access_token)
|
| 99 |
|
| 100 |
-
except
|
| 101 |
logger.error(f"Error fetching access token: {e}")
|
| 102 |
return ""
|
| 103 |
-
except KeyError as e:
|
| 104 |
-
logger.error(f"Missing key in token response: {e}")
|
| 105 |
-
return ""
|
| 106 |
|
| 107 |
def create_meeting(self, title: str, start_time: str, duration: int = 60, attendee_email: str = "") -> Dict:
|
| 108 |
-
"""Create a Zoom meeting"""
|
| 109 |
access_token = self.get_access_token()
|
| 110 |
if not access_token:
|
| 111 |
return {"error": "Could not get access token. Please check your Zoom credentials."}
|
|
@@ -139,16 +135,11 @@ class CustomZoomTool:
|
|
| 139 |
timeout=30
|
| 140 |
)
|
| 141 |
|
| 142 |
-
logger.info(f"Zoom meeting creation status: {response.status_code}")
|
| 143 |
-
|
| 144 |
if response.status_code != 201:
|
| 145 |
error_text = response.text
|
| 146 |
if "scopes" in error_text:
|
| 147 |
-
logger.error(f"Zoom app missing required scopes: {error_text}")
|
| 148 |
return {"error": f"Zoom app missing required scopes. Please add 'meeting:write:meeting' and 'meeting:write:meeting:admin' scopes to your Zoom app."}
|
| 149 |
-
|
| 150 |
-
logger.error(f"Zoom meeting creation failed: {response.status_code} - {error_text}")
|
| 151 |
-
return {"error": f"Meeting creation failed: {response.status_code} - {error_text}"}
|
| 152 |
|
| 153 |
response.raise_for_status()
|
| 154 |
meeting_info = response.json()
|
|
@@ -156,18 +147,13 @@ class CustomZoomTool:
|
|
| 156 |
if attendee_email:
|
| 157 |
self.add_attendee(meeting_info["id"], attendee_email)
|
| 158 |
|
| 159 |
-
logger.info(f"Zoom meeting created successfully: {meeting_info.get('id')}")
|
| 160 |
return meeting_info
|
| 161 |
|
| 162 |
-
except requests.RequestException as e:
|
| 163 |
-
logger.error(f"Error creating meeting: {e}")
|
| 164 |
-
return {"error": f"Network error creating meeting: {str(e)}"}
|
| 165 |
except Exception as e:
|
| 166 |
-
logger.error(f"
|
| 167 |
-
return {"error": f"
|
| 168 |
|
| 169 |
def add_attendee(self, meeting_id: str, email: str) -> bool:
|
| 170 |
-
"""Add an attendee to a meeting"""
|
| 171 |
access_token = self.get_access_token()
|
| 172 |
if not access_token:
|
| 173 |
return False
|
|
@@ -191,8 +177,7 @@ class CustomZoomTool:
|
|
| 191 |
)
|
| 192 |
response.raise_for_status()
|
| 193 |
return True
|
| 194 |
-
|
| 195 |
-
except requests.RequestException as e:
|
| 196 |
logger.error(f"Error adding attendee: {e}")
|
| 197 |
return False
|
| 198 |
|
|
@@ -231,7 +216,6 @@ class SessionState:
|
|
| 231 |
self.resume_text = ""
|
| 232 |
self.analysis_complete = False
|
| 233 |
self.is_selected = False
|
| 234 |
-
self.current_pdf_path = None
|
| 235 |
self.gemini_api_key = os.getenv("GEMINI_API_KEY", "")
|
| 236 |
self.zoom_account_id = os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 237 |
self.zoom_client_id = os.getenv("ZOOM_CLIENT_ID", "")
|
|
@@ -239,16 +223,15 @@ class SessionState:
|
|
| 239 |
self.email_sender = os.getenv("EMAIL_SENDER", "")
|
| 240 |
self.email_passkey = os.getenv("EMAIL_PASSKEY", "")
|
| 241 |
self.company_name = os.getenv("COMPANY_NAME", "AI Recruiting Team")
|
| 242 |
-
self.status_messages = []
|
| 243 |
|
| 244 |
session_state = SessionState()
|
| 245 |
|
| 246 |
-
def create_resume_analyzer()
|
| 247 |
-
"""Creates and returns a resume analysis agent."""
|
| 248 |
if not session_state.gemini_api_key:
|
| 249 |
return None
|
| 250 |
-
|
| 251 |
try:
|
|
|
|
|
|
|
| 252 |
return Agent(
|
| 253 |
model=Gemini(
|
| 254 |
id="gemini-2.0-flash",
|
|
@@ -268,8 +251,10 @@ def create_resume_analyzer() -> Optional[Agent]:
|
|
| 268 |
logger.error(f"Error creating resume analyzer: {e}")
|
| 269 |
return None
|
| 270 |
|
| 271 |
-
def create_email_agent()
|
| 272 |
try:
|
|
|
|
|
|
|
| 273 |
return Agent(
|
| 274 |
model=Gemini(
|
| 275 |
id="gemini-1.5-flash",
|
|
@@ -290,14 +275,15 @@ def create_email_agent() -> Optional[Agent]:
|
|
| 290 |
logger.error(f"Error creating email agent: {e}")
|
| 291 |
return None
|
| 292 |
|
| 293 |
-
def create_scheduler_agent()
|
| 294 |
try:
|
|
|
|
|
|
|
| 295 |
zoom_tools = CustomZoomTool(
|
| 296 |
account_id=session_state.zoom_account_id,
|
| 297 |
client_id=session_state.zoom_client_id,
|
| 298 |
client_secret=session_state.zoom_client_secret
|
| 299 |
)
|
| 300 |
-
|
| 301 |
return Agent(
|
| 302 |
name="Interview Scheduler",
|
| 303 |
model=Gemini(
|
|
@@ -321,7 +307,6 @@ def create_scheduler_agent() -> Optional[Agent]:
|
|
| 321 |
return None
|
| 322 |
|
| 323 |
def send_email(to_email: str, subject: str, body: str) -> tuple[bool, str]:
|
| 324 |
-
"""Send email using SMTP"""
|
| 325 |
try:
|
| 326 |
if not session_state.email_sender or not session_state.email_passkey:
|
| 327 |
return False, "Email credentials not configured properly"
|
|
@@ -330,22 +315,15 @@ def send_email(to_email: str, subject: str, body: str) -> tuple[bool, str]:
|
|
| 330 |
msg['From'] = session_state.email_sender
|
| 331 |
msg['To'] = to_email
|
| 332 |
msg['Subject'] = subject
|
| 333 |
-
|
| 334 |
msg.attach(MIMEText(body, 'plain'))
|
| 335 |
|
| 336 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
| 337 |
server.starttls()
|
| 338 |
server.login(session_state.email_sender, session_state.email_passkey)
|
| 339 |
-
|
| 340 |
text = msg.as_string()
|
| 341 |
server.sendmail(session_state.email_sender, to_email, text)
|
| 342 |
server.quit()
|
| 343 |
-
|
| 344 |
return True, f"Email sent successfully to {to_email}"
|
| 345 |
-
except smtplib.SMTPAuthenticationError as e:
|
| 346 |
-
return False, f"Email authentication failed. Please check your email and app password: {e}"
|
| 347 |
-
except smtplib.SMTPException as e:
|
| 348 |
-
return False, f"SMTP error occurred: {e}"
|
| 349 |
except Exception as e:
|
| 350 |
logger.error(f"Error sending email: {e}")
|
| 351 |
return False, f"Error sending email: {e}"
|
|
@@ -361,11 +339,7 @@ def extract_text_from_pdf(pdf_path) -> str:
|
|
| 361 |
except Exception as e:
|
| 362 |
return f"Error extracting PDF text: {str(e)}"
|
| 363 |
|
| 364 |
-
def analyze_resume(
|
| 365 |
-
resume_text: str,
|
| 366 |
-
role: Literal["ai_ml_engineer", "frontend_engineer", "backend_engineer"],
|
| 367 |
-
analyzer: Agent
|
| 368 |
-
) -> Tuple[bool, str]:
|
| 369 |
try:
|
| 370 |
response = analyzer.run(
|
| 371 |
f"""Please analyze this resume against the following requirements and provide your response in valid JSON format:
|
|
@@ -393,12 +367,9 @@ def analyze_resume(
|
|
| 393 |
IMPORTANT:
|
| 394 |
- Return ONLY the JSON object
|
| 395 |
- Do not include any markdown formatting, backticks, or explanatory text
|
| 396 |
-
- Make sure the JSON is valid and parseable
|
| 397 |
-
- Use boolean values (true/false) not strings
|
| 398 |
"""
|
| 399 |
)
|
| 400 |
|
| 401 |
-
# Handle response
|
| 402 |
assistant_message = None
|
| 403 |
if hasattr(response, 'messages'):
|
| 404 |
for msg in response.messages:
|
|
@@ -411,30 +382,23 @@ def analyze_resume(
|
|
| 411 |
if not assistant_message:
|
| 412 |
raise ValueError("No assistant message found in response.")
|
| 413 |
|
| 414 |
-
# Clean the response to extract JSON
|
| 415 |
content = assistant_message.strip()
|
| 416 |
-
|
| 417 |
if content.startswith('```json'):
|
| 418 |
content = content[7:]
|
| 419 |
if content.startswith('```'):
|
| 420 |
content = content[3:]
|
| 421 |
if content.endswith('```'):
|
| 422 |
content = content[:-3]
|
| 423 |
-
|
| 424 |
content = content.strip()
|
| 425 |
|
| 426 |
result = json.loads(content)
|
| 427 |
if not isinstance(result, dict) or not all(k in result for k in ["selected", "feedback"]):
|
| 428 |
raise ValueError("Invalid response format")
|
| 429 |
-
|
| 430 |
return result["selected"], result["feedback"]
|
| 431 |
-
|
| 432 |
-
except (json.JSONDecodeError, ValueError) as e:
|
| 433 |
-
return False, f"Resume analysis could not be completed due to parsing error: {str(e)}"
|
| 434 |
except Exception as e:
|
| 435 |
return False, f"Resume analysis failed: {str(e)}"
|
| 436 |
|
| 437 |
-
def send_selection_email(email_agent
|
| 438 |
try:
|
| 439 |
response = email_agent.run(
|
| 440 |
f"""
|
|
@@ -446,11 +410,9 @@ def send_selection_email(email_agent: Agent, to_email: str, role: str) -> tuple[
|
|
| 446 |
4. The name of the company is 'AI Recruiting Team'
|
| 447 |
5. Use all lowercase letters
|
| 448 |
6. End with exactly: 'best,\nthe ai recruiting team'
|
| 449 |
-
|
| 450 |
Return only the email body text, no subject line.
|
| 451 |
"""
|
| 452 |
)
|
| 453 |
-
|
| 454 |
email_content = None
|
| 455 |
if hasattr(response, 'messages'):
|
| 456 |
for msg in response.messages:
|
|
@@ -459,19 +421,13 @@ def send_selection_email(email_agent: Agent, to_email: str, role: str) -> tuple[
|
|
| 459 |
break
|
| 460 |
elif hasattr(response, 'content'):
|
| 461 |
email_content = response.content
|
| 462 |
-
|
| 463 |
if not email_content:
|
| 464 |
return False, "Could not generate email content"
|
| 465 |
-
|
| 466 |
-
return send_email(
|
| 467 |
-
to_email=to_email,
|
| 468 |
-
subject=f"congratulations! you've been selected for the {role} position",
|
| 469 |
-
body=email_content
|
| 470 |
-
)
|
| 471 |
except Exception as e:
|
| 472 |
return False, f"Error sending selection email: {str(e)}"
|
| 473 |
|
| 474 |
-
def send_rejection_email(email_agent
|
| 475 |
try:
|
| 476 |
response = email_agent.run(
|
| 477 |
f"""
|
|
@@ -482,16 +438,11 @@ def send_rejection_email(email_agent: Agent, to_email: str, role: str, feedback:
|
|
| 482 |
3. mention specific feedback from: {feedback}
|
| 483 |
4. encourage them to upskill and try again
|
| 484 |
5. suggest some learning resources based on missing skills
|
| 485 |
-
6. end the email with exactly:
|
| 486 |
-
best,
|
| 487 |
-
the ai recruiting team
|
| 488 |
-
|
| 489 |
Do not include any names in the signature.
|
| 490 |
-
The tone should be like a human writing a quick but thoughtful email.
|
| 491 |
Return only the email body text, no subject line.
|
| 492 |
"""
|
| 493 |
)
|
| 494 |
-
|
| 495 |
email_content = None
|
| 496 |
if hasattr(response, 'messages'):
|
| 497 |
for msg in response.messages:
|
|
@@ -500,23 +451,16 @@ def send_rejection_email(email_agent: Agent, to_email: str, role: str, feedback:
|
|
| 500 |
break
|
| 501 |
elif hasattr(response, 'content'):
|
| 502 |
email_content = response.content
|
| 503 |
-
|
| 504 |
if not email_content:
|
| 505 |
return False, "Could not generate email content"
|
| 506 |
-
|
| 507 |
-
return send_email(
|
| 508 |
-
to_email=to_email,
|
| 509 |
-
subject=f"update on your application for {role} position",
|
| 510 |
-
body=email_content
|
| 511 |
-
)
|
| 512 |
except Exception as e:
|
| 513 |
return False, f"Error sending rejection email: {str(e)}"
|
| 514 |
|
| 515 |
-
def schedule_interview(scheduler
|
| 516 |
try:
|
| 517 |
ist_tz = pytz.timezone('Asia/Kolkata')
|
| 518 |
current_time_ist = datetime.now(ist_tz)
|
| 519 |
-
|
| 520 |
tomorrow_ist = current_time_ist + timedelta(days=1)
|
| 521 |
interview_time = tomorrow_ist.replace(hour=11, minute=0, second=0, microsecond=0)
|
| 522 |
formatted_time = interview_time.strftime('%Y-%m-%dT%H:%M:%S')
|
|
@@ -535,20 +479,13 @@ def schedule_interview(scheduler: Agent, candidate_email: str, email_agent: Agen
|
|
| 535 |
)
|
| 536 |
|
| 537 |
if "error" in meeting_info:
|
| 538 |
-
error_msg = f"Could not create Zoom meeting automatically: {meeting_info['error']}"
|
| 539 |
-
if "scopes" in meeting_info['error']:
|
| 540 |
-
error_msg += "\nπ‘ **Fix:** Go to your Zoom app settings and add the required scopes:\n- `meeting:write:meeting`\n- `meeting:write:meeting:admin`\n- `user:read:admin`"
|
| 541 |
-
|
| 542 |
meeting_details = f"""
|
| 543 |
π
Interview Details:
|
| 544 |
- Meeting Title: {role} Technical Interview
|
| 545 |
- Date & Time: {interview_time.strftime('%B %d, %Y at %I:%M %p IST')}
|
| 546 |
- Duration: 60 minutes
|
| 547 |
-
|
| 548 |
Note: Zoom meeting link will be shared separately by our team.
|
| 549 |
Please be available at the scheduled time.
|
| 550 |
-
|
| 551 |
-
Please join the meeting 5 minutes early and be confident!
|
| 552 |
Time zone: IST (India Standard Time - UTC+5:30)
|
| 553 |
"""
|
| 554 |
else:
|
|
@@ -560,8 +497,7 @@ Time zone: IST (India Standard Time - UTC+5:30)
|
|
| 560 |
- Join URL: {meeting_info.get('join_url', 'N/A')}
|
| 561 |
- Meeting ID: {meeting_info.get('id', 'N/A')}
|
| 562 |
- Passcode: {meeting_info.get('password', 'N/A')}
|
| 563 |
-
|
| 564 |
-
Please join the meeting 5 minutes early and be confident!
|
| 565 |
Time zone: IST (India Standard Time - UTC+5:30)
|
| 566 |
"""
|
| 567 |
|
|
@@ -569,14 +505,12 @@ Time zone: IST (India Standard Time - UTC+5:30)
|
|
| 569 |
f"""Draft an interview confirmation email with these details:
|
| 570 |
- Role: {role} position
|
| 571 |
- Meeting Details: {meeting_details}
|
| 572 |
-
|
| 573 |
Important:
|
| 574 |
- Use all lowercase letters
|
| 575 |
- Clearly specify that the time is in IST (India Standard Time)
|
| 576 |
- Ask the candidate to join 5 minutes early
|
| 577 |
-
- Ask them to be confident and not nervous
|
| 578 |
- End with exactly: 'best,\nthe ai recruiting team'
|
| 579 |
-
|
| 580 |
Return only the email body text, no subject line.
|
| 581 |
"""
|
| 582 |
)
|
|
@@ -598,20 +532,15 @@ Time zone: IST (India Standard Time - UTC+5:30)
|
|
| 598 |
subject=f"interview details for {role} position",
|
| 599 |
body=email_content
|
| 600 |
)
|
| 601 |
-
|
| 602 |
if success:
|
| 603 |
-
return True, f"Interview scheduled successfully! Check your email for details.
|
| 604 |
else:
|
| 605 |
-
return False, f"
|
| 606 |
-
|
| 607 |
except Exception as e:
|
| 608 |
-
|
| 609 |
-
return False, f"Unable to schedule interview. Please try again. Error: {str(e)}"
|
| 610 |
|
| 611 |
-
# Gradio
|
| 612 |
def process_resume(file, role, email, gemini_key, zoom_account, zoom_client, zoom_secret, email_sender, email_pass, company):
|
| 613 |
-
"""Main processing function for Gradio"""
|
| 614 |
-
# Update session state
|
| 615 |
session_state.gemini_api_key = gemini_key or os.getenv("GEMINI_API_KEY", "")
|
| 616 |
session_state.zoom_account_id = zoom_account or os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 617 |
session_state.zoom_client_id = zoom_client or os.getenv("ZOOM_CLIENT_ID", "")
|
|
@@ -621,11 +550,9 @@ def process_resume(file, role, email, gemini_key, zoom_account, zoom_client, zoo
|
|
| 621 |
session_state.company_name = company or os.getenv("COMPANY_NAME", "AI Recruiting Team")
|
| 622 |
session_state.candidate_email = email
|
| 623 |
|
| 624 |
-
# Validate inputs
|
| 625 |
if not all([session_state.gemini_api_key, session_state.zoom_account_id,
|
| 626 |
session_state.zoom_client_id, session_state.zoom_client_secret,
|
| 627 |
-
session_state.email_sender, session_state.email_passkey
|
| 628 |
-
session_state.company_name]):
|
| 629 |
return "β Please configure all required settings in the Configuration tab first.", None, None, "", ""
|
| 630 |
|
| 631 |
if file is None:
|
|
@@ -635,48 +562,35 @@ def process_resume(file, role, email, gemini_key, zoom_account, zoom_client, zoo
|
|
| 635 |
return "β Please enter your email address.", None, None, "", ""
|
| 636 |
|
| 637 |
try:
|
| 638 |
-
# Extract text from PDF
|
| 639 |
resume_text = extract_text_from_pdf(file)
|
| 640 |
if not resume_text or "Error" in resume_text:
|
| 641 |
return f"β {resume_text}", None, None, "", ""
|
| 642 |
|
| 643 |
session_state.resume_text = resume_text
|
| 644 |
-
|
| 645 |
-
# Create analyzer
|
| 646 |
analyzer = create_resume_analyzer()
|
| 647 |
if analyzer is None:
|
| 648 |
return "β Failed to create resume analyzer. Please check your Gemini API key.", None, None, "", ""
|
| 649 |
|
| 650 |
-
# Create email agent for notifications
|
| 651 |
email_agent = create_email_agent()
|
| 652 |
if email_agent is None:
|
| 653 |
-
return "β Failed to create email agent.
|
| 654 |
|
| 655 |
-
# Analyze resume
|
| 656 |
is_selected, feedback = analyze_resume(resume_text, role, analyzer)
|
| 657 |
|
| 658 |
if is_selected:
|
| 659 |
session_state.analysis_complete = True
|
| 660 |
session_state.is_selected = True
|
| 661 |
-
|
| 662 |
-
# Send selection email
|
| 663 |
success, message = send_selection_email(email_agent, email, role)
|
| 664 |
email_status = f"β
Selection email sent!\n{message}" if success else f"β οΈ {message}"
|
| 665 |
-
|
| 666 |
return f"β
Congratulations! Your skills match our requirements.\n\nFeedback: {feedback}\n\n{email_status}", "Selected", feedback, "", "β
Application approved! Click 'Schedule Interview' to proceed."
|
| 667 |
else:
|
| 668 |
-
# Send rejection email
|
| 669 |
success, message = send_rejection_email(email_agent, email, role, feedback)
|
| 670 |
email_status = f"β
Rejection email sent!\n{message}" if success else f"β οΈ {message}"
|
| 671 |
-
|
| 672 |
return f"β Unfortunately, your skills don't match our requirements.\n\nFeedback: {feedback}\n\n{email_status}", "Rejected", feedback, "", ""
|
| 673 |
-
|
| 674 |
except Exception as e:
|
| 675 |
return f"β Error processing application: {str(e)}\n\n{traceback.format_exc()}", None, None, "", ""
|
| 676 |
|
| 677 |
def schedule_interview_gradio(role, email, gemini_key, zoom_account, zoom_client, zoom_secret, email_sender, email_pass, company):
|
| 678 |
-
"""Schedule interview function for Gradio"""
|
| 679 |
-
# Update session state
|
| 680 |
session_state.gemini_api_key = gemini_key or os.getenv("GEMINI_API_KEY", "")
|
| 681 |
session_state.zoom_account_id = zoom_account or os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 682 |
session_state.zoom_client_id = zoom_client or os.getenv("ZOOM_CLIENT_ID", "")
|
|
@@ -688,8 +602,7 @@ def schedule_interview_gradio(role, email, gemini_key, zoom_account, zoom_client
|
|
| 688 |
|
| 689 |
if not all([session_state.gemini_api_key, session_state.zoom_account_id,
|
| 690 |
session_state.zoom_client_id, session_state.zoom_client_secret,
|
| 691 |
-
session_state.email_sender, session_state.email_passkey
|
| 692 |
-
session_state.company_name]):
|
| 693 |
return "β Please configure all required settings in the Configuration tab first."
|
| 694 |
|
| 695 |
if not email:
|
|
@@ -702,56 +615,45 @@ def schedule_interview_gradio(role, email, gemini_key, zoom_account, zoom_client
|
|
| 702 |
email_agent = create_email_agent()
|
| 703 |
if email_agent is None:
|
| 704 |
return "β Failed to create email agent."
|
| 705 |
-
|
| 706 |
scheduler_agent = create_scheduler_agent()
|
| 707 |
if scheduler_agent is None:
|
| 708 |
return "β Failed to create scheduler agent."
|
| 709 |
-
|
| 710 |
success, message = schedule_interview(scheduler_agent, email, email_agent, role)
|
| 711 |
-
|
| 712 |
if success:
|
| 713 |
return f"β
Interview scheduled successfully!\n\n{message}"
|
| 714 |
else:
|
| 715 |
return f"β οΈ {message}"
|
| 716 |
-
|
| 717 |
except Exception as e:
|
| 718 |
return f"β Error scheduling interview: {str(e)}\n\n{traceback.format_exc()}"
|
| 719 |
|
| 720 |
def reset_application():
|
| 721 |
-
"""Reset the application state"""
|
| 722 |
session_state.candidate_email = ""
|
| 723 |
session_state.resume_text = ""
|
| 724 |
session_state.analysis_complete = False
|
| 725 |
session_state.is_selected = False
|
| 726 |
-
session_state.current_pdf_path = None
|
| 727 |
return "π Application reset successfully! You can start a new application.", "", "", "", ""
|
| 728 |
|
| 729 |
def test_email_config(email_sender_val, email_pass_val):
|
| 730 |
if not email_sender_val or not email_pass_val:
|
| 731 |
return "β Please fill in both Email Sender and Email App Password fields."
|
| 732 |
-
|
| 733 |
session_state.email_sender = email_sender_val
|
| 734 |
session_state.email_passkey = email_pass_val
|
| 735 |
-
|
| 736 |
success, message = send_email(
|
| 737 |
to_email=email_sender_val,
|
| 738 |
subject="Test Email from AI Recruitment System",
|
| 739 |
-
body="This is a test email to verify your email configuration
|
| 740 |
)
|
| 741 |
-
|
| 742 |
return f"{'β
' if success else 'β'} Test Result: {message}"
|
| 743 |
|
| 744 |
def test_zoom_config(zoom_account_val, zoom_client_val, zoom_secret_val):
|
| 745 |
if not all([zoom_account_val, zoom_client_val, zoom_secret_val]):
|
| 746 |
return "β Please fill in all Zoom configuration fields."
|
| 747 |
-
|
| 748 |
zoom_test = CustomZoomTool(
|
| 749 |
account_id=zoom_account_val,
|
| 750 |
client_id=zoom_client_val,
|
| 751 |
client_secret=zoom_secret_val
|
| 752 |
)
|
| 753 |
token = zoom_test.get_access_token()
|
| 754 |
-
|
| 755 |
if token:
|
| 756 |
return "β
Zoom authentication successful!"
|
| 757 |
else:
|
|
@@ -769,7 +671,6 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 769 |
""")
|
| 770 |
|
| 771 |
with gr.Tabs():
|
| 772 |
-
# Tab 1: Main Application
|
| 773 |
with gr.TabItem("π Application"):
|
| 774 |
with gr.Row():
|
| 775 |
with gr.Column(scale=2):
|
|
@@ -778,23 +679,19 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 778 |
label="Select Role",
|
| 779 |
value="ai_ml_engineer"
|
| 780 |
)
|
| 781 |
-
|
| 782 |
resume_file = gr.File(
|
| 783 |
label="Upload Resume (PDF)",
|
| 784 |
file_types=[".pdf"],
|
| 785 |
type="filepath"
|
| 786 |
)
|
| 787 |
-
|
| 788 |
email = gr.Textbox(
|
| 789 |
label="Candidate's Email Address",
|
| 790 |
placeholder="Enter your email address",
|
| 791 |
type="text"
|
| 792 |
)
|
| 793 |
-
|
| 794 |
with gr.Row():
|
| 795 |
analyze_btn = gr.Button("π Analyze Resume", variant="primary", size="lg")
|
| 796 |
reset_btn = gr.Button("π Reset Application", variant="secondary", size="lg")
|
| 797 |
-
|
| 798 |
status_output = gr.Textbox(
|
| 799 |
label="Status",
|
| 800 |
lines=10,
|
|
@@ -804,33 +701,11 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 804 |
|
| 805 |
with gr.Column(scale=1):
|
| 806 |
gr.Markdown("### π Role Requirements")
|
| 807 |
-
role_requirements = gr.Markdown(
|
| 808 |
-
|
| 809 |
-
)
|
| 810 |
-
|
| 811 |
-
result_status = gr.Textbox(
|
| 812 |
-
label="Application Result",
|
| 813 |
-
lines=2,
|
| 814 |
-
interactive=False,
|
| 815 |
-
visible=True
|
| 816 |
-
)
|
| 817 |
-
|
| 818 |
-
feedback_output = gr.Textbox(
|
| 819 |
-
label="Feedback Details",
|
| 820 |
-
lines=5,
|
| 821 |
-
interactive=False,
|
| 822 |
-
visible=True
|
| 823 |
-
)
|
| 824 |
-
|
| 825 |
-
interview_status_indicator = gr.Textbox(
|
| 826 |
-
label="Interview Status",
|
| 827 |
-
lines=3,
|
| 828 |
-
interactive=False,
|
| 829 |
-
value="",
|
| 830 |
-
visible=True
|
| 831 |
-
)
|
| 832 |
|
| 833 |
-
# Interview scheduling section
|
| 834 |
with gr.Row():
|
| 835 |
with gr.Column():
|
| 836 |
gr.Markdown("### π
Interview Scheduling")
|
|
@@ -842,7 +717,6 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 842 |
value="Schedule your interview after resume analysis..."
|
| 843 |
)
|
| 844 |
|
| 845 |
-
# Tab 2: Configuration
|
| 846 |
with gr.TabItem("βοΈ Configuration"):
|
| 847 |
gr.Markdown("""
|
| 848 |
### π API Configuration
|
|
@@ -910,7 +784,6 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 910 |
value="Click a test button to verify your configuration..."
|
| 911 |
)
|
| 912 |
|
| 913 |
-
# Tab 3: Help & Instructions
|
| 914 |
with gr.TabItem("π Help"):
|
| 915 |
gr.Markdown("""
|
| 916 |
## π How to Use the AI Recruitment System
|
|
@@ -937,31 +810,10 @@ with gr.Blocks(title="AI Recruitment System", theme=gr.themes.Soft()) as demo:
|
|
| 937 |
1. Click **Schedule Interview**
|
| 938 |
2. Check your email for the Zoom meeting details
|
| 939 |
3. Join the interview 5 minutes early
|
| 940 |
-
|
| 941 |
-
## π§ Troubleshooting
|
| 942 |
-
|
| 943 |
-
### Email Issues
|
| 944 |
-
- Make sure 2-Factor Authentication is enabled on Gmail
|
| 945 |
-
- Generate a new App Password (not your regular password)
|
| 946 |
-
- Check that the App Password is 16 characters
|
| 947 |
-
|
| 948 |
-
### Zoom Issues
|
| 949 |
-
- Ensure all required scopes are added to your Zoom app
|
| 950 |
-
- Activate the app after adding scopes
|
| 951 |
-
- Check that Account ID, Client ID, and Client Secret are correct
|
| 952 |
-
|
| 953 |
-
### API Issues
|
| 954 |
-
- Verify your Gemini API key is active
|
| 955 |
-
- Check your internet connection
|
| 956 |
-
- Ensure you have sufficient API quota
|
| 957 |
""")
|
| 958 |
|
| 959 |
# Event handlers
|
| 960 |
-
role.change(
|
| 961 |
-
fn=update_role_requirements,
|
| 962 |
-
inputs=role,
|
| 963 |
-
outputs=role_requirements
|
| 964 |
-
)
|
| 965 |
|
| 966 |
analyze_btn.click(
|
| 967 |
fn=process_resume,
|
|
|
|
| 7 |
try:
|
| 8 |
import audioop
|
| 9 |
except ImportError:
|
|
|
|
| 10 |
import types
|
| 11 |
audioop = types.ModuleType('audioop')
|
| 12 |
sys.modules['audioop'] = audioop
|
|
|
|
| 13 |
for func in ['add', 'adpcm2lin', 'adpcm32lin', 'alaw2lin', 'avg', 'avgpp',
|
| 14 |
'bias', 'cross', 'findfactor', 'findfit', 'findmax', 'getsample',
|
| 15 |
'lin2adpcm', 'lin2alaw', 'lin2ulaw', 'max', 'maxpp', 'mul', 'ratecv',
|
|
|
|
| 30 |
from email.mime.text import MIMEText
|
| 31 |
from email.mime.multipart import MIMEMultipart
|
| 32 |
from typing import Literal, Tuple, Dict, Optional
|
|
|
|
| 33 |
import traceback
|
|
|
|
| 34 |
|
| 35 |
+
# Import Agno components
|
| 36 |
try:
|
| 37 |
from phi.agent import Agent
|
| 38 |
from phi.model.google import Gemini
|
|
|
|
| 43 |
from agno.models.google import Gemini
|
| 44 |
from agno.utils.log import logger
|
| 45 |
except ImportError:
|
| 46 |
+
# Fallback to dummy logger
|
| 47 |
+
import logging
|
| 48 |
+
logger = logging.getLogger(__name__)
|
| 49 |
+
# Create dummy Agent class if needed
|
| 50 |
+
class Agent:
|
| 51 |
+
def __init__(self, *args, **kwargs):
|
| 52 |
+
pass
|
| 53 |
+
class Gemini:
|
| 54 |
+
def __init__(self, *args, **kwargs):
|
| 55 |
+
pass
|
| 56 |
|
| 57 |
class CustomZoomTool:
|
| 58 |
def __init__(self, *, account_id: Optional[str] = None, client_id: Optional[str] = None,
|
|
|
|
| 86 |
timeout=30
|
| 87 |
)
|
| 88 |
|
|
|
|
|
|
|
| 89 |
if response.status_code != 200:
|
| 90 |
logger.error(f"Zoom token request failed: {response.status_code} - {response.text}")
|
| 91 |
return ""
|
| 92 |
|
| 93 |
response.raise_for_status()
|
|
|
|
| 94 |
token_info = response.json()
|
| 95 |
self.access_token = token_info["access_token"]
|
| 96 |
expires_in = token_info["expires_in"]
|
| 97 |
self.token_expires_at = time.time() + expires_in - 60
|
|
|
|
|
|
|
| 98 |
return str(self.access_token)
|
| 99 |
|
| 100 |
+
except Exception as e:
|
| 101 |
logger.error(f"Error fetching access token: {e}")
|
| 102 |
return ""
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
def create_meeting(self, title: str, start_time: str, duration: int = 60, attendee_email: str = "") -> Dict:
|
|
|
|
| 105 |
access_token = self.get_access_token()
|
| 106 |
if not access_token:
|
| 107 |
return {"error": "Could not get access token. Please check your Zoom credentials."}
|
|
|
|
| 135 |
timeout=30
|
| 136 |
)
|
| 137 |
|
|
|
|
|
|
|
| 138 |
if response.status_code != 201:
|
| 139 |
error_text = response.text
|
| 140 |
if "scopes" in error_text:
|
|
|
|
| 141 |
return {"error": f"Zoom app missing required scopes. Please add 'meeting:write:meeting' and 'meeting:write:meeting:admin' scopes to your Zoom app."}
|
| 142 |
+
return {"error": f"Meeting creation failed: {response.status_code} - {error_text}"}
|
|
|
|
|
|
|
| 143 |
|
| 144 |
response.raise_for_status()
|
| 145 |
meeting_info = response.json()
|
|
|
|
| 147 |
if attendee_email:
|
| 148 |
self.add_attendee(meeting_info["id"], attendee_email)
|
| 149 |
|
|
|
|
| 150 |
return meeting_info
|
| 151 |
|
|
|
|
|
|
|
|
|
|
| 152 |
except Exception as e:
|
| 153 |
+
logger.error(f"Error creating meeting: {e}")
|
| 154 |
+
return {"error": f"Error creating meeting: {str(e)}"}
|
| 155 |
|
| 156 |
def add_attendee(self, meeting_id: str, email: str) -> bool:
|
|
|
|
| 157 |
access_token = self.get_access_token()
|
| 158 |
if not access_token:
|
| 159 |
return False
|
|
|
|
| 177 |
)
|
| 178 |
response.raise_for_status()
|
| 179 |
return True
|
| 180 |
+
except Exception as e:
|
|
|
|
| 181 |
logger.error(f"Error adding attendee: {e}")
|
| 182 |
return False
|
| 183 |
|
|
|
|
| 216 |
self.resume_text = ""
|
| 217 |
self.analysis_complete = False
|
| 218 |
self.is_selected = False
|
|
|
|
| 219 |
self.gemini_api_key = os.getenv("GEMINI_API_KEY", "")
|
| 220 |
self.zoom_account_id = os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 221 |
self.zoom_client_id = os.getenv("ZOOM_CLIENT_ID", "")
|
|
|
|
| 223 |
self.email_sender = os.getenv("EMAIL_SENDER", "")
|
| 224 |
self.email_passkey = os.getenv("EMAIL_PASSKEY", "")
|
| 225 |
self.company_name = os.getenv("COMPANY_NAME", "AI Recruiting Team")
|
|
|
|
| 226 |
|
| 227 |
session_state = SessionState()
|
| 228 |
|
| 229 |
+
def create_resume_analyzer():
|
|
|
|
| 230 |
if not session_state.gemini_api_key:
|
| 231 |
return None
|
|
|
|
| 232 |
try:
|
| 233 |
+
from phi.agent import Agent
|
| 234 |
+
from phi.model.google import Gemini
|
| 235 |
return Agent(
|
| 236 |
model=Gemini(
|
| 237 |
id="gemini-2.0-flash",
|
|
|
|
| 251 |
logger.error(f"Error creating resume analyzer: {e}")
|
| 252 |
return None
|
| 253 |
|
| 254 |
+
def create_email_agent():
|
| 255 |
try:
|
| 256 |
+
from phi.agent import Agent
|
| 257 |
+
from phi.model.google import Gemini
|
| 258 |
return Agent(
|
| 259 |
model=Gemini(
|
| 260 |
id="gemini-1.5-flash",
|
|
|
|
| 275 |
logger.error(f"Error creating email agent: {e}")
|
| 276 |
return None
|
| 277 |
|
| 278 |
+
def create_scheduler_agent():
|
| 279 |
try:
|
| 280 |
+
from phi.agent import Agent
|
| 281 |
+
from phi.model.google import Gemini
|
| 282 |
zoom_tools = CustomZoomTool(
|
| 283 |
account_id=session_state.zoom_account_id,
|
| 284 |
client_id=session_state.zoom_client_id,
|
| 285 |
client_secret=session_state.zoom_client_secret
|
| 286 |
)
|
|
|
|
| 287 |
return Agent(
|
| 288 |
name="Interview Scheduler",
|
| 289 |
model=Gemini(
|
|
|
|
| 307 |
return None
|
| 308 |
|
| 309 |
def send_email(to_email: str, subject: str, body: str) -> tuple[bool, str]:
|
|
|
|
| 310 |
try:
|
| 311 |
if not session_state.email_sender or not session_state.email_passkey:
|
| 312 |
return False, "Email credentials not configured properly"
|
|
|
|
| 315 |
msg['From'] = session_state.email_sender
|
| 316 |
msg['To'] = to_email
|
| 317 |
msg['Subject'] = subject
|
|
|
|
| 318 |
msg.attach(MIMEText(body, 'plain'))
|
| 319 |
|
| 320 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
| 321 |
server.starttls()
|
| 322 |
server.login(session_state.email_sender, session_state.email_passkey)
|
|
|
|
| 323 |
text = msg.as_string()
|
| 324 |
server.sendmail(session_state.email_sender, to_email, text)
|
| 325 |
server.quit()
|
|
|
|
| 326 |
return True, f"Email sent successfully to {to_email}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
except Exception as e:
|
| 328 |
logger.error(f"Error sending email: {e}")
|
| 329 |
return False, f"Error sending email: {e}"
|
|
|
|
| 339 |
except Exception as e:
|
| 340 |
return f"Error extracting PDF text: {str(e)}"
|
| 341 |
|
| 342 |
+
def analyze_resume(resume_text: str, role: str, analyzer) -> Tuple[bool, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
try:
|
| 344 |
response = analyzer.run(
|
| 345 |
f"""Please analyze this resume against the following requirements and provide your response in valid JSON format:
|
|
|
|
| 367 |
IMPORTANT:
|
| 368 |
- Return ONLY the JSON object
|
| 369 |
- Do not include any markdown formatting, backticks, or explanatory text
|
|
|
|
|
|
|
| 370 |
"""
|
| 371 |
)
|
| 372 |
|
|
|
|
| 373 |
assistant_message = None
|
| 374 |
if hasattr(response, 'messages'):
|
| 375 |
for msg in response.messages:
|
|
|
|
| 382 |
if not assistant_message:
|
| 383 |
raise ValueError("No assistant message found in response.")
|
| 384 |
|
|
|
|
| 385 |
content = assistant_message.strip()
|
|
|
|
| 386 |
if content.startswith('```json'):
|
| 387 |
content = content[7:]
|
| 388 |
if content.startswith('```'):
|
| 389 |
content = content[3:]
|
| 390 |
if content.endswith('```'):
|
| 391 |
content = content[:-3]
|
|
|
|
| 392 |
content = content.strip()
|
| 393 |
|
| 394 |
result = json.loads(content)
|
| 395 |
if not isinstance(result, dict) or not all(k in result for k in ["selected", "feedback"]):
|
| 396 |
raise ValueError("Invalid response format")
|
|
|
|
| 397 |
return result["selected"], result["feedback"]
|
|
|
|
|
|
|
|
|
|
| 398 |
except Exception as e:
|
| 399 |
return False, f"Resume analysis failed: {str(e)}"
|
| 400 |
|
| 401 |
+
def send_selection_email(email_agent, to_email: str, role: str) -> tuple[bool, str]:
|
| 402 |
try:
|
| 403 |
response = email_agent.run(
|
| 404 |
f"""
|
|
|
|
| 410 |
4. The name of the company is 'AI Recruiting Team'
|
| 411 |
5. Use all lowercase letters
|
| 412 |
6. End with exactly: 'best,\nthe ai recruiting team'
|
|
|
|
| 413 |
Return only the email body text, no subject line.
|
| 414 |
"""
|
| 415 |
)
|
|
|
|
| 416 |
email_content = None
|
| 417 |
if hasattr(response, 'messages'):
|
| 418 |
for msg in response.messages:
|
|
|
|
| 421 |
break
|
| 422 |
elif hasattr(response, 'content'):
|
| 423 |
email_content = response.content
|
|
|
|
| 424 |
if not email_content:
|
| 425 |
return False, "Could not generate email content"
|
| 426 |
+
return send_email(to_email, f"congratulations! you've been selected for the {role} position", email_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
except Exception as e:
|
| 428 |
return False, f"Error sending selection email: {str(e)}"
|
| 429 |
|
| 430 |
+
def send_rejection_email(email_agent, to_email: str, role: str, feedback: str) -> tuple[bool, str]:
|
| 431 |
try:
|
| 432 |
response = email_agent.run(
|
| 433 |
f"""
|
|
|
|
| 438 |
3. mention specific feedback from: {feedback}
|
| 439 |
4. encourage them to upskill and try again
|
| 440 |
5. suggest some learning resources based on missing skills
|
| 441 |
+
6. end the email with exactly: best,\nthe ai recruiting team
|
|
|
|
|
|
|
|
|
|
| 442 |
Do not include any names in the signature.
|
|
|
|
| 443 |
Return only the email body text, no subject line.
|
| 444 |
"""
|
| 445 |
)
|
|
|
|
| 446 |
email_content = None
|
| 447 |
if hasattr(response, 'messages'):
|
| 448 |
for msg in response.messages:
|
|
|
|
| 451 |
break
|
| 452 |
elif hasattr(response, 'content'):
|
| 453 |
email_content = response.content
|
|
|
|
| 454 |
if not email_content:
|
| 455 |
return False, "Could not generate email content"
|
| 456 |
+
return send_email(to_email, f"update on your application for {role} position", email_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
except Exception as e:
|
| 458 |
return False, f"Error sending rejection email: {str(e)}"
|
| 459 |
|
| 460 |
+
def schedule_interview(scheduler, candidate_email: str, email_agent, role: str) -> tuple[bool, str]:
|
| 461 |
try:
|
| 462 |
ist_tz = pytz.timezone('Asia/Kolkata')
|
| 463 |
current_time_ist = datetime.now(ist_tz)
|
|
|
|
| 464 |
tomorrow_ist = current_time_ist + timedelta(days=1)
|
| 465 |
interview_time = tomorrow_ist.replace(hour=11, minute=0, second=0, microsecond=0)
|
| 466 |
formatted_time = interview_time.strftime('%Y-%m-%dT%H:%M:%S')
|
|
|
|
| 479 |
)
|
| 480 |
|
| 481 |
if "error" in meeting_info:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
meeting_details = f"""
|
| 483 |
π
Interview Details:
|
| 484 |
- Meeting Title: {role} Technical Interview
|
| 485 |
- Date & Time: {interview_time.strftime('%B %d, %Y at %I:%M %p IST')}
|
| 486 |
- Duration: 60 minutes
|
|
|
|
| 487 |
Note: Zoom meeting link will be shared separately by our team.
|
| 488 |
Please be available at the scheduled time.
|
|
|
|
|
|
|
| 489 |
Time zone: IST (India Standard Time - UTC+5:30)
|
| 490 |
"""
|
| 491 |
else:
|
|
|
|
| 497 |
- Join URL: {meeting_info.get('join_url', 'N/A')}
|
| 498 |
- Meeting ID: {meeting_info.get('id', 'N/A')}
|
| 499 |
- Passcode: {meeting_info.get('password', 'N/A')}
|
| 500 |
+
Please join the meeting 5 minutes early and be confident!
|
|
|
|
| 501 |
Time zone: IST (India Standard Time - UTC+5:30)
|
| 502 |
"""
|
| 503 |
|
|
|
|
| 505 |
f"""Draft an interview confirmation email with these details:
|
| 506 |
- Role: {role} position
|
| 507 |
- Meeting Details: {meeting_details}
|
|
|
|
| 508 |
Important:
|
| 509 |
- Use all lowercase letters
|
| 510 |
- Clearly specify that the time is in IST (India Standard Time)
|
| 511 |
- Ask the candidate to join 5 minutes early
|
| 512 |
+
- Ask them to be confident and not nervous
|
| 513 |
- End with exactly: 'best,\nthe ai recruiting team'
|
|
|
|
| 514 |
Return only the email body text, no subject line.
|
| 515 |
"""
|
| 516 |
)
|
|
|
|
| 532 |
subject=f"interview details for {role} position",
|
| 533 |
body=email_content
|
| 534 |
)
|
|
|
|
| 535 |
if success:
|
| 536 |
+
return True, f"Interview scheduled successfully! Check your email for details."
|
| 537 |
else:
|
| 538 |
+
return False, f"Failed to send email notification: {message}"
|
|
|
|
| 539 |
except Exception as e:
|
| 540 |
+
return False, f"Unable to schedule interview: {str(e)}"
|
|
|
|
| 541 |
|
| 542 |
+
# Gradio Functions
|
| 543 |
def process_resume(file, role, email, gemini_key, zoom_account, zoom_client, zoom_secret, email_sender, email_pass, company):
|
|
|
|
|
|
|
| 544 |
session_state.gemini_api_key = gemini_key or os.getenv("GEMINI_API_KEY", "")
|
| 545 |
session_state.zoom_account_id = zoom_account or os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 546 |
session_state.zoom_client_id = zoom_client or os.getenv("ZOOM_CLIENT_ID", "")
|
|
|
|
| 550 |
session_state.company_name = company or os.getenv("COMPANY_NAME", "AI Recruiting Team")
|
| 551 |
session_state.candidate_email = email
|
| 552 |
|
|
|
|
| 553 |
if not all([session_state.gemini_api_key, session_state.zoom_account_id,
|
| 554 |
session_state.zoom_client_id, session_state.zoom_client_secret,
|
| 555 |
+
session_state.email_sender, session_state.email_passkey]):
|
|
|
|
| 556 |
return "β Please configure all required settings in the Configuration tab first.", None, None, "", ""
|
| 557 |
|
| 558 |
if file is None:
|
|
|
|
| 562 |
return "β Please enter your email address.", None, None, "", ""
|
| 563 |
|
| 564 |
try:
|
|
|
|
| 565 |
resume_text = extract_text_from_pdf(file)
|
| 566 |
if not resume_text or "Error" in resume_text:
|
| 567 |
return f"β {resume_text}", None, None, "", ""
|
| 568 |
|
| 569 |
session_state.resume_text = resume_text
|
|
|
|
|
|
|
| 570 |
analyzer = create_resume_analyzer()
|
| 571 |
if analyzer is None:
|
| 572 |
return "β Failed to create resume analyzer. Please check your Gemini API key.", None, None, "", ""
|
| 573 |
|
|
|
|
| 574 |
email_agent = create_email_agent()
|
| 575 |
if email_agent is None:
|
| 576 |
+
return "β Failed to create email agent.", None, None, "", ""
|
| 577 |
|
|
|
|
| 578 |
is_selected, feedback = analyze_resume(resume_text, role, analyzer)
|
| 579 |
|
| 580 |
if is_selected:
|
| 581 |
session_state.analysis_complete = True
|
| 582 |
session_state.is_selected = True
|
|
|
|
|
|
|
| 583 |
success, message = send_selection_email(email_agent, email, role)
|
| 584 |
email_status = f"β
Selection email sent!\n{message}" if success else f"β οΈ {message}"
|
|
|
|
| 585 |
return f"β
Congratulations! Your skills match our requirements.\n\nFeedback: {feedback}\n\n{email_status}", "Selected", feedback, "", "β
Application approved! Click 'Schedule Interview' to proceed."
|
| 586 |
else:
|
|
|
|
| 587 |
success, message = send_rejection_email(email_agent, email, role, feedback)
|
| 588 |
email_status = f"β
Rejection email sent!\n{message}" if success else f"β οΈ {message}"
|
|
|
|
| 589 |
return f"β Unfortunately, your skills don't match our requirements.\n\nFeedback: {feedback}\n\n{email_status}", "Rejected", feedback, "", ""
|
|
|
|
| 590 |
except Exception as e:
|
| 591 |
return f"β Error processing application: {str(e)}\n\n{traceback.format_exc()}", None, None, "", ""
|
| 592 |
|
| 593 |
def schedule_interview_gradio(role, email, gemini_key, zoom_account, zoom_client, zoom_secret, email_sender, email_pass, company):
|
|
|
|
|
|
|
| 594 |
session_state.gemini_api_key = gemini_key or os.getenv("GEMINI_API_KEY", "")
|
| 595 |
session_state.zoom_account_id = zoom_account or os.getenv("ZOOM_ACCOUNT_ID", "")
|
| 596 |
session_state.zoom_client_id = zoom_client or os.getenv("ZOOM_CLIENT_ID", "")
|
|
|
|
| 602 |
|
| 603 |
if not all([session_state.gemini_api_key, session_state.zoom_account_id,
|
| 604 |
session_state.zoom_client_id, session_state.zoom_client_secret,
|
| 605 |
+
session_state.email_sender, session_state.email_passkey]):
|
|
|
|
| 606 |
return "β Please configure all required settings in the Configuration tab first."
|
| 607 |
|
| 608 |
if not email:
|
|
|
|
| 615 |
email_agent = create_email_agent()
|
| 616 |
if email_agent is None:
|
| 617 |
return "β Failed to create email agent."
|
|
|
|
| 618 |
scheduler_agent = create_scheduler_agent()
|
| 619 |
if scheduler_agent is None:
|
| 620 |
return "β Failed to create scheduler agent."
|
|
|
|
| 621 |
success, message = schedule_interview(scheduler_agent, email, email_agent, role)
|
|
|
|
| 622 |
if success:
|
| 623 |
return f"β
Interview scheduled successfully!\n\n{message}"
|
| 624 |
else:
|
| 625 |
return f"β οΈ {message}"
|
|
|
|
| 626 |
except Exception as e:
|
| 627 |
return f"β Error scheduling interview: {str(e)}\n\n{traceback.format_exc()}"
|
| 628 |
|
| 629 |
def reset_application():
|
|
|
|
| 630 |
session_state.candidate_email = ""
|
| 631 |
session_state.resume_text = ""
|
| 632 |
session_state.analysis_complete = False
|
| 633 |
session_state.is_selected = False
|
|
|
|
| 634 |
return "π Application reset successfully! You can start a new application.", "", "", "", ""
|
| 635 |
|
| 636 |
def test_email_config(email_sender_val, email_pass_val):
|
| 637 |
if not email_sender_val or not email_pass_val:
|
| 638 |
return "β Please fill in both Email Sender and Email App Password fields."
|
|
|
|
| 639 |
session_state.email_sender = email_sender_val
|
| 640 |
session_state.email_passkey = email_pass_val
|
|
|
|
| 641 |
success, message = send_email(
|
| 642 |
to_email=email_sender_val,
|
| 643 |
subject="Test Email from AI Recruitment System",
|
| 644 |
+
body="This is a test email to verify your email configuration.\n\nbest,\nthe ai recruiting team"
|
| 645 |
)
|
|
|
|
| 646 |
return f"{'β
' if success else 'β'} Test Result: {message}"
|
| 647 |
|
| 648 |
def test_zoom_config(zoom_account_val, zoom_client_val, zoom_secret_val):
|
| 649 |
if not all([zoom_account_val, zoom_client_val, zoom_secret_val]):
|
| 650 |
return "β Please fill in all Zoom configuration fields."
|
|
|
|
| 651 |
zoom_test = CustomZoomTool(
|
| 652 |
account_id=zoom_account_val,
|
| 653 |
client_id=zoom_client_val,
|
| 654 |
client_secret=zoom_secret_val
|
| 655 |
)
|
| 656 |
token = zoom_test.get_access_token()
|
|
|
|
| 657 |
if token:
|
| 658 |
return "β
Zoom authentication successful!"
|
| 659 |
else:
|
|
|
|
| 671 |
""")
|
| 672 |
|
| 673 |
with gr.Tabs():
|
|
|
|
| 674 |
with gr.TabItem("π Application"):
|
| 675 |
with gr.Row():
|
| 676 |
with gr.Column(scale=2):
|
|
|
|
| 679 |
label="Select Role",
|
| 680 |
value="ai_ml_engineer"
|
| 681 |
)
|
|
|
|
| 682 |
resume_file = gr.File(
|
| 683 |
label="Upload Resume (PDF)",
|
| 684 |
file_types=[".pdf"],
|
| 685 |
type="filepath"
|
| 686 |
)
|
|
|
|
| 687 |
email = gr.Textbox(
|
| 688 |
label="Candidate's Email Address",
|
| 689 |
placeholder="Enter your email address",
|
| 690 |
type="text"
|
| 691 |
)
|
|
|
|
| 692 |
with gr.Row():
|
| 693 |
analyze_btn = gr.Button("π Analyze Resume", variant="primary", size="lg")
|
| 694 |
reset_btn = gr.Button("π Reset Application", variant="secondary", size="lg")
|
|
|
|
| 695 |
status_output = gr.Textbox(
|
| 696 |
label="Status",
|
| 697 |
lines=10,
|
|
|
|
| 701 |
|
| 702 |
with gr.Column(scale=1):
|
| 703 |
gr.Markdown("### π Role Requirements")
|
| 704 |
+
role_requirements = gr.Markdown(ROLE_REQUIREMENTS["ai_ml_engineer"])
|
| 705 |
+
result_status = gr.Textbox(label="Application Result", lines=2, interactive=False, visible=True)
|
| 706 |
+
feedback_output = gr.Textbox(label="Feedback Details", lines=5, interactive=False, visible=True)
|
| 707 |
+
interview_status_indicator = gr.Textbox(label="Interview Status", lines=3, interactive=False, value="", visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
|
|
|
|
| 709 |
with gr.Row():
|
| 710 |
with gr.Column():
|
| 711 |
gr.Markdown("### π
Interview Scheduling")
|
|
|
|
| 717 |
value="Schedule your interview after resume analysis..."
|
| 718 |
)
|
| 719 |
|
|
|
|
| 720 |
with gr.TabItem("βοΈ Configuration"):
|
| 721 |
gr.Markdown("""
|
| 722 |
### π API Configuration
|
|
|
|
| 784 |
value="Click a test button to verify your configuration..."
|
| 785 |
)
|
| 786 |
|
|
|
|
| 787 |
with gr.TabItem("π Help"):
|
| 788 |
gr.Markdown("""
|
| 789 |
## π How to Use the AI Recruitment System
|
|
|
|
| 810 |
1. Click **Schedule Interview**
|
| 811 |
2. Check your email for the Zoom meeting details
|
| 812 |
3. Join the interview 5 minutes early
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
""")
|
| 814 |
|
| 815 |
# Event handlers
|
| 816 |
+
role.change(fn=update_role_requirements, inputs=role, outputs=role_requirements)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
|
| 818 |
analyze_btn.click(
|
| 819 |
fn=process_resume,
|