CloudAnts commited on
Commit
88fac77
·
1 Parent(s): 00f5739
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -47,19 +47,32 @@ def calculate_iou(bbox1, bbox2):
47
  return iou
48
 
49
 
50
- cropped_dir = "./app/cropped_images/"
51
- if os.path.exists(cropped_dir):
 
 
 
 
 
 
 
 
52
  shutil.rmtree(cropped_dir)
53
- os.makedirs(cropped_dir, exist_ok=True)
54
-
55
- output_dir1 = "./app/Folder1"
56
- output_dir2 = "./app/Folder2"
57
- output_dir3 = "./app/Folder3"
58
- UPLOAD_FOLDER = "./app/data1"
59
- os.makedirs(output_dir1, exist_ok=True)
60
- os.makedirs(output_dir2, exist_ok=True)
61
- os.makedirs(output_dir3, exist_ok=True)
62
- os.makedirs(UPLOAD_FOLDER, exist_ok=True)
 
 
 
 
 
63
 
64
  @app.route('/')
65
  def index():
@@ -67,13 +80,14 @@ def index():
67
 
68
  @app.route('/upload', methods=['POST'])
69
  def upload_file():
 
70
  if 'invoice-upload' not in request.files:
71
  return jsonify({'error': 'No file part'}), 400
72
  file = request.files['invoice-upload']
73
  if file.filename == '':
74
  return jsonify({'error': 'No selected file'}), 400
75
  if file:
76
- file_path = os.path.join(UPLOAD_FOLDER, file.filename)
77
  file.save(file_path)
78
  output_image, output_csv = process_image()
79
 
 
47
  return iou
48
 
49
 
50
+ def recreate_directories():
51
+ # Paths for the directories
52
+ cropped_dir = "./app/cropped_images/"
53
+ output_dir1 = "./app/Folder1"
54
+ output_dir2 = "./app/Folder2"
55
+ output_dir3 = "./app/Folder3"
56
+ UPLOAD_FOLDER = "./app/data1"
57
+
58
+ # Remove existing directories
59
+ if os.path.exists(cropped_dir):
60
  shutil.rmtree(cropped_dir)
61
+ if os.path.exists(output_dir1):
62
+ shutil.rmtree(output_dir1)
63
+ if os.path.exists(output_dir2):
64
+ shutil.rmtree(output_dir2)
65
+ if os.path.exists(output_dir3):
66
+ shutil.rmtree(output_dir3)
67
+ if os.path.exists(UPLOAD_FOLDER):
68
+ shutil.rmtree(UPLOAD_FOLDER)
69
+
70
+ # Recreate directories
71
+ os.makedirs(cropped_dir, exist_ok=True)
72
+ os.makedirs(output_dir1, exist_ok=True)
73
+ os.makedirs(output_dir2, exist_ok=True)
74
+ os.makedirs(output_dir3, exist_ok=True)
75
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
76
 
77
  @app.route('/')
78
  def index():
 
80
 
81
  @app.route('/upload', methods=['POST'])
82
  def upload_file():
83
+ recreate_directories()
84
  if 'invoice-upload' not in request.files:
85
  return jsonify({'error': 'No file part'}), 400
86
  file = request.files['invoice-upload']
87
  if file.filename == '':
88
  return jsonify({'error': 'No selected file'}), 400
89
  if file:
90
+ file_path = os.path.join('./app/data1', file.filename)
91
  file.save(file_path)
92
  output_image, output_csv = process_image()
93