Spaces:
Configuration error
Configuration error
File size: 4,324 Bytes
cb97851 146e731 f80cf2d f70c1ff de6bb68 55cf84d aa26954 cb97851 f9a80bc cb97851 5af784b e55b547 5af784b e55b547 5af784b de6bb68 5af784b cb97851 bef6750 cb97851 de6bb68 cb97851 edc4b6c bef6750 cb97851 5af784b de6bb68 f80cf2d 5af784b aa26954 5af784b aa26954 5af784b aa26954 5af784b aa26954 de6bb68 aa26954 de6bb68 aa26954 de6bb68 aa26954 de6bb68 55cf84d 5af784b 55cf84d 5af784b 55cf84d 5af784b 55cf84d 5af784b aa26954 5af784b aa26954 6d69b0b aa26954 6d69b0b 5af784b aa26954 b9464fb cb97851 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
"""
gradio.py
Functions for handling Gradio UI interactions and processing user inputs.
"""
import logging
from pathlib import Path
from functions.helper import clean_text_whitespace
from functions.linkedin_resume import extract_text
from functions.github import get_github_repositories
from functions.job_call import summarize_job_call
from functions.writer_agent import write_resume
# pylint: disable=broad-exception-caught
# Set up logging
# Create logs directory if it doesn't exist
logs_dir = Path(__file__).parent.parent / "logs"
logs_dir.mkdir(exist_ok=True)
# Strip extraneous handlers
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
# Configure logging to write to file and console
logging.basicConfig(
level=logging.INFO,
format='%(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(logs_dir / "gradio.log", mode='w'), # Log to file
logging.StreamHandler() # Also log to console
]
)
def process_inputs(
linkedin_pdf_path: str = None,
github_username: str = None,
job_post_text: str = None,
user_instructions: str = None
):
"""
Process the input files and URLs from the Gradio interface.
Args:
linkedin_pdf: (str) Path to uploaded LinkedIn resume export PDF file
github_username (str): GitHub profile URL
job_post_text (str): Job post text content
user_instructions (str): Additional instructions from the user
Returns:
str: Formatted output with file and URL information
"""
logger = logging.getLogger(f'{__name__}.process_inputs')
logger.info("LinkedIn PDF: %s", linkedin_pdf_path)
logger.info("GitHub username: %s", github_username)
logger.info("Job post: %s", clean_text_whitespace(job_post_text[:100]).replace("\n", " "))
logger.info("User instructions: %s", user_instructions[:100] if user_instructions else "None")
# ==================================================================== #
# Extract and structure text from the linkedin profile PDF
logger.info("Extracting text from LinkedIn PDF: %s", linkedin_pdf_path)
linkedin_resume = extract_text(linkedin_pdf_path)
if linkedin_resume:
logger.info("LinkedIn PDF text extraction successful")
else:
logger.error("LinkedIn PDF text extraction failed")
# ==================================================================== #
# Process GitHub profile
logger.info("Processing GitHub profile: %s", github_username.strip())
# Retrieve repositories from GitHub
github_repositories = get_github_repositories(github_username.strip())
if github_repositories:
logger.info("GitHub repositories retrieved successfully")
else:
logger.error("GitHub repositories retrieval failed")
# ==================================================================== #
# Process job post text
logger.info("Processing job post (%d characters)", len(job_post_text))
# Parse the job post text
job_post = summarize_job_call(job_post_text.strip())
if job_post:
logger.info("Job post parsed successfully")
else:
logger.error("Job post parsing failed")
# # ==================================================================== #
# # Process user instructions
# if user_instructions and user_instructions.strip():
# result += "✅ Additional instructions provided\n"
# logger.info("User instructions provided (%d characters)", len(user_instructions))
# else:
# result += "ℹ️ No additional instructions provided\n"
# logger.info("No additional instructions provided")
# logger.info("Input processing completed")
# ==================================================================== #
# Generate resume only if we have valid extraction results
result = None
if linkedin_resume and github_repositories and job_post:
logger.info("Generating resume with provided data")
try:
result = write_resume(linkedin_resume, github_repositories, job_post)
except Exception as e:
logger.error("Resume generation failed: %s", str(e))
else:
logger.warning("Resume generation skipped - content missing")
return result
|