CR7CAD commited on
Commit
4077883
·
verified ·
1 Parent(s): 6135a86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import os
2
- import tempfile
3
  import streamlit as st
4
  import docx
5
- import textract
6
  from transformers import pipeline
7
  import numpy as np
8
  from scipy.spatial.distance import cosine
@@ -35,7 +34,7 @@ models = load_models()
35
  #####################################
36
  def extract_text_from_file(file_obj):
37
  """
38
- Extract text from .doc and .docx files.
39
  Returns the extracted text or an error message if extraction fails.
40
  """
41
  filename = file_obj.name
@@ -48,17 +47,13 @@ def extract_text_from_file(file_obj):
48
  text = "\n".join(para.text for para in document.paragraphs if para.text.strip())
49
  except Exception as e:
50
  text = f"Error processing DOCX file: {e}"
51
- elif ext == ".doc":
52
  try:
53
- with tempfile.NamedTemporaryFile(delete=False, suffix=".doc") as tmp:
54
- tmp.write(file_obj.read())
55
- tmp_filename = tmp.name
56
- text = textract.process(tmp_filename).decode("utf-8")
57
- os.unlink(tmp_filename)
58
  except Exception as e:
59
- text = f"Error processing DOC file: {e}"
60
  else:
61
- text = "Unsupported file type."
62
  return text
63
 
64
  #####################################
@@ -127,7 +122,7 @@ def compute_suitability(candidate_summary, company_prompt, models):
127
  st.title("Resume Analyzer and Company Suitability Checker")
128
  st.markdown(
129
  """
130
- Upload your resume file in **.doc** or **.docx** format. The app performs the following tasks:
131
  1. Extracts text from the resume.
132
  2. Uses a transformer-based model to generate a concise candidate summary.
133
  3. Compares the candidate summary with a company profile to produce a suitability score.
@@ -135,7 +130,7 @@ Upload your resume file in **.doc** or **.docx** format. The app performs the fo
135
  )
136
 
137
  # File uploader
138
- uploaded_file = st.file_uploader("Upload your resume (.doc or .docx)", type=["doc", "docx"])
139
 
140
  # Company description text area
141
  company_prompt = st.text_area(
@@ -175,7 +170,7 @@ if uploaded_file is not None and company_prompt and st.button("Analyze Resume"):
175
  # Extract text from resume
176
  resume_text = extract_text_from_file(uploaded_file)
177
 
178
- if resume_text.startswith("Error") or resume_text == "Unsupported file type.":
179
  st.error(resume_text)
180
  else:
181
  # Display extracted text
 
1
  import os
2
+ import io
3
  import streamlit as st
4
  import docx
 
5
  from transformers import pipeline
6
  import numpy as np
7
  from scipy.spatial.distance import cosine
 
34
  #####################################
35
  def extract_text_from_file(file_obj):
36
  """
37
+ Extract text from .docx files.
38
  Returns the extracted text or an error message if extraction fails.
39
  """
40
  filename = file_obj.name
 
47
  text = "\n".join(para.text for para in document.paragraphs if para.text.strip())
48
  except Exception as e:
49
  text = f"Error processing DOCX file: {e}"
50
+ elif ext == ".txt":
51
  try:
52
+ text = file_obj.getvalue().decode("utf-8")
 
 
 
 
53
  except Exception as e:
54
+ text = f"Error processing TXT file: {e}"
55
  else:
56
+ text = "Unsupported file type. Please upload a .docx or .txt file."
57
  return text
58
 
59
  #####################################
 
122
  st.title("Resume Analyzer and Company Suitability Checker")
123
  st.markdown(
124
  """
125
+ Upload your resume file in **.docx** or **.txt** format. The app performs the following tasks:
126
  1. Extracts text from the resume.
127
  2. Uses a transformer-based model to generate a concise candidate summary.
128
  3. Compares the candidate summary with a company profile to produce a suitability score.
 
130
  )
131
 
132
  # File uploader
133
+ uploaded_file = st.file_uploader("Upload your resume (.docx or .txt)", type=["docx", "txt"])
134
 
135
  # Company description text area
136
  company_prompt = st.text_area(
 
170
  # Extract text from resume
171
  resume_text = extract_text_from_file(uploaded_file)
172
 
173
+ if resume_text.startswith("Error") or resume_text == "Unsupported file type. Please upload a .docx or .txt file.":
174
  st.error(resume_text)
175
  else:
176
  # Display extracted text