cocoat commited on
Commit
6056f06
·
verified ·
1 Parent(s): 963e626

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -109,12 +109,8 @@ euler_scheduler = EulerAncestralDiscreteScheduler.from_config(
109
  dpm_scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
110
  pipe.scheduler = euler_scheduler
111
 
112
- def upload_image_to_hub(image_pil, prompt_text):
113
  # ファイル名を生成(タイムスタンプとプロンプトの一部)
114
- timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
115
- # プロンプトから安全なファイル名の一部を生成
116
- # safe_prompt = "".join(c for c in prompt_text if c.isalnum() or c in (' ', '.', '_')).replace(' ', '_')[:30]
117
- filename = f"image_{timestamp}.png"
118
  filepath = f"temp_{filename}"
119
  image_pil.save(filepath)
120
 
@@ -159,10 +155,9 @@ def upload_image_to_hub(image_pil, prompt_text):
159
  finally:
160
  pass
161
 
162
- def upload_image_to_private_hub(image_pil, prompt_text):
163
- timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
164
- filename = f"image_{timestamp}.png"
165
- filepath = f"temp_private_{filename}" # 一時ファイル名が重複しないように private を追加
166
  image_pil.save(filepath)
167
 
168
  try:
@@ -262,9 +257,9 @@ def infer(prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type,
262
  caption_text_for_history = caption_text.replace("\n", "|-|").strip()
263
  # 画像をHubにアップロードし、そのURLとリポジトリ内パスを取得
264
  # 公開用リポジトリにアップロード
265
- uploaded_image_url, path_in_public_repo_for_history = upload_image_to_hub(img, caption_text)
266
  # 非公開リポジトリにアップロード
267
- path_in_private_repo_for_history = upload_image_to_private_hub(img, caption_text)
268
 
269
 
270
  # 履歴を更新
 
109
  dpm_scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
110
  pipe.scheduler = euler_scheduler
111
 
112
+ def upload_image_to_hub(image_pil, prompt_text, filename)):
113
  # ファイル名を生成(タイムスタンプとプロンプトの一部)
 
 
 
 
114
  filepath = f"temp_{filename}"
115
  image_pil.save(filepath)
116
 
 
155
  finally:
156
  pass
157
 
158
+ def upload_image_to_private_hub(image_pil, prompt_text, filename):
159
+
160
+ filepath = f"temp_private_{filename}"
 
161
  image_pil.save(filepath)
162
 
163
  try:
 
257
  caption_text_for_history = caption_text.replace("\n", "|-|").strip()
258
  # 画像をHubにアップロードし、そのURLとリポジトリ内パスを取得
259
  # 公開用リポジトリにアップロード
260
+ uploaded_image_url, path_in_public_repo_for_history = upload_image_to_hub(img, caption_text, filename)
261
  # 非公開リポジトリにアップロード
262
+ path_in_private_repo_for_history = upload_image_to_private_hub(img, caption_text, filename)
263
 
264
 
265
  # 履歴を更新