Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,11 @@ from qwenimage.pipeline_qwenimage_edit_plus import QwenImageEditPlusPipeline
|
|
| 12 |
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
| 13 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 14 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# --- Translation Function ---
|
| 17 |
@spaces.GPU
|
|
@@ -29,10 +34,10 @@ def translate_albanian_to_english(text, language="en"):
|
|
| 29 |
)
|
| 30 |
response.raise_for_status()
|
| 31 |
translated = response.json().get("translate", "")
|
| 32 |
-
|
| 33 |
return translated
|
| 34 |
except Exception as e:
|
| 35 |
-
|
| 36 |
if attempt == 1:
|
| 37 |
raise gr.Error("Translation failed. Please try again.")
|
| 38 |
raise gr.Error("Translation failed. Please try again.")
|
|
@@ -85,11 +90,7 @@ QUALITY_PROMPT = ", high quality, detailed, vibrant, professional lighting"
|
|
| 85 |
|
| 86 |
# --- Main Inference Function ---
|
| 87 |
@spaces.GPU(duration=40)
|
| 88 |
-
def infer(
|
| 89 |
-
image,
|
| 90 |
-
prompt,
|
| 91 |
-
progress=gr.Progress(track_tqdm=True),
|
| 92 |
-
):
|
| 93 |
"""
|
| 94 |
Generates an image using the local Qwen-Image diffusers pipeline.
|
| 95 |
"""
|
|
@@ -118,14 +119,14 @@ def infer(
|
|
| 118 |
elif hasattr(image, "name"):
|
| 119 |
pil_image = Image.open(image.name).convert("RGB")
|
| 120 |
except Exception as e:
|
| 121 |
-
|
| 122 |
raise gr.Error("Failed to load input image.")
|
| 123 |
|
| 124 |
if height == 256 and width == 256:
|
| 125 |
height, width = None, None
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
# Generate the image
|
| 131 |
output = pipe(
|
|
@@ -281,25 +282,6 @@ def create_demo():
|
|
| 281 |
div[aria-label="Input Image"] .gr-button {
|
| 282 |
display: none !important; /* Force hide all toolbar elements */
|
| 283 |
}
|
| 284 |
-
.image-container.processing {
|
| 285 |
-
background: #000000 !important;
|
| 286 |
-
}
|
| 287 |
-
.image-container.processing::before {
|
| 288 |
-
content: "Processing...";
|
| 289 |
-
color: #FFFFFF !important;
|
| 290 |
-
opacity: 0.7;
|
| 291 |
-
font-size: 1rem;
|
| 292 |
-
font-weight: 600;
|
| 293 |
-
position: absolute;
|
| 294 |
-
top: 50%;
|
| 295 |
-
left: 50%;
|
| 296 |
-
transform: translate(-50%, -50%);
|
| 297 |
-
text-align: center;
|
| 298 |
-
width: auto;
|
| 299 |
-
max-width: 150px;
|
| 300 |
-
white-space: nowrap;
|
| 301 |
-
display: inline-block;
|
| 302 |
-
}
|
| 303 |
input, textarea {
|
| 304 |
background: #000000 !important;
|
| 305 |
color: #FFFFFF !important;
|
|
@@ -355,8 +337,8 @@ def create_demo():
|
|
| 355 |
button[aria-label="Download"]:hover {
|
| 356 |
box-shadow: 0 0 12px rgba(255, 255, 255, 0.5) !important;
|
| 357 |
}
|
| 358 |
-
.progress-text, .gr-progress {
|
| 359 |
-
display: none !important;
|
| 360 |
}
|
| 361 |
footer, .gr-button-secondary {
|
| 362 |
display: none !important;
|
|
@@ -389,11 +371,6 @@ def create_demo():
|
|
| 389 |
box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important;
|
| 390 |
border: 0.5px solid #FFFFFF !important; /* Thinner white border */
|
| 391 |
}
|
| 392 |
-
.image-container.processing::before {
|
| 393 |
-
font-size: 0.9rem;
|
| 394 |
-
max-width: 90%;
|
| 395 |
-
white-space: normal;
|
| 396 |
-
}
|
| 397 |
}
|
| 398 |
</style>
|
| 399 |
<script>
|
|
@@ -406,11 +383,6 @@ def create_demo():
|
|
| 406 |
console.log(`Container ${container.id || container.className}: width=${width}px, box-shadow=${style.boxShadow}, background=${style.background}, border=${style.border} (Viewport: ${window.innerWidth}px)`);
|
| 407 |
container.setAttribute('data-width', `${width}px`);
|
| 408 |
});
|
| 409 |
-
const processingText = document.querySelectorAll('.image-container.processing::before');
|
| 410 |
-
processingText.forEach(text => {
|
| 411 |
-
const style = window.getComputedStyle(text);
|
| 412 |
-
console.log(`Processing text: width=${style.width}, font-size=${style.fontSize}`);
|
| 413 |
-
});
|
| 414 |
const editButton = document.querySelector('.gr-button-primary');
|
| 415 |
if (editButton) {
|
| 416 |
const style = window.getComputedStyle(editButton);
|
|
@@ -457,23 +429,12 @@ def create_demo():
|
|
| 457 |
toolbar.style.display = 'none';
|
| 458 |
console.log(`Forced hide toolbar: ${toolbar.className}`);
|
| 459 |
});
|
| 460 |
-
//
|
| 461 |
-
const
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
console.log('Processing state added to result_image');
|
| 467 |
-
});
|
| 468 |
-
const observer = new MutationObserver(() => {
|
| 469 |
-
if (resultImage.querySelector('img')) {
|
| 470 |
-
resultImage.classList.remove('processing');
|
| 471 |
-
console.log('Processing state removed from result_image');
|
| 472 |
-
observer.disconnect();
|
| 473 |
-
}
|
| 474 |
-
});
|
| 475 |
-
observer.observe(resultImage, { childList: true, subtree: true });
|
| 476 |
-
}
|
| 477 |
});
|
| 478 |
</script>
|
| 479 |
""")
|
|
@@ -520,6 +481,6 @@ def create_demo():
|
|
| 520 |
return demo
|
| 521 |
|
| 522 |
if __name__ == "__main__":
|
| 523 |
-
|
| 524 |
demo = create_demo()
|
| 525 |
demo.queue().launch(share=True)
|
|
|
|
| 12 |
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
| 13 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 14 |
import requests
|
| 15 |
+
import logging
|
| 16 |
+
|
| 17 |
+
# Set up logging to suppress print statements in UI
|
| 18 |
+
logging.basicConfig(level=logging.INFO, filename='qwen_image_editor.log', filemode='a')
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
# --- Translation Function ---
|
| 22 |
@spaces.GPU
|
|
|
|
| 34 |
)
|
| 35 |
response.raise_for_status()
|
| 36 |
translated = response.json().get("translate", "")
|
| 37 |
+
logger.info(f"Translation response: {translated}")
|
| 38 |
return translated
|
| 39 |
except Exception as e:
|
| 40 |
+
logger.error(f"Translation error (attempt {attempt + 1}): {e}")
|
| 41 |
if attempt == 1:
|
| 42 |
raise gr.Error("Translation failed. Please try again.")
|
| 43 |
raise gr.Error("Translation failed. Please try again.")
|
|
|
|
| 90 |
|
| 91 |
# --- Main Inference Function ---
|
| 92 |
@spaces.GPU(duration=40)
|
| 93 |
+
def infer(image, prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
"""
|
| 95 |
Generates an image using the local Qwen-Image diffusers pipeline.
|
| 96 |
"""
|
|
|
|
| 119 |
elif hasattr(image, "name"):
|
| 120 |
pil_image = Image.open(image.name).convert("RGB")
|
| 121 |
except Exception as e:
|
| 122 |
+
logger.error(f"Error loading image: {e}")
|
| 123 |
raise gr.Error("Failed to load input image.")
|
| 124 |
|
| 125 |
if height == 256 and width == 256:
|
| 126 |
height, width = None, None
|
| 127 |
+
logger.info(f"Calling pipeline with prompt: '{prompt_final}'")
|
| 128 |
+
logger.info(f"Negative Prompt: '{negative_prompt}'")
|
| 129 |
+
logger.info(f"Seed: {seed}, Steps: {num_inference_steps}, Guidance: {true_guidance_scale}, Size: {width}x{height}")
|
| 130 |
|
| 131 |
# Generate the image
|
| 132 |
output = pipe(
|
|
|
|
| 282 |
div[aria-label="Input Image"] .gr-button {
|
| 283 |
display: none !important; /* Force hide all toolbar elements */
|
| 284 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
input, textarea {
|
| 286 |
background: #000000 !important;
|
| 287 |
color: #FFFFFF !important;
|
|
|
|
| 337 |
button[aria-label="Download"]:hover {
|
| 338 |
box-shadow: 0 0 12px rgba(255, 255, 255, 0.5) !important;
|
| 339 |
}
|
| 340 |
+
.progress-text, .gr-progress, .gr-prose, .gr-log {
|
| 341 |
+
display: none !important; /* Hide all progress bars and logs */
|
| 342 |
}
|
| 343 |
footer, .gr-button-secondary {
|
| 344 |
display: none !important;
|
|
|
|
| 371 |
box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important;
|
| 372 |
border: 0.5px solid #FFFFFF !important; /* Thinner white border */
|
| 373 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
</style>
|
| 376 |
<script>
|
|
|
|
| 383 |
console.log(`Container ${container.id || container.className}: width=${width}px, box-shadow=${style.boxShadow}, background=${style.background}, border=${style.border} (Viewport: ${window.innerWidth}px)`);
|
| 384 |
container.setAttribute('data-width', `${width}px`);
|
| 385 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
const editButton = document.querySelector('.gr-button-primary');
|
| 387 |
if (editButton) {
|
| 388 |
const style = window.getComputedStyle(editButton);
|
|
|
|
| 429 |
toolbar.style.display = 'none';
|
| 430 |
console.log(`Forced hide toolbar: ${toolbar.className}`);
|
| 431 |
});
|
| 432 |
+
// Hide any technical output containers
|
| 433 |
+
const outputContainers = document.querySelectorAll('.gr-prose, .gr-log, .progress-text, .gr-progress');
|
| 434 |
+
outputContainers.forEach(container => {
|
| 435 |
+
container.style.display = 'none';
|
| 436 |
+
console.log(`Forced hide output container: ${container.className}`);
|
| 437 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
});
|
| 439 |
</script>
|
| 440 |
""")
|
|
|
|
| 481 |
return demo
|
| 482 |
|
| 483 |
if __name__ == "__main__":
|
| 484 |
+
logger.info(f"Gradio version: {gr.__version__}")
|
| 485 |
demo = create_demo()
|
| 486 |
demo.queue().launch(share=True)
|