Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklesworthstone committed May 21, 2024
1 parent 18aabea commit 43f8552
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions service_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,17 @@ async def compute_embedding(text): # Define a function to compute the embedding

async def parse_submitted_document_file_into_sentence_strings_func(temp_file_path: str, mime_type: str):
strings = []
content = ""
if mime_type.startswith('text/'):
with open(temp_file_path, 'r') as buffer:
content = buffer.read()
try:
with open(temp_file_path, 'r', encoding='utf-8') as buffer:
content = buffer.read()
except UnicodeDecodeError:
with open(temp_file_path, 'r', encoding='latin1') as buffer:
content = buffer.read()
else:
try:
content = textract.process(temp_file_path).decode('utf-8')
except UnicodeDecodeError:
try:
content = textract.process(temp_file_path).decode('unicode_escape')
except Exception as e:
logger.error(f"Error while processing file: {e}, mime_type: {mime_type}")
raise HTTPException(status_code=400, detail=f"Unsupported file type or error: {e}")
except Exception as e:
logger.error(f"Error while processing file: {e}, mime_type: {mime_type}")
raise HTTPException(status_code=400, detail=f"Unsupported file type or error: {e}")
Expand Down

0 comments on commit 43f8552

Please sign in to comment.