Update app.py
Browse files
app.py
CHANGED
|
@@ -3,68 +3,29 @@ from PIL import Image
|
|
| 3 |
import logging
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
-
import
|
| 7 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
-
from functools import lru_cache
|
| 9 |
-
from cv_analyzer import detect_cv_sections_and_score
|
| 10 |
-
from ocr_utils import extract_text_aws, extract_text_doctr, extract_text_easyocr, extract_text_paddleocr, load_models, combine_ocr_results, detect_language
|
| 11 |
-
from config import weights
|
| 12 |
from spelling_grammar_checker import evaluate_cv_text
|
| 13 |
from personal_info_extractor import analyze_personal_info
|
| 14 |
|
| 15 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
@lru_cache(maxsize=32)
|
| 20 |
-
def cached_load_models(language):
|
| 21 |
-
return load_models(language)
|
| 22 |
-
|
| 23 |
-
async def process_ocr(image, image_bytes, language):
|
| 24 |
-
doctr_model, easyocr_reader, paddleocr_reader = cached_load_models(language)
|
| 25 |
-
|
| 26 |
-
tasks = [
|
| 27 |
-
executor.submit(extract_text_aws, image_bytes),
|
| 28 |
-
executor.submit(extract_text_doctr, image, doctr_model),
|
| 29 |
-
executor.submit(extract_text_easyocr, image, easyocr_reader),
|
| 30 |
-
executor.submit(extract_text_paddleocr, image, paddleocr_reader)
|
| 31 |
-
]
|
| 32 |
-
|
| 33 |
-
results = await asyncio.gather(*[asyncio.wrap_future(task) for task in tasks])
|
| 34 |
-
|
| 35 |
-
return {
|
| 36 |
-
"aws": results[0],
|
| 37 |
-
"doctr": results[1],
|
| 38 |
-
"easyocr": results[2],
|
| 39 |
-
"paddleocr": results[3]
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
async def main():
|
| 43 |
st.title("CV Text Extraction and Analysis")
|
| 44 |
uploaded_file = st.file_uploader("Choose a CV image file", type=["png", "jpg", "jpeg"])
|
| 45 |
|
| 46 |
if uploaded_file is not None:
|
| 47 |
image = Image.open(uploaded_file)
|
| 48 |
-
image_bytes = uploaded_file.getvalue()
|
| 49 |
-
|
| 50 |
with st.spinner('Processing CV...'):
|
| 51 |
try:
|
| 52 |
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
|
| 53 |
-
temp_file.write(
|
| 54 |
temp_file_path = temp_file.name
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
tasks = [
|
| 62 |
-
asyncio.to_thread(detect_cv_sections_and_score, combined_text),
|
| 63 |
-
asyncio.to_thread(analyze_personal_info, temp_file_path),
|
| 64 |
-
asyncio.to_thread(evaluate_cv_text, temp_file_path)
|
| 65 |
-
]
|
| 66 |
-
|
| 67 |
-
detection_result, personal_info, spelling_grammar_result = await asyncio.gather(*tasks)
|
| 68 |
|
| 69 |
total_score = (
|
| 70 |
detection_result["score_sections"] +
|
|
@@ -72,10 +33,6 @@ async def main():
|
|
| 72 |
spelling_grammar_result["score"]
|
| 73 |
)
|
| 74 |
|
| 75 |
-
# Display results (same as before)
|
| 76 |
-
st.subheader("Extracted Text")
|
| 77 |
-
st.text_area("", combined_text, height=300)
|
| 78 |
-
|
| 79 |
st.subheader("Detected CV Sections")
|
| 80 |
st.write(detection_result["present_sections"])
|
| 81 |
|
|
@@ -105,4 +62,4 @@ async def main():
|
|
| 105 |
st.error(f"An error occurred during processing: {str(e)}")
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
-
|
|
|
|
| 3 |
import logging
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
+
from cv_analyzer import analyze_cv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from spelling_grammar_checker import evaluate_cv_text
|
| 8 |
from personal_info_extractor import analyze_personal_info
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 11 |
|
| 12 |
+
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
st.title("CV Text Extraction and Analysis")
|
| 14 |
uploaded_file = st.file_uploader("Choose a CV image file", type=["png", "jpg", "jpeg"])
|
| 15 |
|
| 16 |
if uploaded_file is not None:
|
| 17 |
image = Image.open(uploaded_file)
|
|
|
|
|
|
|
| 18 |
with st.spinner('Processing CV...'):
|
| 19 |
try:
|
| 20 |
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
|
| 21 |
+
temp_file.write(uploaded_file.getvalue())
|
| 22 |
temp_file_path = temp_file.name
|
| 23 |
|
| 24 |
+
image_bytes = uploaded_file.getvalue()
|
| 25 |
|
| 26 |
+
detection_result = analyze_cv(temp_file_path, image_bytes)
|
| 27 |
+
personal_info = analyze_personal_info(temp_file_path)
|
| 28 |
+
spelling_grammar_result = evaluate_cv_text(temp_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
total_score = (
|
| 31 |
detection_result["score_sections"] +
|
|
|
|
| 33 |
spelling_grammar_result["score"]
|
| 34 |
)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
st.subheader("Detected CV Sections")
|
| 37 |
st.write(detection_result["present_sections"])
|
| 38 |
|
|
|
|
| 62 |
st.error(f"An error occurred during processing: {str(e)}")
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
+
main()
|