cocoat commited on
Commit
f1d7767
·
verified ·
1 Parent(s): 95021a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
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
- import gc
166
- gc.collect()
167
- # GPUメモリを使用している場合、PyTorchのキャッシュをクリアします
168
- if torch.cuda.is_available():
169
- torch.cuda.empty_cache()
170
- return img, gallery_items
 
 
 
 
 
 
 
 
 
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 設定(ダークモード強制防止+カフェ風テーマ)