Spaces:
Configuration error
Configuration error
| """ | |
| gradio.py | |
| Functions for handling Gradio UI interactions and processing user inputs. | |
| """ | |
| import logging | |
| from functions.linkedin_resume import extract_text_from_linkedin_pdf | |
| from functions.github import get_github_repositories | |
| from functions.writer_agent import write_resume | |
| # Set up logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def process_inputs(linkedin_pdf, github_url, job_post_text, user_instructions): | |
| """ | |
| Process the input files and URLs from the Gradio interface. | |
| Args: | |
| linkedin_pdf: Uploaded LinkedIn resume export PDF file | |
| github_url (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 | |
| """ | |
| result = "" | |
| extraction_result = None | |
| logger.info("Processing user inputs from Gradio interface") | |
| # Process LinkedIn PDF file | |
| if linkedin_pdf is not None: | |
| result += "β LinkedIn Resume PDF uploaded\n" | |
| logger.info(f"Processing LinkedIn PDF: {linkedin_pdf.name}") | |
| # Extract and structure text from the PDF | |
| extraction_result = extract_text_from_linkedin_pdf(linkedin_pdf.name) | |
| if extraction_result["status"] == "success": | |
| result += " β Text extraction successful\n\n" | |
| logger.info("LinkedIn PDF text extraction successful") | |
| elif extraction_result["status"] == "warning": | |
| result += f" β οΈ Text extraction: {extraction_result['message']}\n\n" | |
| logger.warning(f"LinkedIn PDF extraction warning: {extraction_result['message']}") | |
| else: | |
| result += f" β Text extraction failed: {extraction_result['message']}\n\n" | |
| logger.error(f"LinkedIn PDF extraction failed: {extraction_result['message']}") | |
| else: | |
| result += "β No LinkedIn resume PDF file uploaded\n\n" | |
| logger.info("No LinkedIn PDF file provided") | |
| # Process GitHub profile | |
| if github_url and github_url.strip(): | |
| result += "β GitHub Profile URL provided\n" | |
| logger.info(f"Processing GitHub URL: {github_url}") | |
| # Retrieve repositories from GitHub | |
| github_result = get_github_repositories(github_url) | |
| if github_result["status"] == "success": | |
| result += " β GitHub list download successful\n\n" | |
| logger.info(f"GitHub repositories retrieved successfully for {github_result['metadata']['username']}") | |
| else: | |
| result += f" β GitHub extraction failed: {github_result['message']}\n\n" | |
| logger.error(f"GitHub extraction failed: {github_result['message']}") | |
| else: | |
| result += "β No GitHub profile URL provided\n\n" | |
| logger.info("No GitHub URL provided") | |
| # Process job post text | |
| if job_post_text and job_post_text.strip(): | |
| result += "β Job post text provided\n" | |
| logger.info(f"Job post text provided ({len(job_post_text)} characters)") | |
| else: | |
| result += "β Job post not provided\n" | |
| logger.info("No job post text provided") | |
| # Process user instructions | |
| if user_instructions and user_instructions.strip(): | |
| result += "β Additional instructions provided\n" | |
| logger.info(f"User instructions provided ({len(user_instructions)} characters)") | |
| 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 result | |
| if extraction_result and extraction_result.get("status") == "success": | |
| try: | |
| resume = write_resume(extraction_result, user_instructions) | |
| result += f"\nβ Resume generated successfully\n" | |
| logger.info("Resume generation completed successfully") | |
| except Exception as e: | |
| result += f"\nβ Resume generation failed: {str(e)}\n" | |
| logger.error(f"Resume generation failed: {str(e)}") | |
| else: | |
| result += f"\nβ Cannot generate resume: No valid LinkedIn data extracted\n" | |
| result += "Please ensure you upload a valid LinkedIn PDF export file.\n" | |
| logger.warning("Resume generation skipped - no valid LinkedIn data available") | |
| return result | |
| def get_processed_data(linkedin_pdf, github_url, job_post_text, user_instructions): | |
| """ | |
| Get structured data from all inputs for further processing. | |
| Args: | |
| linkedin_pdf: Uploaded LinkedIn resume export PDF file | |
| github_url (str): GitHub profile URL | |
| job_post_text (str): Job post text content | |
| user_instructions (str): Additional instructions from the user | |
| Returns: | |
| dict: Structured data containing all processed information | |
| """ | |
| processed_data = { | |
| "linkedin": None, | |
| "github": None, | |
| "job_post": job_post_text.strip() if job_post_text and job_post_text.strip() else None, | |
| "user_instructions": user_instructions.strip() if user_instructions and user_instructions.strip() else None, | |
| "errors": [] | |
| } | |
| # Process LinkedIn PDF | |
| if linkedin_pdf is not None: | |
| extraction_result = extract_text_from_linkedin_pdf(linkedin_pdf.name) | |
| if extraction_result["status"] == "success": | |
| processed_data["linkedin"] = extraction_result | |
| else: | |
| processed_data["errors"].append(f"LinkedIn: {extraction_result['message']}") | |
| # Process GitHub profile | |
| if github_url and github_url.strip(): | |
| github_result = get_github_repositories(github_url) | |
| if github_result["status"] == "success": | |
| processed_data["github"] = github_result | |
| else: | |
| processed_data["errors"].append(f"GitHub: {github_result['message']}") | |
| return processed_data | |