WebashalarForML commited on
Commit
97132db
1 Parent(s): 6404a9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -0
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # libraries
2
+ from flask import Flask, render_template, request, redirect, url_for, flash, session, send_from_directory
3
+ import os
4
+ from utility.utils import extract_text_from_images,Data_Extractor,json_to_llm_str,process_extracted_text,process_resume_data
5
+
6
+ # Flask App
7
+ app = Flask(__name__)
8
+ app.secret_key = 'your_secret_key'
9
+ app.config['UPLOAD_FOLDER'] = 'uploads/'
10
+
11
+ UPLOAD_FOLDER = 'static/uploads/'
12
+ RESULT_FOLDER = 'static/results/'
13
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
14
+ os.makedirs(RESULT_FOLDER, exist_ok=True)
15
+
16
+ if not os.path.exists(app.config['UPLOAD_FOLDER']):
17
+ os.makedirs(app.config['UPLOAD_FOLDER'])
18
+
19
+ @app.route('/')
20
+ def index():
21
+ uploaded_files = session.get('uploaded_files', [])
22
+ return render_template('index.html', uploaded_files=uploaded_files)
23
+
24
+ @app.route('/upload', methods=['POST'])
25
+ def upload_file():
26
+ if 'files' not in request.files:
27
+ flash('No file part')
28
+ return redirect(request.url)
29
+
30
+ files = request.files.getlist('files') # Get multiple files
31
+ if not files or all(file.filename == '' for file in files):
32
+ flash('No selected files')
33
+ return redirect(request.url)
34
+
35
+ uploaded_files = []
36
+ for file in files:
37
+ if file:
38
+ filename = file.filename
39
+ file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
40
+ uploaded_files.append(filename)
41
+
42
+ session['uploaded_files'] = uploaded_files
43
+ flash('Files successfully uploaded')
44
+ return redirect(url_for('index'))
45
+
46
+ @app.route('/remove_file')
47
+ def remove_file():
48
+ uploaded_files = session.get('uploaded_files', [])
49
+ for filename in uploaded_files:
50
+ os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
51
+ session.pop('uploaded_files', None)
52
+ flash('Files successfully removed')
53
+ return redirect(url_for('index'))
54
+
55
+ @app.route('/process', methods=['POST'])
56
+ def process_file():
57
+ uploaded_files = session.get('uploaded_files', [])
58
+ if not uploaded_files:
59
+ flash('No files selected for processing')
60
+ return redirect(url_for('index'))
61
+
62
+ # Create a list of file paths for the extracted text function
63
+ file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
64
+
65
+ # Extract text from all images
66
+ extracted_text,processed_Img = extract_text_from_images(file_paths,RESULT_FOLDER)
67
+ # Convert PDF to text
68
+ print("extracted_text----------------------------",extracted_text)
69
+ print("extracted_text type----------------------------",type(extracted_text))
70
+
71
+ print("processed_Img----------------------------",processed_Img)
72
+ print("processed_Img type----------------------------",type(processed_Img))
73
+
74
+
75
+ try:
76
+ # Call the Gemma model API and get the professional data
77
+ llmText=json_to_llm_str(extracted_text)
78
+ print("llmText---------->",llmText)
79
+ LLMdata = Data_Extractor(llmText)
80
+ print("LLMdata----------------------------",LLMdata)
81
+
82
+ except Exception as e:
83
+ # Handling any exceptions during the process
84
+ print(f"An error occurred: {e}")
85
+
86
+ # Run the backup model in case of an exception
87
+ print("Running backup model...")
88
+
89
+ cont_data=process_extracted_text(extracted_text)
90
+ print("cont_data----------------------------",cont_data)
91
+ #storing the paresed results
92
+ processed_data = process_resume_data(LLMdata,cont_data,extracted_text)
93
+
94
+ session['processed_data'] = processed_data
95
+ session['processed_Img'] = processed_Img
96
+ flash('Data processed and analyzed successfully ')
97
+ return redirect(url_for('result'))
98
+
99
+ @app.route('/result')
100
+ def result():
101
+ processed_data = session.get('processed_data', {})
102
+ processed_Img = session.get('processed_Img', {})
103
+ return render_template('result.html', data=processed_data,Img=processed_Img)
104
+
105
+ @app.route('/uploads/<filename>')
106
+ def uploaded_file(filename):
107
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
108
+
109
+ if __name__ == '__main__':
110
+ app.run(debug=True)