Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ warnings.filterwarnings("ignore")
|
|
| 15 |
from config import Config
|
| 16 |
from segmentation import RoomSegmentation
|
| 17 |
from style_extractor import StyleExtractor
|
| 18 |
-
from utils import load_image_safe, save_image_safe, create_comparison_image, enhance_image_quality
|
| 19 |
|
| 20 |
class AdvancedHFSpacesPipeline:
|
| 21 |
"""Advanced pipeline for Hugging Face Spaces with full capabilities"""
|
|
@@ -503,18 +503,40 @@ class AdvancedHFSpacesPipeline:
|
|
| 503 |
# Process images
|
| 504 |
result, style_summary, full_style_info = self.advanced_style_transfer(user_room, inspiration_room)
|
| 505 |
|
| 506 |
-
# Create comparison image
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
)
|
| 511 |
|
|
|
|
|
|
|
|
|
|
| 512 |
return comparison, style_summary, full_style_info
|
| 513 |
|
| 514 |
except Exception as e:
|
| 515 |
error_msg = f"Advanced processing failed: {str(e)}"
|
| 516 |
print(error_msg)
|
| 517 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
|
| 519 |
# Initialize advanced pipeline
|
| 520 |
pipeline = AdvancedHFSpacesPipeline()
|
|
@@ -570,7 +592,7 @@ def create_advanced_interface():
|
|
| 570 |
# Advanced style details
|
| 571 |
with gr.Accordion("🔍 Detailed Style Analysis", open=False):
|
| 572 |
style_details = gr.JSON(
|
| 573 |
-
label="Complete Style Information"
|
| 574 |
)
|
| 575 |
|
| 576 |
# Processing function
|
|
@@ -608,3 +630,4 @@ if __name__ == "__main__":
|
|
| 608 |
share=False,
|
| 609 |
show_error=True
|
| 610 |
)
|
|
|
|
|
|
| 15 |
from config import Config
|
| 16 |
from segmentation import RoomSegmentation
|
| 17 |
from style_extractor import StyleExtractor
|
| 18 |
+
from utils import load_image_safe, save_image_safe, create_comparison_image, create_multi_comparison_image, enhance_image_quality
|
| 19 |
|
| 20 |
class AdvancedHFSpacesPipeline:
|
| 21 |
"""Advanced pipeline for Hugging Face Spaces with full capabilities"""
|
|
|
|
| 503 |
# Process images
|
| 504 |
result, style_summary, full_style_info = self.advanced_style_transfer(user_room, inspiration_room)
|
| 505 |
|
| 506 |
+
# Create multi-comparison image (show all three images)
|
| 507 |
+
# Convert PIL images to numpy arrays for comparison
|
| 508 |
+
user_np = np.array(user_room)
|
| 509 |
+
inspiration_np = np.array(inspiration_room)
|
| 510 |
+
result_np = np.array(result)
|
| 511 |
+
|
| 512 |
+
# Ensure all images are in RGB format
|
| 513 |
+
if len(user_np.shape) == 3 and user_np.shape[2] == 3:
|
| 514 |
+
user_np = cv2.cvtColor(user_np, cv2.COLOR_RGB2BGR)
|
| 515 |
+
if len(inspiration_np.shape) == 3 and inspiration_np.shape[2] == 3:
|
| 516 |
+
inspiration_np = cv2.cvtColor(inspiration_np, cv2.COLOR_RGB2BGR)
|
| 517 |
+
if len(result_np.shape) == 3 and result_np.shape[2] == 3:
|
| 518 |
+
result_np = cv2.cvtColor(result_np, cv2.COLOR_RGB2BGR)
|
| 519 |
+
|
| 520 |
+
comparison = create_multi_comparison_image(
|
| 521 |
+
[user_np, inspiration_np, result_np],
|
| 522 |
+
titles=["Your Room", "Inspiration", "Advanced Result"],
|
| 523 |
+
title="Advanced Interior Style Transfer"
|
| 524 |
)
|
| 525 |
|
| 526 |
+
# Convert back to PIL format for Gradio
|
| 527 |
+
comparison = Image.fromarray(cv2.cvtColor(comparison, cv2.COLOR_BGR2RGB))
|
| 528 |
+
|
| 529 |
return comparison, style_summary, full_style_info
|
| 530 |
|
| 531 |
except Exception as e:
|
| 532 |
error_msg = f"Advanced processing failed: {str(e)}"
|
| 533 |
print(error_msg)
|
| 534 |
+
|
| 535 |
+
# Fallback: return just the result image
|
| 536 |
+
try:
|
| 537 |
+
return result, style_summary, full_style_info
|
| 538 |
+
except:
|
| 539 |
+
return None, error_msg, {}
|
| 540 |
|
| 541 |
# Initialize advanced pipeline
|
| 542 |
pipeline = AdvancedHFSpacesPipeline()
|
|
|
|
| 592 |
# Advanced style details
|
| 593 |
with gr.Accordion("🔍 Detailed Style Analysis", open=False):
|
| 594 |
style_details = gr.JSON(
|
| 595 |
+
label="Complete Style Information"
|
| 596 |
)
|
| 597 |
|
| 598 |
# Processing function
|
|
|
|
| 630 |
share=False,
|
| 631 |
show_error=True
|
| 632 |
)
|
| 633 |
+
|