Update app.py
Browse files
app.py
CHANGED
|
@@ -349,59 +349,13 @@ def generate_ai_background(
|
|
| 349 |
seed: Optional[int] = None,
|
| 350 |
) -> str:
|
| 351 |
"""Generate AI background using Stable Diffusion."""
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
# Setup generator
|
| 361 |
-
generator = torch.Generator(device=DEVICE)
|
| 362 |
-
if seed is None:
|
| 363 |
-
seed = random.randint(0, 2**31 - 1)
|
| 364 |
-
generator.manual_seed(seed)
|
| 365 |
-
|
| 366 |
-
# Generate background
|
| 367 |
-
if init_image_path and os.path.exists(init_image_path):
|
| 368 |
-
# Image-to-image
|
| 369 |
-
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 370 |
-
"runwayml/stable-diffusion-v1-5",
|
| 371 |
-
torch_dtype=torch.float16 if CUDA_AVAILABLE else torch.float32,
|
| 372 |
-
safety_checker=None
|
| 373 |
-
).to(DEVICE)
|
| 374 |
-
|
| 375 |
-
init_image = Image.open(init_image_path).convert("RGB").resize((width, height))
|
| 376 |
-
result = pipe(
|
| 377 |
-
prompt=prompt,
|
| 378 |
-
image=init_image,
|
| 379 |
-
strength=0.6,
|
| 380 |
-
num_inference_steps=num_steps,
|
| 381 |
-
guidance_scale=guidance_scale,
|
| 382 |
-
generator=generator
|
| 383 |
-
).images[0]
|
| 384 |
-
else:
|
| 385 |
-
# Text-to-image
|
| 386 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 387 |
-
"runwayml/stable-diffusion-v1-5",
|
| 388 |
-
torch_dtype=torch.float16 if CUDA_AVAILABLE else torch.float32,
|
| 389 |
-
safety_checker=None
|
| 390 |
-
).to(DEVICE)
|
| 391 |
-
|
| 392 |
-
result = pipe(
|
| 393 |
-
prompt=prompt,
|
| 394 |
-
height=height,
|
| 395 |
-
width=width,
|
| 396 |
-
num_inference_steps=num_steps,
|
| 397 |
-
guidance_scale=guidance_scale,
|
| 398 |
-
generator=generator
|
| 399 |
-
).images[0]
|
| 400 |
-
|
| 401 |
-
# Save result
|
| 402 |
-
output_path = TEMP_DIR / f"ai_bg_{int(time.time())}_{uuid4().hex[:6]}.jpg"
|
| 403 |
-
result.save(output_path, quality=95)
|
| 404 |
-
return str(output_path)
|
| 405 |
|
| 406 |
# ==============================================================================
|
| 407 |
# MAIN PROCESSING PIPELINE
|
|
|
|
| 349 |
seed: Optional[int] = None,
|
| 350 |
) -> str:
|
| 351 |
"""Generate AI background using Stable Diffusion."""
|
| 352 |
+
# TEMPORARILY DISABLED due to PyTorch/Diffusers compatibility issue
|
| 353 |
+
# To fix: pip install --upgrade torch diffusers transformers
|
| 354 |
+
raise RuntimeError(
|
| 355 |
+
"AI Background temporarily disabled due to PyTorch/Diffusers version compatibility.\n"
|
| 356 |
+
"To fix: pip install --upgrade torch diffusers transformers accelerate\n"
|
| 357 |
+
"For now, please use Upload Image or Gradients instead."
|
| 358 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
# ==============================================================================
|
| 361 |
# MAIN PROCESSING PIPELINE
|