Bentham commited on
Commit
fdc603e
·
verified ·
1 Parent(s): 2d94f7d

Ajout du ".doc"

Browse files
Files changed (1) hide show
  1. main.py +15 -1
main.py CHANGED
@@ -866,7 +866,7 @@ async def convert_file_to_txt(
866
  allowed_extensions = [
867
  '.odt', '.pdf', '.docx', '.html', '.htm', '.md', '.txt', '.rtf', '.epub',
868
  '.tex', '.xml', '.org', '.commonmark', '.cm', '.wiki', '.opml',
869
- '.ppt', '.pptx' # Ajout de PPT et PPTX
870
  ]
871
 
872
  if ext not in allowed_extensions:
@@ -928,6 +928,20 @@ async def convert_file_to_txt(
928
  f.write(text)
929
  logging.debug(f"Conversion PPT réussie avec textract : {output_filename}")
930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
931
  else:
932
  # Conversion des autres formats en texte avec Pandoc
933
  output = pypandoc.convert_file(input_filename, 'plain', outputfile=output_filename)
 
866
  allowed_extensions = [
867
  '.odt', '.pdf', '.docx', '.html', '.htm', '.md', '.txt', '.rtf', '.epub',
868
  '.tex', '.xml', '.org', '.commonmark', '.cm', '.wiki', '.opml',
869
+ '.ppt', '.pptx', '.doc'
870
  ]
871
 
872
  if ext not in allowed_extensions:
 
928
  f.write(text)
929
  logging.debug(f"Conversion PPT réussie avec textract : {output_filename}")
930
 
931
+ elif ext == '.doc':
932
+ # Conversion DOC en texte avec textract
933
+ if 'textract' not in globals():
934
+ raise HTTPException(status_code=500, detail="La librairie textract n'est pas installée.")
935
+ try:
936
+ text = textract.process(input_filename).decode('utf-8', errors='replace')
937
+ except Exception as e:
938
+ logging.error(f"Erreur lors de l'extraction du texte depuis le .doc avec textract : {str(e)}")
939
+ raise HTTPException(status_code=500, detail="Erreur lors de la conversion du fichier .doc.")
940
+
941
+ with open(output_filename, "w", encoding="utf-8") as f:
942
+ f.write(text)
943
+ logging.debug(f"Conversion DOC réussie avec textract : {output_filename}")
944
+
945
  else:
946
  # Conversion des autres formats en texte avec Pandoc
947
  output = pypandoc.convert_file(input_filename, 'plain', outputfile=output_filename)