|
|
|
from flask import Flask, render_template, request, redirect, url_for, flash, session, send_from_directory |
|
import os |
|
from utility.utils import extract_text_from_images,Data_Extractor,json_to_llm_str,process_extracted_text,process_resume_data |
|
from backup.backup import NER_Model |
|
|
|
app = Flask(__name__) |
|
app.secret_key = 'your_secret_key' |
|
app.config['UPLOAD_FOLDER'] = 'uploads/' |
|
|
|
UPLOAD_FOLDER = 'static/uploads/' |
|
RESULT_FOLDER = 'static/results/' |
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True) |
|
os.makedirs(RESULT_FOLDER, exist_ok=True) |
|
|
|
if not os.path.exists(app.config['UPLOAD_FOLDER']): |
|
os.makedirs(app.config['UPLOAD_FOLDER']) |
|
|
|
@app.route('/') |
|
def index(): |
|
uploaded_files = session.get('uploaded_files', []) |
|
return render_template('index.html', uploaded_files=uploaded_files) |
|
|
|
@app.route('/upload', methods=['POST']) |
|
def upload_file(): |
|
if 'files' not in request.files: |
|
flash('No file part') |
|
return redirect(request.url) |
|
|
|
files = request.files.getlist('files') |
|
if not files or all(file.filename == '' for file in files): |
|
flash('No selected files') |
|
return redirect(request.url) |
|
|
|
uploaded_files = [] |
|
for file in files: |
|
if file: |
|
filename = file.filename |
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) |
|
uploaded_files.append(filename) |
|
|
|
session['uploaded_files'] = uploaded_files |
|
flash('Files successfully uploaded') |
|
return redirect(url_for('index')) |
|
|
|
@app.route('/remove_file') |
|
def remove_file(): |
|
uploaded_files = session.get('uploaded_files', []) |
|
for filename in uploaded_files: |
|
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename)) |
|
session.pop('uploaded_files', None) |
|
flash('Files successfully removed') |
|
return redirect(url_for('index')) |
|
|
|
@app.route('/process', methods=['POST']) |
|
def process_file(): |
|
uploaded_files = session.get('uploaded_files', []) |
|
if not uploaded_files: |
|
flash('No files selected for processing') |
|
return redirect(url_for('index')) |
|
|
|
|
|
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files] |
|
|
|
|
|
extracted_text,processed_Img = extract_text_from_images(file_paths,RESULT_FOLDER) |
|
|
|
print("extracted_text----------------------------",extracted_text) |
|
print("extracted_text type----------------------------",type(extracted_text)) |
|
|
|
print("processed_Img----------------------------",processed_Img) |
|
print("processed_Img type----------------------------",type(processed_Img)) |
|
|
|
|
|
try: |
|
|
|
llmText=json_to_llm_str(extracted_text) |
|
print("llmText---------->",llmText) |
|
LLMdata = Data_Extractor(llmText) |
|
print("LLM data----------------------------",LLMdata) |
|
|
|
except Exception as e: |
|
|
|
print(f"An error occurred: {e}") |
|
|
|
print("Running backup model...") |
|
|
|
text=json_to_llm_str(extracted_text) |
|
LLMdata=NER_Model(text) |
|
print("NER data----------------------------",LLMdata) |
|
|
|
|
|
cont_data=process_extracted_text(extracted_text) |
|
print("cont_data----------------------------",cont_data) |
|
|
|
processed_data = process_resume_data(LLMdata,cont_data,extracted_text) |
|
|
|
session['processed_data'] = processed_data |
|
session['processed_Img'] = processed_Img |
|
flash('Data processed and analyzed successfully ') |
|
return redirect(url_for('result')) |
|
|
|
@app.route('/result') |
|
def result(): |
|
processed_data = session.get('processed_data', {}) |
|
processed_Img = session.get('processed_Img', {}) |
|
return render_template('result.html', data=processed_data,Img=processed_Img) |
|
|
|
@app.route('/uploads/<filename>') |
|
def uploaded_file(filename): |
|
return send_from_directory(app.config['UPLOAD_FOLDER'], filename) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |