Skip to content

Commit

Permalink
create file upload directory to store files temporarily for analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaykarle committed May 30, 2024
1 parent 5c60000 commit 7bc68b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

.direnv/
.direnv/
file_uploads/
5 changes: 4 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

DEFAULT_PORT = "3000"
NLP_ENGINE = "flair/ner-english-large"
UPLOAD_DIR = "./file_uploads"

class Server:
"""HTTP Server for calling Presidio Analyzer."""
Expand All @@ -23,6 +24,8 @@ def __init__(self):
nlp_engine = FlairNLPEngine(NLP_ENGINE)
self.engine = CSVAnalyzerEngine(nlp_engine)
self.logger.info("Started analyzer engine")
if not os.path.exists(UPLOAD_DIR):
os.makedirs(UPLOAD_DIR)

@self.app.route("/health")
def health() -> str:
Expand All @@ -37,7 +40,7 @@ def analyze() -> Tuple[str, int]:
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400

filepath = f'uploads/{uuid.uuid4()}'
filepath = f'{UPLOAD_DIR}/{uuid.uuid4()}'
file.save(filepath)
self.logger.info(f"Successfully saved file: {filepath}")

Expand Down

0 comments on commit 7bc68b9

Please sign in to comment.