Jekyll2000 commited on
Commit
c8ce6b9
·
verified ·
1 Parent(s): d055394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -17,13 +17,16 @@ def setup_chromadb():
17
  return client.get_or_create_collection(name="resumes")
18
 
19
  def extract_text_from_resume(file):
20
- if file.name.endswith(".pdf"):
21
- # For PDF files, read the bytes directly
22
- with fitz.open(stream=file, filetype="pdf") as doc:
 
 
 
23
  return "\n".join([page.get_text("text") for page in doc])
24
- elif file.name.endswith(".txt"):
25
- # For text files, read as string
26
- with open(file.name, "r", encoding="utf-8") as f:
27
  return f.read()
28
  return ""
29
 
 
17
  return client.get_or_create_collection(name="resumes")
18
 
19
  def extract_text_from_resume(file):
20
+ # Get the file path from Gradio's file object
21
+ file_path = file.name
22
+
23
+ if file_path.endswith(".pdf"):
24
+ # Open the PDF file directly from the path
25
+ with fitz.open(file_path) as doc:
26
  return "\n".join([page.get_text("text") for page in doc])
27
+ elif file_path.endswith(".txt"):
28
+ # Open the text file directly
29
+ with open(file_path, "r", encoding="utf-8") as f:
30
  return f.read()
31
  return ""
32