Spaces:
Sleeping
Sleeping
Download cv_analyzer.py from Nassira/completeness: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/spaces/Nassira/completeness/resolve/main/cv_analyzer.py
- Command line
-
hf download hf://spaces/Nassira/completeness/cv_analyzer.py
-
curl -L -o cv_analyzer.py https://huggingface.co/spaces/Nassira/completeness/resolve/main/cv_analyzer.py
2.08 kB
| import logging | |
| from ocr_utils import combine_ocr_results, extract_text_aws, extract_text_doctr, extract_text_easyocr, extract_text_paddleocr, load_models, detect_language | |
| from config import weights | |
| from completeness import check_cv_completeness | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| def detect_cv_sections(text): | |
| # Implement your section detection logic here | |
| # This is a placeholder implementation | |
| sections = ["Summary and objective", "Education", "Work Experience"] | |
| return {"present_sections": sections} | |
| def analyze_cv(file_path): | |
| try: | |
| # Detect language | |
| with open(file_path, 'rb') as f: | |
| image_bytes = f.read() | |
| language = detect_language(image_bytes) | |
| # Initialize OCR models | |
| doctr_model, easyocr_reader, paddleocr_reader = load_models(language) | |
| # Extract text using different OCR methods | |
| aws_result = extract_text_aws(image_bytes) | |
| doctr_result = extract_text_doctr(file_path, doctr_model) | |
| easyocr_result = extract_text_easyocr(file_path, easyocr_reader) | |
| paddleocr_result = extract_text_paddleocr(file_path, paddleocr_reader) | |
| # Combine OCR results | |
| results = { | |
| 'aws': aws_result, | |
| 'doctr': doctr_result, | |
| 'easyocr': easyocr_result, | |
| 'paddleocr': paddleocr_result | |
| } | |
| combined_text = combine_ocr_results(results, weights) | |
| # Detect CV sections | |
| sections_result = detect_cv_sections(combined_text) | |
| # Check CV completeness | |
| completeness_result = check_cv_completeness(sections_result, combined_text) | |
| # Combine results | |
| final_result = { | |
| "present_sections": sections_result["present_sections"], | |
| "completeness_analysis": completeness_result | |
| } | |
| return final_result | |
| except Exception as e: | |
| logging.error(f"Error in CV analysis: {str(e)}", exc_info=True) | |
| return {"error": str(e)} |