Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import os, random, tempfile, json
|
|
| 6 |
import re
|
| 7 |
import threading
|
| 8 |
import uuid
|
|
|
|
| 9 |
|
| 10 |
# --- API設定 ---
|
| 11 |
API_KEY = os.getenv("API_KEY")
|
|
@@ -71,19 +72,17 @@ def _new_session_state():
|
|
| 71 |
|
| 72 |
# --- ログ追記(CSVのみ・固定カラムで統一) ---
|
| 73 |
def log_to_csv(entry: dict):
|
|
|
|
| 74 |
with _log_lock:
|
| 75 |
-
row = {col: entry.get(col, None) for col in LOG_COLUMNS}
|
| 76 |
-
df = pd.DataFrame([row], columns=LOG_COLUMNS)
|
| 77 |
-
|
| 78 |
file_exists = os.path.exists(LOG_FILE)
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
def log_event(state: dict, **kwargs):
|
| 89 |
# ✅ Excelで#####になりにくいよう「JST」を付けてテキスト化
|
|
@@ -403,4 +402,5 @@ with gr.Blocks() as demo:
|
|
| 403 |
outputs=[dl_file, dl_msg]
|
| 404 |
)
|
| 405 |
|
| 406 |
-
|
|
|
|
|
|
| 6 |
import re
|
| 7 |
import threading
|
| 8 |
import uuid
|
| 9 |
+
import csv # ✅ 追加:csv.writer用
|
| 10 |
|
| 11 |
# --- API設定 ---
|
| 12 |
API_KEY = os.getenv("API_KEY")
|
|
|
|
| 72 |
|
| 73 |
# --- ログ追記(CSVのみ・固定カラムで統一) ---
|
| 74 |
def log_to_csv(entry: dict):
|
| 75 |
+
# ✅ pandas -> csv.writer に置換(列順は LOG_COLUMNS で保証)
|
| 76 |
with _log_lock:
|
|
|
|
|
|
|
|
|
|
| 77 |
file_exists = os.path.exists(LOG_FILE)
|
| 78 |
+
|
| 79 |
+
with open(LOG_FILE, mode="a", encoding="utf-8", newline="") as f:
|
| 80 |
+
writer = csv.DictWriter(f, fieldnames=LOG_COLUMNS)
|
| 81 |
+
if not file_exists:
|
| 82 |
+
writer.writeheader()
|
| 83 |
+
|
| 84 |
+
row = {col: entry.get(col, None) for col in LOG_COLUMNS}
|
| 85 |
+
writer.writerow(row)
|
| 86 |
|
| 87 |
def log_event(state: dict, **kwargs):
|
| 88 |
# ✅ Excelで#####になりにくいよう「JST」を付けてテキスト化
|
|
|
|
| 402 |
outputs=[dl_file, dl_msg]
|
| 403 |
)
|
| 404 |
|
| 405 |
+
# ✅ 追加:queue(同時アクセス耐性UP)
|
| 406 |
+
demo.queue(max_size=64).launch()
|