Upload 5 files
Browse files- app.py +82 -0
- clf.pkl +3 -0
- encoder.pkl +3 -0
- requirements.txt +0 -0
- tfidf.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import docx
|
4 |
+
import PyPDF2
|
5 |
+
import re
|
6 |
+
|
7 |
+
# Load pre-trained model and TF-IDF vectorizer
|
8 |
+
svc_model = pickle.load(open('clf.pkl', 'rb')) # Update with your model path
|
9 |
+
tfidf = pickle.load(open('tfidf.pkl', 'rb')) # Update with your vectorizer path
|
10 |
+
le = pickle.load(open('encoder.pkl', 'rb')) # Update with your encoder path
|
11 |
+
|
12 |
+
# Function to clean resume text
|
13 |
+
def clean_resume(txt):
|
14 |
+
clean_text = re.sub('http\S+\s', ' ', txt)
|
15 |
+
clean_text = re.sub('RT|cc', ' ', clean_text)
|
16 |
+
clean_text = re.sub('#\S+\s', ' ', clean_text)
|
17 |
+
clean_text = re.sub('@\S+', ' ', clean_text)
|
18 |
+
clean_text = re.sub('[%s]' % re.escape("""!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"""), ' ', clean_text)
|
19 |
+
clean_text = re.sub(r'[^\x00-\x7f]', ' ', clean_text)
|
20 |
+
clean_text = re.sub('\s+', ' ', clean_text)
|
21 |
+
return clean_text
|
22 |
+
|
23 |
+
# Function to extract text from PDF
|
24 |
+
def extract_text_from_pdf(file):
|
25 |
+
pdf_reader = PyPDF2.PdfReader(file)
|
26 |
+
text = ''
|
27 |
+
for page in pdf_reader.pages:
|
28 |
+
text += page.extract_text()
|
29 |
+
return text
|
30 |
+
|
31 |
+
# Function to extract text from DOCX
|
32 |
+
def extract_text_from_docx(file):
|
33 |
+
doc = docx.Document(file)
|
34 |
+
text = ''
|
35 |
+
for paragraph in doc.paragraphs:
|
36 |
+
text += paragraph.text + '\n'
|
37 |
+
return text
|
38 |
+
|
39 |
+
# Function to extract text from TXT
|
40 |
+
def extract_text_from_txt(file):
|
41 |
+
try:
|
42 |
+
text = file.read().decode('utf-8')
|
43 |
+
except UnicodeDecodeError:
|
44 |
+
text = file.read().decode('latin-1')
|
45 |
+
return text
|
46 |
+
|
47 |
+
# Function to handle file upload and extraction
|
48 |
+
def handle_file_upload(uploaded_file):
|
49 |
+
file_extension = uploaded_file.name.split('.')[-1].lower()
|
50 |
+
if file_extension == 'pdf':
|
51 |
+
text = extract_text_from_pdf(uploaded_file)
|
52 |
+
elif file_extension == 'docx':
|
53 |
+
text = extract_text_from_docx(uploaded_file)
|
54 |
+
elif file_extension == 'txt':
|
55 |
+
text = extract_text_from_txt(uploaded_file)
|
56 |
+
else:
|
57 |
+
raise ValueError("Unsupported file type. Please upload a PDF, DOCX, or TXT file.")
|
58 |
+
return text
|
59 |
+
|
60 |
+
# Function to predict the category of a resume
|
61 |
+
def predict_category(file):
|
62 |
+
try:
|
63 |
+
resume_text = handle_file_upload(file)
|
64 |
+
cleaned_text = clean_resume(resume_text)
|
65 |
+
vectorized_text = tfidf.transform([cleaned_text])
|
66 |
+
vectorized_text = vectorized_text.toarray()
|
67 |
+
predicted_category = svc_model.predict(vectorized_text)
|
68 |
+
predicted_category_name = le.inverse_transform(predicted_category)
|
69 |
+
return f"Predicted Category: {predicted_category_name[0]}"
|
70 |
+
except Exception as e:
|
71 |
+
return f"Error: {str(e)}"
|
72 |
+
|
73 |
+
# Define Gradio interface
|
74 |
+
inputs = gr.File(label="Upload Resume (PDF, DOCX, TXT)")
|
75 |
+
outputs = gr.Textbox(label="Prediction")
|
76 |
+
|
77 |
+
interface = gr.Interface(fn=predict_category, inputs=inputs, outputs=outputs, title="Resume Classifier",
|
78 |
+
description="Upload your resume to predict its job category using an AI model.")
|
79 |
+
|
80 |
+
# Launch the interface
|
81 |
+
if __name__ == "__main__":
|
82 |
+
interface.launch()
|
clf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:49b82e1edfab39d145c10403c1b05fbdbac8535b9597beaf925af7d405f59db1
|
3 |
+
size 236270022
|
encoder.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1fdd7cd3001ca6d1137cec3b41f8d385546de4fb01541feb147d9cb68eeac9e3
|
3 |
+
size 632
|
requirements.txt
ADDED
Binary file (4.53 kB). View file
|
|
tfidf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e8b9aee87992110d9a0d61f58b191d8681a69c32b9450ace117728a88aef3571
|
3 |
+
size 213493
|