Opera8 commited on
Commit
8a73758
·
verified ·
1 Parent(s): 3ed7d57

Update yml/generate-editor.py

Browse files
Files changed (1) hide show
  1. yml/generate-editor.py +33 -27
yml/generate-editor.py CHANGED
@@ -185,36 +185,42 @@ except Exception as dl_err:
185
  sys.exit(1)
186
 
187
  # =========================================================
188
- # بخش افزوده شده: ارتباط با CodeFormer برای افزایش کیفیت و بزرگ‌نمایی تصویر خروجی
189
  print('4.5. Connecting to CodeFormer to restore and upscale (Factor=4, Fidelity=1.0)...')
190
  try:
191
  cf_client = Client('sczhou/CodeFormer')
192
  upscale_result = None
193
 
194
- # تست با الگوی ۶ پارامتری (حاوی پارامتر face_align در پلتفرم جدید)
195
- try:
196
- print(' -> Attempting CodeFormer with 6-parameter interface...')
197
- upscale_result = cf_client.predict(
198
- handle_file(filename), # تصویر ورودی ویرایش شده
199
- True, # Face Align
200
- True, # Background Enhance
201
- True, # Face Upsample
202
- 4, # Rescaling Factor (تنظیم شده بر روی ۴)
203
- 1.0, # CodeFormer Fidelity (تنظیم شده بر روی ۱.۰)
204
- api_name='/predict'
205
- )
206
- except Exception as cf_e6:
207
- print(f' -> 6-parameter attempt failed: {cf_e6}. Falling back to 5-parameter interface...')
208
- # متد جایگزین ۵ پارامتری برای نسخه‌های قدیمی اسپیس CodeFormer
209
- upscale_result = cf_client.predict(
210
- handle_file(filename), # تصویر ورودی ویرایش شده
211
- True, # Background Enhance
212
- True, # Face Upsample
213
- 4, # Rescaling Factor (تنظیم شده بر روی ۴)
214
- 1.0, # CodeFormer Fidelity (تنظیم شده بر روی ۱.۰)
215
- api_name='/predict'
216
- )
217
-
 
 
 
 
 
 
218
  upscale_path = None
219
  if isinstance(upscale_result, list) and len(upscale_result) > 0:
220
  upscale_path = upscale_result[0]
@@ -226,7 +232,7 @@ try:
226
  upscale_path = upscale_result
227
 
228
  if upscale_path and os.path.exists(str(upscale_path)):
229
- print(f' -> CodeFormer Success! Saved locally at {upscale_path}')
230
  upscale_ext = 'png'
231
  if str(upscale_path).endswith('.webp'):
232
  upscale_ext = 'webp'
@@ -246,7 +252,7 @@ try:
246
  else:
247
  print(f' -> Enhanced image upload failed: {res_up.status_code} - {res_up.text}')
248
  else:
249
- print(' -> Warning: CodeFormer did not return a valid image file path.')
250
  except Exception as cf_err:
251
  print(f' -> Warning: CodeFormer process bypassed or failed: {cf_err}')
252
  # =========================================================
 
185
  sys.exit(1)
186
 
187
  # =========================================================
188
+ # بخش بهبودیافته: تلاش چندجانبه برای ارتباط موفق با API اسپیس CodeFormer
189
  print('4.5. Connecting to CodeFormer to restore and upscale (Factor=4, Fidelity=1.0)...')
190
  try:
191
  cf_client = Client('sczhou/CodeFormer')
192
  upscale_result = None
193
 
194
+ # ساختار مانیتورینگ متدهای متوالی برای جلوگیری از بروز خطای api_name
195
+ methods_to_try = [
196
+ # روش ۱: استفاده از ایندکس صفر به همراه ساختار ۶ پارامتری (ویرایش جدید اسپیس)
197
+ {"args": [handle_file(filename), True, True, True, 4, 1.0], "kwargs": {"fn_index": 0}},
198
+ # روش ۲: استفاده از ایندکس صفر به همراه ساختار ۵ پارامتری (نسخه‌های پایدار قدیمی)
199
+ {"args": [handle_file(filename), True, True, 4, 1.0], "kwargs": {"fn_index": 0}},
200
+ # روش ۳: تلاش با ایندکس یک به همراه ساختار ۶ پارامتری
201
+ {"args": [handle_file(filename), True, True, True, 4, 1.0], "kwargs": {"fn_index": 1}},
202
+ # روش ۴: تلاش با ایندکس یک به همراه ساختار ۵ پارامتری
203
+ {"args": [handle_file(filename), True, True, 4, 1.0], "kwargs": {"fn_index": 1}},
204
+ # روش ۵: فراخوانی اسمی بدون اسلش (predict) با ساختار ۶ پارامتری
205
+ {"args": [handle_file(filename), True, True, True, 4, 1.0], "kwargs": {"api_name": "predict"}},
206
+ # روش ۶: فراخوانی اسمی بدون اسلش (predict) با ساختار ۵ پارامتری
207
+ {"args": [handle_file(filename), True, True, 4, 1.0], "kwargs": {"api_name": "predict"}},
208
+ # روش ۷: فراخوانی اسمی با اسلش (/predict) با ساختار ۶ پارامتری
209
+ {"args": [handle_file(filename), True, True, True, 4, 1.0], "kwargs": {"api_name": "/predict"}},
210
+ # روش ۸: فراخوانی اسمی با اسلش (/predict) با ساختار ۵ پارامتری
211
+ {"args": [handle_file(filename), True, True, 4, 1.0], "kwargs": {"api_name": "/predict"}},
212
+ ]
213
+
214
+ for idx, method in enumerate(methods_to_try):
215
+ try:
216
+ print(f' -> Trying execution path {idx + 1} of {len(methods_to_try)}...')
217
+ upscale_result = cf_client.predict(*method["args"], **method["kwargs"])
218
+ if upscale_result:
219
+ print(f' -> Success! CodeFormer handled by path {idx + 1}.')
220
+ break
221
+ except Exception as method_err:
222
+ print(f' -> Path {idx + 1} bypassed: {method_err}')
223
+
224
  upscale_path = None
225
  if isinstance(upscale_result, list) and len(upscale_result) > 0:
226
  upscale_path = upscale_result[0]
 
232
  upscale_path = upscale_result
233
 
234
  if upscale_path and os.path.exists(str(upscale_path)):
235
+ print(f' -> CodeFormer Success! Output saved at {upscale_path}')
236
  upscale_ext = 'png'
237
  if str(upscale_path).endswith('.webp'):
238
  upscale_ext = 'webp'
 
252
  else:
253
  print(f' -> Enhanced image upload failed: {res_up.status_code} - {res_up.text}')
254
  else:
255
+ print(' -> Warning: CodeFormer did not return a valid file path.')
256
  except Exception as cf_err:
257
  print(f' -> Warning: CodeFormer process bypassed or failed: {cf_err}')
258
  # =========================================================