GitHub Actions commited on
Commit
119afca
·
1 Parent(s): 9047434

deploy: sync from GitHub 62437f241d21dd95904e6792927a3801c801368d

Browse files
Files changed (1) hide show
  1. app.py +1 -19
app.py CHANGED
@@ -12,13 +12,11 @@ import pickle
12
  import shutil
13
  import logging
14
  from ultralytics import YOLO
15
- # from ultralytics.utils import ThreadingLocked
16
  import numpy as np
17
  import pandas as pd
18
  from torch import cuda
19
  from flask import Flask, Response, render_template, request, jsonify, send_file, session
20
  from multiprocessing.pool import Pool
21
- from multiprocessing import set_start_method
22
  from concurrent.futures import ThreadPoolExecutor
23
  from pathlib import Path
24
  from PIL import Image
@@ -118,9 +116,7 @@ class _FutureWrapper:
118
  def get(self):
119
  return self._f.result()
120
 
121
- # need a global dict to hold async results objects
122
- # so you can check the progress of an abr
123
- # maybe there's a better way around this?
124
  async_results = {}
125
 
126
  @app.errorhandler(Exception)
@@ -129,9 +125,6 @@ def handle_exception(e):
129
  print(traceback.format_exc())
130
  return jsonify({"error": "Server error", "log": str(e)}), 500
131
 
132
- # def allowed_file(filename):
133
- # return '.' in filename and filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']
134
-
135
  @app.route('/')
136
  def index():
137
  return render_template('index.html')
@@ -142,12 +135,10 @@ def upload_files():
142
  session_id = session['id']
143
  files = request.files.getlist('files')
144
  upload_dir = Path(app.config['UPLOAD_FOLDER']) / session_id
145
- print(f"DEBUG /uploads: session_id={session_id}, upload_dir={upload_dir}")
146
  # clear out any existing files for the session
147
  if upload_dir.exists():
148
  shutil.rmtree(upload_dir)
149
  upload_dir.mkdir(parents=True, exist_ok=True)
150
- print(f"DEBUG /uploads: dir created, exists={upload_dir.exists()}")
151
  # generate new unique filenames via uuid, save the mapping dict of old:new to session
152
  filename_map = {}
153
  uuid_map_to_uuid_imgname = {}
@@ -243,13 +234,8 @@ def start_processing():
243
  # id from the /uploads call; the cookie may point to a different worker session.
244
  client_dir = Path(app.config['UPLOAD_FOLDER']) / client_session_id
245
  if client_dir.exists() or not (Path(app.config['UPLOAD_FOLDER']) / session_id).exists():
246
- print(f"DEBUG /process: using client-supplied session {client_session_id} "
247
- f"(cookie session was {session_id})")
248
  session_id = client_session_id
249
  session['id'] = session_id
250
- upload_dir_check = Path(app.config['UPLOAD_FOLDER']) / session_id
251
- print(f"DEBUG /process: session_id={session_id}, upload_dir={upload_dir_check}, exists={upload_dir_check.exists()}")
252
- print(f"DEBUG /process: /tmp/nemaquant/uploads contents={list(Path(app.config['UPLOAD_FOLDER']).iterdir()) if Path(app.config['UPLOAD_FOLDER']).exists() else 'UPLOAD_FOLDER missing'}")
253
  job_state = {
254
  "status": "starting",
255
  "progress": 0,
@@ -534,10 +520,6 @@ def export_csv():
534
  def ensure_session():
535
  if 'id' not in session:
536
  session['id'] = uuid.uuid4().hex
537
- print(f"New session started: {session['id']}")
538
- else:
539
- pass
540
- # print(f"Existing session: {session['id']}")
541
 
542
 
543
  def print_startup_info():
 
12
  import shutil
13
  import logging
14
  from ultralytics import YOLO
 
15
  import numpy as np
16
  import pandas as pd
17
  from torch import cuda
18
  from flask import Flask, Response, render_template, request, jsonify, send_file, session
19
  from multiprocessing.pool import Pool
 
20
  from concurrent.futures import ThreadPoolExecutor
21
  from pathlib import Path
22
  from PIL import Image
 
116
  def get(self):
117
  return self._f.result()
118
 
119
+ # Global dict mapping session_id -> async result (Pool AsyncResult or _FutureWrapper)
 
 
120
  async_results = {}
121
 
122
  @app.errorhandler(Exception)
 
125
  print(traceback.format_exc())
126
  return jsonify({"error": "Server error", "log": str(e)}), 500
127
 
 
 
 
128
  @app.route('/')
129
  def index():
130
  return render_template('index.html')
 
135
  session_id = session['id']
136
  files = request.files.getlist('files')
137
  upload_dir = Path(app.config['UPLOAD_FOLDER']) / session_id
 
138
  # clear out any existing files for the session
139
  if upload_dir.exists():
140
  shutil.rmtree(upload_dir)
141
  upload_dir.mkdir(parents=True, exist_ok=True)
 
142
  # generate new unique filenames via uuid, save the mapping dict of old:new to session
143
  filename_map = {}
144
  uuid_map_to_uuid_imgname = {}
 
234
  # id from the /uploads call; the cookie may point to a different worker session.
235
  client_dir = Path(app.config['UPLOAD_FOLDER']) / client_session_id
236
  if client_dir.exists() or not (Path(app.config['UPLOAD_FOLDER']) / session_id).exists():
 
 
237
  session_id = client_session_id
238
  session['id'] = session_id
 
 
 
239
  job_state = {
240
  "status": "starting",
241
  "progress": 0,
 
520
  def ensure_session():
521
  if 'id' not in session:
522
  session['id'] = uuid.uuid4().hex
 
 
 
 
523
 
524
 
525
  def print_startup_info():