Sumit404 commited on
Commit
7ae42fe
·
verified ·
1 Parent(s): 0c36edf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -4,7 +4,6 @@ import spacy
4
  import re
5
  import html
6
  import os
7
- import tempfile
8
  import logging
9
  import subprocess
10
 
@@ -213,21 +212,16 @@ def generate_portfolio(file, theme="Light"):
213
  logger.error("No file uploaded.")
214
  return "Error: No file uploaded. Please upload a resume file (PDF or text).", "Error: No file uploaded. Please upload a resume file (PDF or text)."
215
 
216
- # Use tempfile to handle file uploads
217
- with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf' if file.name.endswith('.pdf') else '.txt') as tmp_file:
218
- tmp_file.write(file.read())
219
- tmp_file_path = tmp_file.name
220
 
221
  # Extract text from the file
222
- if tmp_file_path.endswith('.pdf'):
223
- resume_text = extract_text_from_pdf(tmp_file_path)
224
  else:
225
- with open(tmp_file_path, 'r', encoding='utf-8') as f:
226
  resume_text = f.read()
227
 
228
- # Clean up the temporary file
229
- os.unlink(tmp_file_path)
230
-
231
  if "Error" in resume_text:
232
  logger.error(f"Failed to extract text: {resume_text}")
233
  return resume_text, resume_text
 
4
  import re
5
  import html
6
  import os
 
7
  import logging
8
  import subprocess
9
 
 
212
  logger.error("No file uploaded.")
213
  return "Error: No file uploaded. Please upload a resume file (PDF or text).", "Error: No file uploaded. Please upload a resume file (PDF or text)."
214
 
215
+ # In Hugging Face Spaces, file.name is the path to the uploaded file
216
+ file_path = file.name if hasattr(file, 'name') else file
 
 
217
 
218
  # Extract text from the file
219
+ if file_path.endswith('.pdf'):
220
+ resume_text = extract_text_from_pdf(file_path)
221
  else:
222
+ with open(file_path, 'r', encoding='utf-8') as f:
223
  resume_text = f.read()
224
 
 
 
 
225
  if "Error" in resume_text:
226
  logger.error(f"Failed to extract text: {resume_text}")
227
  return resume_text, resume_text