Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -161,13 +161,23 @@ def infer(prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type,
|
|
| 161 |
gallery_items = [(item[0], item[1]) for item in history]
|
| 162 |
# tables_html = "".join(f'<div style="margin-bottom:12px">{make_html_table(item[1])}</div>' for item in history)
|
| 163 |
del img
|
|
|
|
| 164 |
# Pythonのガベージコレクタを強制実行し、不要なメモリを回収します
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
|
| 173 |
# CSS 設定(ダークモード強制防止+カフェ風テーマ)
|
|
|
|
| 161 |
gallery_items = [(item[0], item[1]) for item in history]
|
| 162 |
# tables_html = "".join(f'<div style="margin-bottom:12px">{make_html_table(item[1])}</div>' for item in history)
|
| 163 |
del img
|
| 164 |
+
|
| 165 |
# Pythonのガベージコレクタを強制実行し、不要なメモリを回収します
|
| 166 |
+
import gc
|
| 167 |
+
gc.collect()
|
| 168 |
+
# GPUメモリを使用している場合、PyTorchのキャッシュをクリアします
|
| 169 |
+
if torch.cuda.is_available():
|
| 170 |
+
torch.cuda.empty_cache()
|
| 171 |
+
return img, gallery_items
|
| 172 |
+
|
| 173 |
+
except RuntimeError as e:
|
| 174 |
+
# CUDA Out of Memoryなどのエラーをキャッチ
|
| 175 |
+
error_message = f"画像生成中にエラーが発生しました: {e}\n\n"
|
| 176 |
+
if "CUDA out of memory" in str(e):
|
| 177 |
+
error_message += "GPUメモリが不足している可能性があります。画像のサイズを小さくするか、ステップ数を減らしてみてください。"
|
| 178 |
+
else:
|
| 179 |
+
error_message += "原因不明のエラーです。入力パラメータを確認してください。"
|
| 180 |
+
print(error_message) # サーバーログに出力
|
| 181 |
|
| 182 |
|
| 183 |
# CSS 設定(ダークモード強制防止+カフェ風テーマ)
|