Bentham commited on
Commit
f5cca33
·
verified ·
1 Parent(s): b4b84fd

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -0
main.py CHANGED
@@ -1,5 +1,27 @@
 
 
 
 
 
 
 
 
 
1
  import csv
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  @app.post("/convert/")
4
  async def convert_file_to_txt(
5
  file: UploadFile = File(...),
 
1
+ import os
2
+ import uuid
3
+ from fastapi import FastAPI, File, UploadFile, HTTPException, BackgroundTasks
4
+ from fastapi.responses import FileResponse, JSONResponse
5
+ import pypandoc
6
+ import shutil
7
+ import logging
8
+ import tempfile
9
+ from pdfminer.high_level import extract_text
10
  import csv
11
 
12
+ # Initialize the logger
13
+ logging.basicConfig(level=logging.DEBUG)
14
+
15
+ # Initialize the FastAPI application
16
+ app = FastAPI()
17
+
18
+ def delete_temp_files(file_paths: list):
19
+ """Function to delete temporary files after the response"""
20
+ for file_path in file_paths:
21
+ if os.path.exists(file_path):
22
+ os.remove(file_path)
23
+ logging.debug(f"Temporary file deleted: {file_path}")
24
+
25
  @app.post("/convert/")
26
  async def convert_file_to_txt(
27
  file: UploadFile = File(...),