-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
208 lines (155 loc) · 5.05 KB
/
main.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Project Name: Genz Hiring
Developers:
Farhaan
Muhilan
Naveen
Raghava
Filename: main.py
Title: Flask route and logics
Author: Raghava | GitHub: @raghavtwenty
Date Created: November 20, 2023 | Last Updated: May 15, 2024
Language: Python | Version: 3.10.14, 64-bit
"""
# Importing required libraries
from flask import Flask, render_template, request, send_file
from langchain_community.document_loaders import DirectoryLoader
from llm import llm_prompt
# Flask App
app = Flask(__name__)
def get_appreciation(score):
if score < 50:
return "Attention required"
elif score < 70:
return "Getting closer..."
elif score < 85:
return "Good to go!"
else:
return "Perfect!!!"
def extract_text_from_pdf(pdf_file):
if request.method == "POST":
# Get the PDF file from the user
pdf_file = request.files["pdf_file"]
# Save the PDF file to a temporary location
pdf_file.save("./data/temp.pdf")
loc = "./data"
# Extract text from pdf using langchain
loader = DirectoryLoader(loc)
documents = loader.load()
for document in documents:
if hasattr(document, "page_content"):
page_content = document.page_content
else:
page_content = "No 'page_content' found in the document."
# print(page_content)
return page_content
@app.route("/", methods=["GET", "POST"])
def index():
return render_template("index.html")
@app.route("/result", methods=["GET", "POST"])
def result():
global results
global magic
global jobSeek
# Get the uploaded PDF file
uploaded_file = request.files["pdf_file"]
# user data
jobrole = request.form.get("role")
jobdesc = request.form.get("jobdesc")
# Extract text from the PDF file
text = extract_text_from_pdf(uploaded_file)
# pass to llm
results, Magic, JobSeek = llm_prompt(jobrole, jobdesc, text)
left = results[0].split("\n")
right = results[1].split("\n")
score = int(results[2])
magic = Magic.split("\n")
jobSeek = JobSeek
appreciation = get_appreciation(score)
return render_template(
"home.html",
appreciation=appreciation,
left=left,
right=right,
score=score,
magic=magic,
jobSeek=jobSeek,
)
@app.route("/overview")
def overview():
left = results[0].split("\n")
right = results[1].split("\n")
score = int(results[2])
appreciation = get_appreciation(score)
return render_template(
"overview.html",
appreciation=appreciation,
left=left,
right=right,
score=score,
magic=magic,
jobSeek=jobSeek,
)
@app.route("/length")
def length():
left = results[3].split("\n")
right = results[4].split("\n")
score = int(results[5])
return render_template("length.html", left=left, right=right, score=score)
@app.route("/total")
def total():
left = results[6].split("\n")
right = results[7].split("\n")
score = int(results[8])
return render_template("total.html", left=left, right=right, score=score)
@app.route("/bullet")
def bullet():
left = results[9].split("\n")
right = results[10].split("\n")
score = int(results[11])
return render_template("bullet.html", left=left, right=right, score=score)
@app.route("/action")
def action():
left = results[12].split("\n")
right = results[13].split("\n")
score = int(results[14])
return render_template("action.html", left=left, right=right, score=score)
@app.route("/quanti")
def quanti():
left = results[15].split("\n")
right = results[16].split("\n")
score = int(results[17])
return render_template("quanti.html", left=left, right=right, score=score)
@app.route("/skills")
def skills():
left = results[18].split("\n")
right = results[19].split("\n")
score = int(results[20])
return render_template("skills.html", left=left, right=right, score=score)
@app.route("/consis")
def consis():
left = results[21].split("\n")
right = results[22].split("\n")
score = int(results[23])
return render_template("consis.html", left=left, right=right, score=score)
@app.route("/dates")
def dates():
left = results[24].split("\n")
right = results[25].split("\n")
score = int(results[26])
return render_template("dates.html", left=left, right=right, score=score)
@app.route("/spell")
def spell():
left = results[27].split("\n")
right = results[28].split("\n")
score = int(results[29])
return render_template("spell.html", left=left, right=right, score=score)
@app.route("/read")
def read():
left = results[30].split("\n")
right = results[31].split("\n")
score = int(results[32])
return render_template("read.html", left=left, right=right, score=score)
# Main
if __name__ == "__main__":
app.run()