Spaces:
Sleeping
Sleeping
WebashalarForML
commited on
Commit
•
f8f385d
1
Parent(s):
1acf205
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ os.environ['PADDLEOCR_HOME'] = os.path.join(app.config['UPLOAD_FOLDER'], '.paddl
|
|
36 |
|
37 |
@app.route('/')
|
38 |
def index():
|
39 |
-
uploaded_files = session.get('uploaded_files', [])
|
40 |
logging.info(f"Accessed index page, uploaded files: {uploaded_files}")
|
41 |
return render_template('index.html', uploaded_files=uploaded_files)
|
42 |
|
@@ -53,22 +53,23 @@ def upload_file():
|
|
53 |
logging.warning("No files selected for upload")
|
54 |
return redirect(request.url)
|
55 |
|
56 |
-
uploaded_files = []
|
57 |
for file in files:
|
58 |
if file:
|
59 |
filename = file.filename
|
60 |
-
|
61 |
-
|
|
|
62 |
logging.info(f"Uploaded file: {filename}")
|
63 |
|
64 |
-
session['uploaded_files'] = uploaded_files
|
65 |
flash('Files successfully uploaded')
|
66 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
67 |
return redirect(url_for('index'))
|
68 |
|
69 |
@app.route('/remove_file')
|
70 |
def remove_file():
|
71 |
-
uploaded_files = session.get('uploaded_files', [])
|
72 |
for filename in uploaded_files:
|
73 |
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
74 |
if os.path.exists(file_path): # Check if the file exists before trying to remove it
|
@@ -77,14 +78,14 @@ def remove_file():
|
|
77 |
else:
|
78 |
logging.warning(f"File not found for removal: {filename}")
|
79 |
|
80 |
-
session.pop('uploaded_files', None)
|
81 |
flash('Files successfully removed')
|
82 |
logging.info("All uploaded files removed")
|
83 |
return redirect(url_for('index'))
|
84 |
|
85 |
@app.route('/process', methods=['POST'])
|
86 |
def process_file():
|
87 |
-
uploaded_files = session.get('uploaded_files', [])
|
88 |
if not uploaded_files:
|
89 |
flash('No files selected for processing')
|
90 |
logging.warning("No files selected for processing")
|
@@ -94,7 +95,7 @@ def process_file():
|
|
94 |
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
|
95 |
logging.info(f"Processing files: {file_paths}")
|
96 |
|
97 |
-
extracted_text = {} # Initialize extracted_text
|
98 |
try:
|
99 |
# Extract text from all images
|
100 |
extracted_text, processed_Img = extract_text_from_images(file_paths, RESULT_FOLDER)
|
@@ -113,30 +114,29 @@ def process_file():
|
|
113 |
logging.info("Running backup model...")
|
114 |
|
115 |
# Run the backup model in case of an exception
|
116 |
-
if extracted_text: # Ensure extracted_text has a value before using it
|
117 |
text = json_to_llm_str(extracted_text)
|
118 |
LLMdata = NER_Model(text)
|
119 |
logging.info(f"NER model data: {LLMdata}")
|
120 |
else:
|
121 |
-
logging.warning("No extracted text available for backup model")
|
122 |
|
123 |
cont_data = process_extracted_text(extracted_text)
|
124 |
logging.info(f"Contextual data: {cont_data}")
|
125 |
|
126 |
-
# Storing the parsed results
|
127 |
processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
|
128 |
-
logging.info(f"Processed data: {processed_data}")
|
129 |
-
|
130 |
session['processed_data'] = processed_data
|
131 |
session['processed_Img'] = processed_Img
|
|
|
132 |
flash('Data processed and analyzed successfully')
|
133 |
logging.info("Data processed and analyzed successfully")
|
134 |
return redirect(url_for('result'))
|
135 |
|
136 |
@app.route('/result')
|
137 |
def result():
|
138 |
-
processed_data = session.get('processed_data', {})
|
139 |
-
processed_Img = session.get('processed_Img', {})
|
140 |
logging.info(f"Displaying results: Data - {processed_data}, Images - {processed_Img}")
|
141 |
return render_template('result.html', data=processed_data, Img=processed_Img)
|
142 |
|
|
|
36 |
|
37 |
@app.route('/')
|
38 |
def index():
|
39 |
+
uploaded_files = session.get('uploaded_files', []) # Retrieve the session data
|
40 |
logging.info(f"Accessed index page, uploaded files: {uploaded_files}")
|
41 |
return render_template('index.html', uploaded_files=uploaded_files)
|
42 |
|
|
|
53 |
logging.warning("No files selected for upload")
|
54 |
return redirect(request.url)
|
55 |
|
56 |
+
uploaded_files = session.get('uploaded_files', []) # Get the existing session data
|
57 |
for file in files:
|
58 |
if file:
|
59 |
filename = file.filename
|
60 |
+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
61 |
+
file.save(file_path)
|
62 |
+
uploaded_files.append(filename) # Add each file to the session's list
|
63 |
logging.info(f"Uploaded file: {filename}")
|
64 |
|
65 |
+
session['uploaded_files'] = uploaded_files # Save uploaded files in session
|
66 |
flash('Files successfully uploaded')
|
67 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
68 |
return redirect(url_for('index'))
|
69 |
|
70 |
@app.route('/remove_file')
|
71 |
def remove_file():
|
72 |
+
uploaded_files = session.get('uploaded_files', []) # Get the uploaded files from the session
|
73 |
for filename in uploaded_files:
|
74 |
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
75 |
if os.path.exists(file_path): # Check if the file exists before trying to remove it
|
|
|
78 |
else:
|
79 |
logging.warning(f"File not found for removal: {filename}")
|
80 |
|
81 |
+
session.pop('uploaded_files', None) # Clear the session files
|
82 |
flash('Files successfully removed')
|
83 |
logging.info("All uploaded files removed")
|
84 |
return redirect(url_for('index'))
|
85 |
|
86 |
@app.route('/process', methods=['POST'])
|
87 |
def process_file():
|
88 |
+
uploaded_files = session.get('uploaded_files', []) # Get files from the session
|
89 |
if not uploaded_files:
|
90 |
flash('No files selected for processing')
|
91 |
logging.warning("No files selected for processing")
|
|
|
95 |
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
|
96 |
logging.info(f"Processing files: {file_paths}")
|
97 |
|
98 |
+
extracted_text = {} # Initialize extracted_text
|
99 |
try:
|
100 |
# Extract text from all images
|
101 |
extracted_text, processed_Img = extract_text_from_images(file_paths, RESULT_FOLDER)
|
|
|
114 |
logging.info("Running backup model...")
|
115 |
|
116 |
# Run the backup model in case of an exception
|
117 |
+
if extracted_text: # Ensure extracted_text has a value before using it
|
118 |
text = json_to_llm_str(extracted_text)
|
119 |
LLMdata = NER_Model(text)
|
120 |
logging.info(f"NER model data: {LLMdata}")
|
121 |
else:
|
122 |
+
logging.warning("No extracted text available for backup model")
|
123 |
|
124 |
cont_data = process_extracted_text(extracted_text)
|
125 |
logging.info(f"Contextual data: {cont_data}")
|
126 |
|
127 |
+
# Storing the parsed results in session
|
128 |
processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
|
|
|
|
|
129 |
session['processed_data'] = processed_data
|
130 |
session['processed_Img'] = processed_Img
|
131 |
+
session.modified = True # Ensure session is updated
|
132 |
flash('Data processed and analyzed successfully')
|
133 |
logging.info("Data processed and analyzed successfully")
|
134 |
return redirect(url_for('result'))
|
135 |
|
136 |
@app.route('/result')
|
137 |
def result():
|
138 |
+
processed_data = session.get('processed_data', {}) # Retrieve processed data from the session
|
139 |
+
processed_Img = session.get('processed_Img', {}) # Retrieve processed images from the session
|
140 |
logging.info(f"Displaying results: Data - {processed_data}, Images - {processed_Img}")
|
141 |
return render_template('result.html', data=processed_data, Img=processed_Img)
|
142 |
|