cocoat commited on
Commit
3c01f56
·
verified ·
1 Parent(s): 71336a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -160,26 +160,27 @@ def infer(prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type,
160
 
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 設定(ダークモード強制防止+カフェ風テーマ)
184
  css = """
185
  @import url('https://fonts.googleapis.com/css2?family=Playpen+Sans+Hebrew:wght@100;200;300;400;500;600;700;800&display=swap');
 
160
 
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
 
164
+ import gc
165
+ import torch
166
+ def process_image(img, gallery_items): # Assuming this is part of a function
167
+ try:
168
+ gc.collect()
169
+ # Clear PyTorch's cache if GPU memory is being used
170
+ if torch.cuda.is_available():
171
+ torch.cuda.empty_cache()
172
+ return img, gallery_items
173
 
174
  except RuntimeError as e:
175
+ # Catch errors like CUDA Out of Memory
176
+ error_message = f"error in generate: {e}\n\n"
177
+ if "CUDA out of memory" in str(e):
178
+ error_message += "memory error"
179
+ else:
180
+ error_message += "other error"
181
+ print(error_message) # Output to server logs
182
+ return None, None
183
 
 
184
  # CSS 設定(ダークモード強制防止+カフェ風テーマ)
185
  css = """
186
  @import url('https://fonts.googleapis.com/css2?family=Playpen+Sans+Hebrew:wght@100;200;300;400;500;600;700;800&display=swap');