Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +157 -70
Dockerfile
CHANGED
|
@@ -1,70 +1,157 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# libraries
|
| 2 |
+
from flask import Flask, render_template, request, redirect, url_for, flash, session, send_from_directory
|
| 3 |
+
import os
|
| 4 |
+
import logging
|
| 5 |
+
from utility.utils import extract_text_from_images, Data_Extractor, json_to_llm_str, process_extracted_text, process_resume_data
|
| 6 |
+
from backup.backup import NER_Model
|
| 7 |
+
from paddleocr import PaddleOCR
|
| 8 |
+
|
| 9 |
+
# Configure logging
|
| 10 |
+
logging.basicConfig(
|
| 11 |
+
level=logging.INFO,
|
| 12 |
+
handlers=[
|
| 13 |
+
logging.StreamHandler() # Remove FileHandler and log only to the console
|
| 14 |
+
]
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Flask App
|
| 18 |
+
app = Flask(__name__)
|
| 19 |
+
app.secret_key = 'your_secret_key'
|
| 20 |
+
app.config['UPLOAD_FOLDER'] = 'uploads/'
|
| 21 |
+
app.config['RESULT_FOLDER'] = 'uploads/'
|
| 22 |
+
|
| 23 |
+
UPLOAD_FOLDER = 'static/uploads/'
|
| 24 |
+
RESULT_FOLDER = 'static/results/'
|
| 25 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 26 |
+
os.makedirs(RESULT_FOLDER, exist_ok=True)
|
| 27 |
+
|
| 28 |
+
if not os.path.exists(app.config['UPLOAD_FOLDER']):
|
| 29 |
+
os.makedirs(app.config['UPLOAD_FOLDER'])
|
| 30 |
+
|
| 31 |
+
if not os.path.exists(app.config['RESULT_FOLDER']):
|
| 32 |
+
os.makedirs(app.config['RESULT_FOLDER'])
|
| 33 |
+
|
| 34 |
+
# Set the PaddleOCR home directory to a writable location
|
| 35 |
+
os.environ['PADDLEOCR_HOME'] = '/tmp/.paddleocr'
|
| 36 |
+
|
| 37 |
+
# Check if PaddleOCR home directory is writable
|
| 38 |
+
if not os.path.exists('/tmp/.paddleocr'):
|
| 39 |
+
os.makedirs('/tmp/.paddleocr', exist_ok=True)
|
| 40 |
+
logging.info("Created PaddleOCR home directory.")
|
| 41 |
+
else:
|
| 42 |
+
logging.info("PaddleOCR home directory exists.")
|
| 43 |
+
|
| 44 |
+
@app.route('/')
|
| 45 |
+
def index():
|
| 46 |
+
uploaded_files = session.get('uploaded_files', [])
|
| 47 |
+
logging.info(f"Accessed index page, uploaded files: {uploaded_files}")
|
| 48 |
+
return render_template('index.html', uploaded_files=uploaded_files)
|
| 49 |
+
|
| 50 |
+
@app.route('/upload', methods=['POST'])
|
| 51 |
+
def upload_file():
|
| 52 |
+
if 'files' not in request.files:
|
| 53 |
+
flash('No file part')
|
| 54 |
+
logging.warning("No file part found in the request")
|
| 55 |
+
return redirect(request.url)
|
| 56 |
+
|
| 57 |
+
files = request.files.getlist('files')
|
| 58 |
+
if not files or all(file.filename == '' for file in files):
|
| 59 |
+
flash('No selected files')
|
| 60 |
+
logging.warning("No files selected for upload")
|
| 61 |
+
return redirect(request.url)
|
| 62 |
+
|
| 63 |
+
uploaded_files = session.get('uploaded_files', [])
|
| 64 |
+
for file in files:
|
| 65 |
+
if file:
|
| 66 |
+
filename = file.filename
|
| 67 |
+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 68 |
+
file.save(file_path)
|
| 69 |
+
uploaded_files.append(filename)
|
| 70 |
+
logging.info(f"Uploaded file: {filename} at {file_path}")
|
| 71 |
+
|
| 72 |
+
session['uploaded_files'] = uploaded_files
|
| 73 |
+
flash('Files successfully uploaded')
|
| 74 |
+
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
| 75 |
+
return redirect(url_for('index'))
|
| 76 |
+
|
| 77 |
+
@app.route('/remove_file')
|
| 78 |
+
def remove_file():
|
| 79 |
+
uploaded_files = session.get('uploaded_files', [])
|
| 80 |
+
for filename in uploaded_files:
|
| 81 |
+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 82 |
+
if os.path.exists(file_path):
|
| 83 |
+
os.remove(file_path)
|
| 84 |
+
logging.info(f"Removed file: {filename}")
|
| 85 |
+
else:
|
| 86 |
+
logging.warning(f"File not found for removal: {file_path}") # More specific log
|
| 87 |
+
|
| 88 |
+
session.pop('uploaded_files', None)
|
| 89 |
+
flash('Files successfully removed')
|
| 90 |
+
logging.info("All uploaded files removed")
|
| 91 |
+
return redirect(url_for('index'))
|
| 92 |
+
|
| 93 |
+
@app.route('/process', methods=['POST'])
|
| 94 |
+
def process_file():
|
| 95 |
+
uploaded_files = session.get('uploaded_files', [])
|
| 96 |
+
if not uploaded_files:
|
| 97 |
+
flash('No files selected for processing')
|
| 98 |
+
logging.warning("No files selected for processing")
|
| 99 |
+
return redirect(url_for('index'))
|
| 100 |
+
|
| 101 |
+
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
|
| 102 |
+
logging.info(f"Processing files: {file_paths}")
|
| 103 |
+
|
| 104 |
+
extracted_text = {}
|
| 105 |
+
processed_Img = {}
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
extracted_text, processed_Img = extract_text_from_images(file_paths, RESULT_FOLDER)
|
| 109 |
+
logging.info(f"Extracted text: {extracted_text}")
|
| 110 |
+
logging.info(f"Processed images: {processed_Img}")
|
| 111 |
+
|
| 112 |
+
llmText = json_to_llm_str(extracted_text)
|
| 113 |
+
logging.info(f"LLM text: {llmText}")
|
| 114 |
+
|
| 115 |
+
LLMdata = Data_Extractor(llmText)
|
| 116 |
+
logging.info(f"LLM data: {LLMdata}")
|
| 117 |
+
|
| 118 |
+
except Exception as e:
|
| 119 |
+
logging.error(f"Error during LLM processing: {e}")
|
| 120 |
+
logging.info("Running backup model...")
|
| 121 |
+
|
| 122 |
+
LLMdata = {}
|
| 123 |
+
|
| 124 |
+
if extracted_text:
|
| 125 |
+
text = json_to_llm_str(extracted_text)
|
| 126 |
+
LLMdata = NER_Model(text)
|
| 127 |
+
logging.info(f"NER model data: {LLMdata}")
|
| 128 |
+
else:
|
| 129 |
+
logging.warning("No extracted text available for backup model")
|
| 130 |
+
|
| 131 |
+
cont_data = process_extracted_text(extracted_text)
|
| 132 |
+
logging.info(f"Contextual data: {cont_data}")
|
| 133 |
+
|
| 134 |
+
processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
|
| 135 |
+
logging.info(f"Processed data: {processed_data}")
|
| 136 |
+
|
| 137 |
+
session['processed_data'] = processed_data
|
| 138 |
+
session['processed_Img'] = processed_Img
|
| 139 |
+
flash('Data processed and analyzed successfully')
|
| 140 |
+
logging.info("Data processed and analyzed successfully")
|
| 141 |
+
return redirect(url_for('result'))
|
| 142 |
+
|
| 143 |
+
@app.route('/result')
|
| 144 |
+
def result():
|
| 145 |
+
processed_data = session.get('processed_data', {})
|
| 146 |
+
processed_Img = session.get('processed_Img', {})
|
| 147 |
+
logging.info(f"Displaying results: Data - {processed_data}, Images - {processed_Img}")
|
| 148 |
+
return render_template('result.html', data=processed_data, Img=processed_Img)
|
| 149 |
+
|
| 150 |
+
@app.route('/uploads/<filename>')
|
| 151 |
+
def uploaded_file(filename):
|
| 152 |
+
logging.info(f"Serving file: {filename}")
|
| 153 |
+
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
|
| 154 |
+
|
| 155 |
+
if __name__ == '__main__':
|
| 156 |
+
logging.info("Starting Flask app")
|
| 157 |
+
app.run(debug=True)
|