Skip to content

Commit

Permalink
address openai#109
Browse files Browse the repository at this point in the history
  • Loading branch information
isafulf committed Apr 3, 2023
1 parent 0219da9 commit e871ab4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ def extract_text_from_filepath(filepath: str, mimetype: Optional[str] = None) ->
else:
raise Exception("Unsupported file type")

# Open the file in binary mode
file = open(filepath, "rb")
extracted_text = extract_text_from_file(file, mimetype)
try:
with open(filepath, "rb") as file:
extracted_text = extract_text_from_file(file, mimetype)
except Exception as e:
print(f"Error: {e}")
raise e

return extracted_text

Expand Down Expand Up @@ -78,10 +81,8 @@ def extract_text_from_file(file: BufferedReader, mimetype: str) -> str:
extracted_text += "\n"
else:
# Unsupported file type
file.close()
raise ValueError("Unsupported file type: {}".format(mimetype))

file.close()
return extracted_text


Expand Down

0 comments on commit e871ab4

Please sign in to comment.