Update yml/generate-editor.py
Browse files- 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 |
-
# بخش
|
| 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 |
-
#
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
)
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
#
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 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!
|
| 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
|
| 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 |
# =========================================================
|