Spaces:
Configuration error
Configuration error
""" | |
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, | |
): | |
""" | |
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 | |
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", " ")) | |
# ==================================================================== # | |
# 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") | |
# ==================================================================== # | |
# Generate resume only if we have valid extraction results | |
result = "" | |
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)) | |
result = "" | |
else: | |
logger.warning("Resume generation skipped - content missing") | |
return result | |