Spaces:
Running
on
Zero
Running
on
Zero
requirements
Browse files- app.py +4 -5
- requirements.txt +2 -2
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from flask import Flask, request, render_template, send_file, jsonify, send_from_directory
|
2 |
from flask_socketio import SocketIO, join_room, leave_room, close_room, rooms, disconnect
|
3 |
-
from flask_socketio import request as socketio_request
|
4 |
from flask_cors import CORS
|
5 |
from flask_limiter import Limiter
|
6 |
from flask_limiter.util import get_remote_address
|
@@ -60,7 +59,7 @@ def update_queue_status(message):
|
|
60 |
|
61 |
def process_task(task):
|
62 |
try:
|
63 |
-
client_id =
|
64 |
task.is_processing = True
|
65 |
# ファイルデータをPIL Imageに変換
|
66 |
image = Image.open(io.BytesIO(task.file_data))
|
@@ -119,14 +118,14 @@ connected_clients = 0
|
|
119 |
tasks_per_client = {}
|
120 |
@socketio.on('connect')
|
121 |
def handle_connect(auth):
|
122 |
-
client_id =
|
123 |
join_room(client_id) # クライアントを自身のルームに入れる
|
124 |
global connected_clients
|
125 |
connected_clients += 1
|
126 |
|
127 |
@socketio.on('disconnect')
|
128 |
def handle_disconnect():
|
129 |
-
client_id =
|
130 |
leave_room(client_id) # クライアントをルームから出す
|
131 |
global connected_clients
|
132 |
connected_clients -= 1
|
@@ -149,7 +148,7 @@ def submit_task():
|
|
149 |
|
150 |
# クライアントIPアドレスを取得
|
151 |
client_ip = get_remote_address()
|
152 |
-
client_id =
|
153 |
|
154 |
# 同一IPからの同時タスク数を制限
|
155 |
if tasks_per_client.get(client_ip, 0) >= 2:
|
|
|
1 |
from flask import Flask, request, render_template, send_file, jsonify, send_from_directory
|
2 |
from flask_socketio import SocketIO, join_room, leave_room, close_room, rooms, disconnect
|
|
|
3 |
from flask_cors import CORS
|
4 |
from flask_limiter import Limiter
|
5 |
from flask_limiter.util import get_remote_address
|
|
|
59 |
|
60 |
def process_task(task):
|
61 |
try:
|
62 |
+
client_id = request.sid
|
63 |
task.is_processing = True
|
64 |
# ファイルデータをPIL Imageに変換
|
65 |
image = Image.open(io.BytesIO(task.file_data))
|
|
|
118 |
tasks_per_client = {}
|
119 |
@socketio.on('connect')
|
120 |
def handle_connect(auth):
|
121 |
+
client_id = request.sid # クライアントIDを取得
|
122 |
join_room(client_id) # クライアントを自身のルームに入れる
|
123 |
global connected_clients
|
124 |
connected_clients += 1
|
125 |
|
126 |
@socketio.on('disconnect')
|
127 |
def handle_disconnect():
|
128 |
+
client_id = request.sid # クライアントIDを取得
|
129 |
leave_room(client_id) # クライアントをルームから出す
|
130 |
global connected_clients
|
131 |
connected_clients -= 1
|
|
|
148 |
|
149 |
# クライアントIPアドレスを取得
|
150 |
client_ip = get_remote_address()
|
151 |
+
client_id = request.sid # クライアントIDを取得
|
152 |
|
153 |
# 同一IPからの同時タスク数を制限
|
154 |
if tasks_per_client.get(client_ip, 0) >= 2:
|
requirements.txt
CHANGED
@@ -3,9 +3,9 @@ torch==2.2.0
|
|
3 |
torchvision==0.17.0
|
4 |
torchaudio==2.2.0
|
5 |
diffusers==0.27.0 # pth file cannot be loaded in the latest version
|
6 |
-
Flask==
|
7 |
Flask-Cors==4.0.0
|
8 |
-
Flask-SocketIO==
|
9 |
gradio==4.36.1
|
10 |
huggingface_hub==0.23.2
|
11 |
kornia==0.7.1
|
|
|
3 |
torchvision==0.17.0
|
4 |
torchaudio==2.2.0
|
5 |
diffusers==0.27.0 # pth file cannot be loaded in the latest version
|
6 |
+
Flask==2.8.0
|
7 |
Flask-Cors==4.0.0
|
8 |
+
Flask-SocketIO==4.4.0
|
9 |
gradio==4.36.1
|
10 |
huggingface_hub==0.23.2
|
11 |
kornia==0.7.1
|