Spaces:
Runtime error
Runtime error
File size: 4,279 Bytes
a03fc9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
"""
Room Layout Generator Web Interface
A web application for generating indoor layouts from natural language descriptions
"""
import warnings
import gradio as gr
from pathlib import Path
from config.settings import settings
from core import ConfigGenerator, ModelConverter
from backend import InfinigenBackend
from utils.logger import logger
warnings.filterwarnings("ignore", category=UserWarning)
class LayoutApp:
"""Layout generation application"""
def __init__(self):
# Validate configuration
try:
settings.validate()
except ValueError as e:
logger.error(f"Configuration error: {e}")
raise
# Initialize components
self.config_gen = ConfigGenerator()
self.backend = InfinigenBackend()
self.converter = ModelConverter()
logger.info("Application initialized successfully")
def generate_layout(self, user_input: str) -> str:
"""
Main pipeline: from user input to 3D model
Args:
user_input: User's layout requirement description
Returns:
Path to generated .glb file
"""
if not user_input or not user_input.strip():
return "Please enter your layout requirements"
try:
# 1. Generate configuration
logger.info("Step 1/3: Generating configuration...")
yaml_content = self.config_gen.generate(user_input)
# Save configuration
self.config_gen.save(yaml_content, settings.CONFIG_OUTPUT)
# 2. Generate layout
logger.info("Step 2/3: Generating layout (this may take a while)...")
blend_file = self.backend.generate(
config_path=settings.CONFIG_OUTPUT,
output_dir=settings.OUTPUT_DIR,
seed=settings.DEFAULT_SEED
)
# 3. Convert format
logger.info("Step 3/3: Converting to web format...")
glb_file = self.converter.blend_to_glb(blend_file)
logger.info(f"Generation complete: {glb_file}")
return str(glb_file)
except Exception as e:
error_msg = f"Generation failed: {str(e)}"
logger.error(error_msg)
return error_msg
def create_interface(app: LayoutApp) -> gr.Interface:
"""Create Gradio interface"""
demo = gr.Interface(
fn=app.generate_layout,
inputs=gr.Textbox(
lines=6,
placeholder=(
"Describe your desired room layout...\n\n"
"Example:\n"
"I want a 2-bedroom house with private bathrooms in each bedroom, "
"living room 1.3x larger than bedrooms, kitchen connected to dining room."
),
label="Layout Requirements"
),
outputs=gr.Model3D(
scale=2,
label="Generated 3D Layout"
),
title="Room Layout Generator",
description=(
"Generate indoor layouts from natural language descriptions.\n"
"Supports English/Chinese input. Max 3 bedrooms, 10 total rooms."
),
examples=[
["2 bedrooms with private bathrooms, living room 1.5x bedroom size"],
["3-bedroom house, 2 bathrooms, kitchen connected to dining room"],
["1 bedroom, 1 bathroom, open kitchen connected to living room"]
],
theme=gr.themes.Soft()
)
return demo
def main():
"""Launch application"""
print("Room Layout Generator")
print("=" * 50)
print(f"Project root: {settings.INFINIGEN_ROOT}")
print(f"Output dir: {settings.OUTPUT_DIR}")
print(f"Blender: {settings.BLENDER_PATH}")
print(f"AI model: {settings.OPENAI_MODEL}")
print("=" * 50)
try:
app = LayoutApp()
demo = create_interface(app)
demo.launch(
share=settings.SHARE_GRADIO,
allowed_paths=[str(settings.OUTPUT_DIR)]
)
except Exception as e:
logger.error(f"Failed to start application: {e}")
raise
if __name__ == "__main__":
main()
|