Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,6 +90,14 @@ LORA_MAPPING = {
|
|
| 90 |
"افزایش کیفیت (Upscale)": "upscale-image"
|
| 91 |
}
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
def translate_prompt(text):
|
| 94 |
"""ترجمه متن فارسی به انگلیسی"""
|
| 95 |
if not text:
|
|
@@ -130,6 +138,7 @@ def infer(
|
|
| 130 |
randomize_seed,
|
| 131 |
guidance_scale,
|
| 132 |
steps,
|
|
|
|
| 133 |
progress=gr.Progress(track_tqdm=True)
|
| 134 |
):
|
| 135 |
if input_image is None:
|
|
@@ -148,7 +157,18 @@ def infer(
|
|
| 148 |
negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
|
| 149 |
|
| 150 |
original_image = input_image.convert("RGB")
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
result = pipe(
|
| 154 |
image=original_image,
|
|
@@ -168,7 +188,8 @@ def infer_example(input_image, prompt, lora_adapter):
|
|
| 168 |
input_pil = input_image.convert("RGB")
|
| 169 |
guidance_scale = 1.0
|
| 170 |
steps = 4
|
| 171 |
-
|
|
|
|
| 172 |
return result, seed
|
| 173 |
|
| 174 |
|
|
@@ -266,6 +287,7 @@ textarea, input[type="text"] {
|
|
| 266 |
background-color: #ffffff !important;
|
| 267 |
color: #111827 !important;
|
| 268 |
padding: 12px !important;
|
|
|
|
| 269 |
font-family: 'Vazirmatn', sans-serif !important;
|
| 270 |
}
|
| 271 |
|
|
@@ -313,7 +335,7 @@ textarea:focus, input[type="text"]:focus {
|
|
| 313 |
box-shadow: 0 8px 25px rgba(59, 130, 246, 0.45) !important;
|
| 314 |
}
|
| 315 |
|
| 316 |
-
/* --- 6. بخش نمونهها
|
| 317 |
.gradio-container .prose table,
|
| 318 |
.gradio-container table {
|
| 319 |
background-color: #ffffff !important;
|
|
@@ -427,10 +449,17 @@ with gr.Blocks() as demo:
|
|
| 427 |
choices=list(LORA_MAPPING.keys()),
|
| 428 |
value="تبدیل عکس به انیمه"
|
| 429 |
)
|
|
|
|
|
|
|
| 430 |
with gr.Accordion("تنظیمات پیشرفته", open=False, visible=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
seed = gr.Slider(label="دانه تصادفی (Seed)", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
| 432 |
randomize_seed = gr.Checkbox(label="استفاده از Seed تصادفی", value=True)
|
| 433 |
-
# اصلاح شده: استفاده از آرگومانهای با نام
|
| 434 |
guidance_scale = gr.Slider(label="میزان وفاداری به متن (Guidance Scale)", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
|
| 435 |
steps = gr.Slider(label="تعداد مراحل پردازش (Steps)", minimum=1, maximum=50, step=1, value=4)
|
| 436 |
|
|
@@ -459,7 +488,7 @@ with gr.Blocks() as demo:
|
|
| 459 |
# اتصال دکمه اجرا
|
| 460 |
run_button.click(
|
| 461 |
fn=infer,
|
| 462 |
-
inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
|
| 463 |
outputs=[output_image, seed]
|
| 464 |
)
|
| 465 |
|
|
|
|
| 90 |
"افزایش کیفیت (Upscale)": "upscale-image"
|
| 91 |
}
|
| 92 |
|
| 93 |
+
# --- گزینههای نسبت ابعاد ---
|
| 94 |
+
ASPECT_RATIOS = {
|
| 95 |
+
"خودکار (پیشفرض)": "Auto",
|
| 96 |
+
"۱:۱ (مربع)": (1024, 1024),
|
| 97 |
+
"۱۶:۹ (افقی - لنداسکیپ)": (1344, 768),
|
| 98 |
+
"۹:۱۶ (عمودی - استوری)": (768, 1344)
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
def translate_prompt(text):
|
| 102 |
"""ترجمه متن فارسی به انگلیسی"""
|
| 103 |
if not text:
|
|
|
|
| 138 |
randomize_seed,
|
| 139 |
guidance_scale,
|
| 140 |
steps,
|
| 141 |
+
aspect_ratio_selection, # پارامتر جدید
|
| 142 |
progress=gr.Progress(track_tqdm=True)
|
| 143 |
):
|
| 144 |
if input_image is None:
|
|
|
|
| 157 |
negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
|
| 158 |
|
| 159 |
original_image = input_image.convert("RGB")
|
| 160 |
+
|
| 161 |
+
# --- منطق تعیین ابعاد ---
|
| 162 |
+
if aspect_ratio_selection == "خودکار (پیشفرض)" or aspect_ratio_selection is None:
|
| 163 |
+
width, height = update_dimensions_on_upload(original_image)
|
| 164 |
+
else:
|
| 165 |
+
# دریافت ابعاد از دیکشنری
|
| 166 |
+
dims = ASPECT_RATIOS.get(aspect_ratio_selection)
|
| 167 |
+
if dims and isinstance(dims, tuple):
|
| 168 |
+
width, height = dims
|
| 169 |
+
else:
|
| 170 |
+
# fallback to auto
|
| 171 |
+
width, height = update_dimensions_on_upload(original_image)
|
| 172 |
|
| 173 |
result = pipe(
|
| 174 |
image=original_image,
|
|
|
|
| 188 |
input_pil = input_image.convert("RGB")
|
| 189 |
guidance_scale = 1.0
|
| 190 |
steps = 4
|
| 191 |
+
# برای نمونهها حالت خودکار را پیشفرض قرار میدهیم
|
| 192 |
+
result, seed = infer(input_pil, prompt, lora_adapter, 0, True, guidance_scale, steps, "خودکار (پیشفرض)")
|
| 193 |
return result, seed
|
| 194 |
|
| 195 |
|
|
|
|
| 287 |
background-color: #ffffff !important;
|
| 288 |
color: #111827 !important;
|
| 289 |
padding: 12px !important;
|
| 290 |
+
transition: all 0.3s ease;
|
| 291 |
font-family: 'Vazirmatn', sans-serif !important;
|
| 292 |
}
|
| 293 |
|
|
|
|
| 335 |
box-shadow: 0 8px 25px rgba(59, 130, 246, 0.45) !important;
|
| 336 |
}
|
| 337 |
|
| 338 |
+
/* --- 6. بخش نمونهها --- */
|
| 339 |
.gradio-container .prose table,
|
| 340 |
.gradio-container table {
|
| 341 |
background-color: #ffffff !important;
|
|
|
|
| 449 |
choices=list(LORA_MAPPING.keys()),
|
| 450 |
value="تبدیل عکس به انیمه"
|
| 451 |
)
|
| 452 |
+
|
| 453 |
+
# --- تنظیمات پیشرفته با قابلیت انتخاب سایز ---
|
| 454 |
with gr.Accordion("تنظیمات پیشرفته", open=False, visible=True):
|
| 455 |
+
aspect_ratio_selection = gr.Dropdown(
|
| 456 |
+
label="ابعاد تصویر خروجی",
|
| 457 |
+
choices=list(ASPECT_RATIOS.keys()),
|
| 458 |
+
value="خودکار (پیشفرض)",
|
| 459 |
+
interactive=True
|
| 460 |
+
)
|
| 461 |
seed = gr.Slider(label="دانه تصادفی (Seed)", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
| 462 |
randomize_seed = gr.Checkbox(label="استفاده از Seed تصادفی", value=True)
|
|
|
|
| 463 |
guidance_scale = gr.Slider(label="میزان وفاداری به متن (Guidance Scale)", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
|
| 464 |
steps = gr.Slider(label="تعداد مراحل پردازش (Steps)", minimum=1, maximum=50, step=1, value=4)
|
| 465 |
|
|
|
|
| 488 |
# اتصال دکمه اجرا
|
| 489 |
run_button.click(
|
| 490 |
fn=infer,
|
| 491 |
+
inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps, aspect_ratio_selection],
|
| 492 |
outputs=[output_image, seed]
|
| 493 |
)
|
| 494 |
|