yeq6x commited on
Commit
5426f86
·
1 Parent(s): e9f2510
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -23,6 +23,7 @@ from gevent import pywsgi
23
  from geventwebsocket.handler import WebSocketHandler
24
 
25
  app = Flask(__name__)
 
26
  CORS(app)
27
  socketio = SocketIO(app, cors_allowed_origins="*")
28
 
@@ -59,13 +60,12 @@ def update_queue_status(message):
59
 
60
  def process_task(task):
61
  try:
 
62
  client_id = session.get("sid")
63
- print(f"client_id: {client_id}")
64
  task.is_processing = True
65
  # ファイルデータをPIL Imageに変換
66
  image = Image.open(io.BytesIO(task.file_data))
67
  image = ensure_rgb(image)
68
- update_queue_status('Task 1')
69
 
70
  # キャンセルチェック
71
  if task.cancel_flag:
@@ -73,12 +73,10 @@ def process_task(task):
73
 
74
  # 画像処理ロジックを呼び出す
75
  sotai_image, sketch_image = process_image_as_base64(image, task.mode, task.weight1, task.weight2)
76
- update_queue_status('Task 2')
77
 
78
  # キャンセルチェック
79
  if task.cancel_flag:
80
  return
81
- update_queue_status('Task 3')
82
 
83
  socketio.emit('task_complete', {
84
  'task_id': task.task_id,
@@ -86,8 +84,8 @@ def process_task(task):
86
  'sketch_image': sketch_image
87
  }, to=client_id)
88
  except Exception as e:
89
- # print(f"Task error: {str(e)}")
90
- # if not task.cancel_flag:
91
  socketio.emit('task_error', {'task_id': task.task_id, 'error': str(e)}, to=client_id)
92
  finally:
93
  task.is_processing = False
@@ -100,7 +98,7 @@ def process_task(task):
100
  client_ip = task.client_ip
101
  tasks_per_client[client_ip] = tasks_per_client.get(client_ip, 0) - 1
102
 
103
- update_queue_status('Task completed or cancelled4')
104
 
105
  def worker():
106
  while True:
 
23
  from geventwebsocket.handler import WebSocketHandler
24
 
25
  app = Flask(__name__)
26
+ app.secret_key = 'user'
27
  CORS(app)
28
  socketio = SocketIO(app, cors_allowed_origins="*")
29
 
 
60
 
61
  def process_task(task):
62
  try:
63
+ update_queue_status(str("sid" in session))
64
  client_id = session.get("sid")
 
65
  task.is_processing = True
66
  # ファイルデータをPIL Imageに変換
67
  image = Image.open(io.BytesIO(task.file_data))
68
  image = ensure_rgb(image)
 
69
 
70
  # キャンセルチェック
71
  if task.cancel_flag:
 
73
 
74
  # 画像処理ロジックを呼び出す
75
  sotai_image, sketch_image = process_image_as_base64(image, task.mode, task.weight1, task.weight2)
 
76
 
77
  # キャンセルチェック
78
  if task.cancel_flag:
79
  return
 
80
 
81
  socketio.emit('task_complete', {
82
  'task_id': task.task_id,
 
84
  'sketch_image': sketch_image
85
  }, to=client_id)
86
  except Exception as e:
87
+ print(f"Task error: {str(e)}")
88
+ if not task.cancel_flag:
89
  socketio.emit('task_error', {'task_id': task.task_id, 'error': str(e)}, to=client_id)
90
  finally:
91
  task.is_processing = False
 
98
  client_ip = task.client_ip
99
  tasks_per_client[client_ip] = tasks_per_client.get(client_ip, 0) - 1
100
 
101
+ update_queue_status('Task completed or cancelled')
102
 
103
  def worker():
104
  while True: