Nassira commited on
Commit
349be51
·
verified ·
1 Parent(s): 0ed9e64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import os
 
4
  from ocr_utils import (
5
  load_models,
6
  extract_text_aws,
@@ -10,24 +11,39 @@ from ocr_utils import (
10
  combine_ocr_results,
11
  detect_language,
12
  )
 
13
 
14
  # Load OCR weights from JSON file
15
- import json
16
- with open('weights_ocr.json', 'r') as f:
17
  weights = json.load(f)
18
 
19
  def main():
20
- st.title("CV Text Extraction and Combination")
 
21
  uploaded_file = st.file_uploader("Choose a CV image file", type=["png", "jpg", "jpeg"])
22
-
23
  if uploaded_file is not None:
24
  image = Image.open(uploaded_file)
25
  st.image(image, caption="Uploaded CV", use_column_width=True)
26
-
27
- with st.spinner('Detecting language and extracting text from CV...'):
 
28
  with open("temp_cv_image.png", "wb") as temp_file:
29
  temp_file.write(uploaded_file.getvalue())
30
-
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  aws_results = extract_text_aws(uploaded_file.getvalue())
32
  sample_text = ' '.join([item[0] for item in aws_results[:10]])
33
  detected_language = detect_language(sample_text)
@@ -40,11 +56,13 @@ def main():
40
  "easyocr": extract_text_easyocr("temp_cv_image.png", easyocr_reader),
41
  "paddleocr": extract_text_paddleocr("temp_cv_image.png", paddleocr_reader),
42
  }
43
-
44
  combined_text = combine_ocr_results(results, weights)
45
-
 
46
  st.text_area("Combined Text", combined_text, height=300)
47
-
 
48
  os.remove("temp_cv_image.png")
49
 
50
  if __name__ == "__main__":
 
1
  import streamlit as st
2
  from PIL import Image
3
  import os
4
+ import json
5
  from ocr_utils import (
6
  load_models,
7
  extract_text_aws,
 
11
  combine_ocr_results,
12
  detect_language,
13
  )
14
+ from cv_analyzer import analyze_cv
15
 
16
  # Load OCR weights from JSON file
17
+ with open('ocr_weights.json', 'r') as f:
 
18
  weights = json.load(f)
19
 
20
  def main():
21
+ st.title("CV Analysis and Text Extraction")
22
+
23
  uploaded_file = st.file_uploader("Choose a CV image file", type=["png", "jpg", "jpeg"])
24
+
25
  if uploaded_file is not None:
26
  image = Image.open(uploaded_file)
27
  st.image(image, caption="Uploaded CV", use_column_width=True)
28
+
29
+ with st.spinner('Analyzing CV...'):
30
+ # Save the uploaded file temporarily
31
  with open("temp_cv_image.png", "wb") as temp_file:
32
  temp_file.write(uploaded_file.getvalue())
33
+
34
+ # Analyze the CV
35
+ analysis_result = analyze_cv("temp_cv_image.png")
36
+
37
+ # Display the analysis results
38
+ st.subheader("CV Analysis Results")
39
+ st.write(f"Detected Sections: {', '.join(analysis_result['present_sections'])}")
40
+ st.write(f"CV Score: {analysis_result['score_sections']}")
41
+
42
+ # Display raw JSON output
43
+ st.subheader("Raw JSON Output")
44
+ st.json(analysis_result)
45
+
46
+ # Extract and combine text
47
  aws_results = extract_text_aws(uploaded_file.getvalue())
48
  sample_text = ' '.join([item[0] for item in aws_results[:10]])
49
  detected_language = detect_language(sample_text)
 
56
  "easyocr": extract_text_easyocr("temp_cv_image.png", easyocr_reader),
57
  "paddleocr": extract_text_paddleocr("temp_cv_image.png", paddleocr_reader),
58
  }
59
+
60
  combined_text = combine_ocr_results(results, weights)
61
+
62
+ st.subheader("Extracted Text")
63
  st.text_area("Combined Text", combined_text, height=300)
64
+
65
+ # Clean up the temporary file
66
  os.remove("temp_cv_image.png")
67
 
68
  if __name__ == "__main__":