Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -535,23 +535,24 @@ class UltraSupremeOptimizer:
|
|
535 |
except Exception as e:
|
536 |
logger.error(f"Initialization error: {e}")
|
537 |
return False
|
538 |
-
def optimize_image(self, image):
|
539 |
-
if image is None:
|
540 |
-
return None
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
|
|
|
|
|
|
|
|
555 |
|
556 |
@spaces.GPU
|
557 |
def generate_ultra_supreme_prompt(self, image):
|
|
|
535 |
except Exception as e:
|
536 |
logger.error(f"Initialization error: {e}")
|
537 |
return False
|
|
|
|
|
|
|
538 |
|
539 |
+
def optimize_image(self, image):
|
540 |
+
if image is None:
|
541 |
+
return None
|
542 |
+
|
543 |
+
if isinstance(image, np.ndarray):
|
544 |
+
image = Image.fromarray(image)
|
545 |
+
elif not isinstance(image, Image.Image):
|
546 |
+
image = Image.open(image)
|
547 |
+
|
548 |
+
if image.mode != 'RGB':
|
549 |
+
image = image.convert('RGB')
|
550 |
+
|
551 |
+
max_size = 768 if self.device != "cpu" else 512
|
552 |
+
if image.size[0] > max_size or image.size[1] > max_size:
|
553 |
+
image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
554 |
+
|
555 |
+
return image
|
556 |
|
557 |
@spaces.GPU
|
558 |
def generate_ultra_supreme_prompt(self, image):
|