import gradio as gr from typing import List, Literal, Optional from pydantic import BaseModel, Field import json # Your Pydantic models (copied from your code) class Reception(BaseModel): l_shape_sofa: bool = False three_seaters_sofa: bool = False two_seaters_sofa: bool = False chairs: bool = False notes: Optional[str] = None class LivingRoom(BaseModel): tv_unit: bool = False l_shape_sofa: bool = False recliner: bool = False notes: Optional[str] = None class Dining(BaseModel): table_6_chairs: bool = False table_8_chairs: bool = False table_10_chairs: bool = False buffet: bool = False bench: bool = False notes: Optional[str] = None class Kitchenette(BaseModel): microwave: bool = False mini_bar : bool =False basin : bool =False notes: Optional[str] = None class Kitchen(BaseModel): oven: bool = False stove: bool = False fridge_double: Optional[bool] = False fridge_single: Optional[bool] = False fridge_dispenser: Optional[bool] = False deep_freeze_horizontal: Optional[bool] = False deep_freeze_vertical: Optional[bool] = False water_dispenser :bool = False basin_حوض_حلتين: Optional[bool] = False basin_حوض_حلة_واحدة_كبيرة: Optional[bool] = False basin_حوض_حوض_زاوية: Optional[bool] = False basin_حوض_حوض_صغير_cm55: Optional[bool] = False dish_washer_45cm: Optional[bool] = False dish_washer_60cm: Optional[bool] = False washing_machine_laundry:bool =False cooker_ventilation_hood: Optional[bool] = False cooker_ventilation_شفاط_سقفي: Optional[bool] = False cooker_size_60cm: Optional[bool] = False cooker_size_90cm: Optional[bool] = False oven_size_60cm: Optional[bool] = False oven_size_90cm: Optional[bool] = False microwave : bool = False pantry: bool=False bar : bool=False island:bool=False breakfast_nook:bool =False دولاب_نظافة:bool=False notes: Optional[str] = None class MasterBedroom(BaseModel): bed_size_1_6: Optional[bool] = False bed_size_1_8: Optional[bool] = False bed_size_2: Optional[bool] = False bed_size_2_2: Optional[bool] = False bedside_table_0: Optional[bool] = False bedside_table_1: Optional[bool] = False bedside_table_2: Optional[bool] = False tv_unit: bool = False vanity_dresser: bool = False with_chair: bool = False standing_mirror: bool = False inside_room: bool = False inside_dressing: bool = False inside_dressing_note: Optional[str] = None notes: Optional[str] = None class MasterToilet(BaseModel): bathtub: bool = False bathtub_note: Optional[str] = None shower_built_in: bool = False shower_note: Optional[str] = None standard: bool = False jacuzzi: bool = False built_in_seat: bool = False حوض_ساقط_رخامة: bool = False وحدة_حوض_مستقل: bool = False wall_niches: bool = False bathroom_storage: bool = False notes: Optional[str] = None class Bed(BaseModel): type_main: Optional[bool] = False type_bunk: Optional[bool] = False type_sofa: Optional[bool] = False size_1: Optional[bool] = False size_1_2: Optional[bool] = False size_1_4: Optional[bool] = False window_seat:bool =False bedside_table_0: Optional[bool] = False bedside_table_1: Optional[bool] = False bedside_table_2: Optional[bool] = False notes: Optional[str] = None class VanityDresser(BaseModel): with_chair:bool =False standing_mirror:bool=False inside_room:bool=False inside_dressing:bool=False notes: Optional[str] = None class Bedroom1(BaseModel): beds: List[Bed] = [] dressing_walk_in: Optional[bool] = False dressing_wardrobe: Optional[bool] = False van_dresser:VanityDresser=VanityDresser() table:bool=False tv_unit:bool=False notes: Optional[str] = None class Bedroom2(BaseModel): beds: List[Bed]=[] dressing_walk_in: Optional[bool] = False dressing_wardrobe: Optional[bool] = False van_dresser:VanityDresser=VanityDresser() table:bool=False tv_unit:bool=False notes: Optional[str] = None class SharedToilet(BaseModel): bathtub: bool = False bathtub_note: Optional[str] = None shower_built_in: bool = False shower_note: Optional[str] = None standard: bool = False jacuzzi: bool = False built_in_seat: bool = False حوض_ساقط_رخامة: bool = False وحدة_حوض_مستقل: bool = False wall_niches: bool = False bathroom_storage: bool = False غسالة_الثياب_ومجف:bool=False notes: Optional[str] = None class GuestBedroom(BaseModel): bed:Bed=Bed() wardrobe:bool=False bathroom_storage:bool=False tv_unit:bool=False chair:bool=False notes: Optional[str] = None class PrayingRoom(BaseModel): mehrab:bool=False library:bool=False notes: Optional[str] = None class Office(BaseModel): library:bool=False tv_unit:bool=False sofa:bool=False sofa_bed:bool=False coffee_corner:bool=False closet:bool=False notes: Optional[str] = None class GeneralRequirementsNotes(BaseModel): general_notes: Optional[str] = None class Names(BaseModel): mr:str="" mrs:str="" class UserFormData(BaseModel): reception: Reception = Reception() living_room: LivingRoom = LivingRoom() dining: Dining = Dining() kitchenette: Kitchenette = Kitchenette() kitchen: Kitchen = Kitchen() master_bedroom: MasterBedroom = MasterBedroom() master_toilet: MasterToilet = MasterToilet() bedroom1: Bedroom1 = Bedroom1() bedroom2: Bedroom2 = Bedroom2() shared_toilet: SharedToilet = SharedToilet() guest_bedroom: GuestBedroom = GuestBedroom() praying_room: PrayingRoom = PrayingRoom() office: Office = Office() general_requirements_notes: GeneralRequirementsNotes = GeneralRequirementsNotes() names: Names = Names() class InteriorDesignState(BaseModel): user_form: UserFormData design_brief: Optional[str] = None design_instructions: Optional[str] = None # Global state to track beds bedroom1_beds = [] bedroom2_beds = [] def create_bed_inputs(bed_id, bedroom_type): """Create input components for a single bed""" prefix = f"{bedroom_type}_bed_{bed_id}" with gr.Group(): gr.Markdown(f"### Bed {bed_id}") with gr.Row(): with gr.Column(): gr.Markdown("**Bed Type:**") type_main = gr.Checkbox(label="Main Bed", elem_id=f"{prefix}_type_main") type_bunk = gr.Checkbox(label="Bunk Bed", elem_id=f"{prefix}_type_bunk") type_sofa = gr.Checkbox(label="Sofa Bed", elem_id=f"{prefix}_type_sofa") gr.Markdown("**Bed Size:**") size_1 = gr.Checkbox(label="Size 1m", elem_id=f"{prefix}_size_1") size_1_2 = gr.Checkbox(label="Size 1.2m", elem_id=f"{prefix}_size_1_2") size_1_4 = gr.Checkbox(label="Size 1.4m", elem_id=f"{prefix}_size_1_4") with gr.Column(): gr.Markdown("**Accessories:**") window_seat = gr.Checkbox(label="Window Seat", elem_id=f"{prefix}_window_seat") gr.Markdown("**Bedside Tables:**") bedside_table_0 = gr.Checkbox(label="0 Tables", elem_id=f"{prefix}_bedside_table_0") bedside_table_1 = gr.Checkbox(label="1 Table", elem_id=f"{prefix}_bedside_table_1") bedside_table_2 = gr.Checkbox(label="2 Tables", elem_id=f"{prefix}_bedside_table_2") notes = gr.Textbox(label="Bed Notes", lines=2, elem_id=f"{prefix}_notes") return { 'type_main': type_main, 'type_bunk': type_bunk, 'type_sofa': type_sofa, 'size_1': size_1, 'size_1_2': size_1_2, 'size_1_4': size_1_4, 'window_seat': window_seat, 'bedside_table_0': bedside_table_0, 'bedside_table_1': bedside_table_1, 'bedside_table_2': bedside_table_2, 'notes': notes } def add_bed_bedroom1(): global bedroom1_beds if len(bedroom1_beds) < 5: bed_id = len(bedroom1_beds) + 1 bed_inputs = create_bed_inputs(bed_id, "bedroom1") bedroom1_beds.append(bed_inputs) return gr.update(visible=True) return gr.update() def add_bed_bedroom2(): global bedroom2_beds if len(bedroom2_beds) < 5: bed_id = len(bedroom2_beds) + 1 bed_inputs = create_bed_inputs(bed_id, "bedroom2") bedroom2_beds.append(bed_inputs) return gr.update(visible=True) return gr.update() def process_form_data(*args): """Process all form data and create UserFormData model""" try: # This is a simplified version - you'll need to map all the arguments # to the correct dictionary structure # For now, let's create a basic structure collected_data = { "names": { "mr": args[0] if args[0] else "", "mrs": args[1] if args[1] else "" }, "reception": { "l_shape_sofa": args[2] if len(args) > 2 else False, "three_seaters_sofa": args[3] if len(args) > 3 else False, "two_seaters_sofa": args[4] if len(args) > 4 else False, "chairs": args[5] if len(args) > 5 else False, "notes": args[6] if len(args) > 6 and args[6] else None }, # Add more sections as needed... } # Create the model form = UserFormData(**collected_data) json_output = form.model_dump_json() return f"✅ Form processed successfully!\n\n{json_output}" except Exception as e: return f"❌ Error processing form: {str(e)}" # Create the main Gradio interface with gr.Blocks(title="Interior Design Form", theme=gr.themes.Soft()) as app: gr.Markdown("# 🏠 Interior Design Requirements Form") # Names Section (at the top) with gr.Group(): gr.Markdown("## 👥 Client Information") with gr.Row(): mr_name = gr.Textbox(label="Mr.", placeholder="Enter husband's name") mrs_name = gr.Textbox(label="Mrs.", placeholder="Enter wife's name") # Reception Section with gr.Accordion("🛋️ Reception", open=False): with gr.Row(): with gr.Column(): reception_l_shape = gr.Checkbox(label="L-Shape Sofa") reception_three_seaters = gr.Checkbox(label="Three Seaters Sofa") with gr.Column(): reception_two_seaters = gr.Checkbox(label="Two Seaters Sofa") reception_chairs = gr.Checkbox(label="Chairs") reception_notes = gr.Textbox(label="Reception Notes", lines=3) # Living Room Section with gr.Accordion("📺 Living Room", open=False): with gr.Row(): living_tv_unit = gr.Checkbox(label="TV Unit") living_l_shape = gr.Checkbox(label="L-Shape Sofa") living_recliner = gr.Checkbox(label="Recliner") living_notes = gr.Textbox(label="Living Room Notes", lines=3) # Dining Section with gr.Accordion("🍽️ Dining", open=False): with gr.Row(): with gr.Column(): dining_table_6 = gr.Checkbox(label="Table 6 Chairs") dining_table_8 = gr.Checkbox(label="Table 8 Chairs") with gr.Column(): dining_table_10 = gr.Checkbox(label="Table 10 Chairs") dining_buffet = gr.Checkbox(label="Buffet") dining_bench = gr.Checkbox(label="Bench") dining_notes = gr.Textbox(label="Dining Notes", lines=3) # Kitchenette Section with gr.Accordion("☕ Kitchenette", open=False): with gr.Row(): kitchenette_microwave = gr.Checkbox(label="Microwave") kitchenette_mini_bar = gr.Checkbox(label="Mini Bar") kitchenette_basin = gr.Checkbox(label="Basin") kitchenette_notes = gr.Textbox(label="Kitchenette Notes", lines=3) # Kitchen Section (simplified - you can expand this) with gr.Accordion("🍳 Kitchen", open=False): with gr.Row(): with gr.Column(): gr.Markdown("**Basic Appliances:**") kitchen_oven = gr.Checkbox(label="Oven") kitchen_stove = gr.Checkbox(label="Stove") kitchen_microwave = gr.Checkbox(label="Microwave") kitchen_water_dispenser = gr.Checkbox(label="Water Dispenser") gr.Markdown("**Refrigeration:**") kitchen_fridge_double = gr.Checkbox(label="Double Fridge") kitchen_fridge_single = gr.Checkbox(label="Single Fridge") kitchen_fridge_dispenser = gr.Checkbox(label="Fridge with Dispenser") with gr.Column(): gr.Markdown("**Storage & Features:**") kitchen_pantry = gr.Checkbox(label="Pantry") kitchen_bar = gr.Checkbox(label="Bar") kitchen_island = gr.Checkbox(label="Island") kitchen_breakfast_nook = gr.Checkbox(label="Breakfast Nook") kitchen_دولاب_نظافة = gr.Checkbox(label="دولاب نظافة") gr.Markdown("**basin**") basin_حوض_حلتين=gr.Checkbox(label="basin_حوض_حلتين") basin_حوض_حلة_واحدة_كبيرة=gr.Checkbox(label="basin_حوض_حلة_واحدة_كبيرة") basin_حوض_حوض_زاوية=gr.Checkbox(label="basin_حوض_حوض_زاوية") basin_حوض_حوض_صغير_cm55=gr.Checkbox(label="basin_حوض_حوض_صغير_cm55") with gr.Column(): gr.Markdown("**cooker &oven**") cooker_ventilation_شفاط_سقفي=gr.Checkbox(label="cooker_ventilation_شفاط_سقفي") cooker_ventilation_hood=gr.Checkbox(label="cooker_ventilation_hood") cooker_size_60cm=gr.Checkbox(label="cooker_size_60cm") cooker_size_90cm=gr.Checkbox(label="cooker_size_90cm") oven_size_60cm=gr.Checkbox(label="oven_size_60cm") oven_size_90cm=gr.Checkbox(label="oven_size_90cm") gr.Markdown("**washer & deep freezer**") dish_washer_45cm=gr.Checkbox(label="dish_washer_45cm") dish_washer_60cm=gr.Checkbox(label="dish_washer_60cm") washing_machine_laundry=gr.Checkbox(label="washing_machine_laundry") deep_freeze_horizontal=gr.Checkbox(label="deep_freeze_horizontal") deep_freeze_vertical=gr.Checkbox(label="deep_freeze_vertical") kitchen_notes = gr.Textbox(label="Kitchen Notes", lines=3) # Master Bedroom Section with gr.Accordion("🛏️ Master Bedroom", open=False): with gr.Row(): with gr.Column(): gr.Markdown("**Bed Sizes:**") master_bed_1_6 = gr.Checkbox(label="Bed Size 1.6m") master_bed_1_8 = gr.Checkbox(label="Bed Size 1.8m") master_bed_2 = gr.Checkbox(label="Bed Size 2m") master_bed_2_2 = gr.Checkbox(label="Bed Size 2.2m") gr.Markdown("**Bedside Tables:**") master_bedside_0 = gr.Checkbox(label="0 Tables") master_bedside_1 = gr.Checkbox(label="1 Table") master_bedside_2 = gr.Checkbox(label="2 Tables") with gr.Column(): gr.Markdown("**Furniture:**") master_tv_unit = gr.Checkbox(label="TV Unit") master_vanity_dresser = gr.Checkbox(label="Vanity Dresser") master_with_chair = gr.Checkbox(label="With Chair") master_standing_mirror = gr.Checkbox(label="Standing Mirror") master_inside_room = gr.Checkbox(label="Inside Room") master_inside_dressing = gr.Checkbox(label="Inside Dressing") master_inside_dressing_note = gr.Textbox(label="Inside Dressing Note", lines=2) master_notes = gr.Textbox(label="Master Bedroom Notes", lines=3) # Bedroom1 Section with Dynamic Beds with gr.Accordion("🛏️ Bedroom 1", open=False): with gr.Column(): # Bedroom1 beds container bedroom1_beds_container = gr.Column() # Initialize with one bed with bedroom1_beds_container: bed1_inputs = create_bed_inputs(1, "bedroom1") bedroom1_beds.append(bed1_inputs) # Add bed button with gr.Row(): add_bed1_btn = gr.Button("➕ Add Bed", size="sm") gr.Markdown(f"(Max 5 beds)") # Other bedroom1 features with gr.Row(): with gr.Column(): bedroom1_dressing_walk_in = gr.Checkbox(label="Walk-in Dressing") bedroom1_dressing_wardrobe = gr.Checkbox(label="Wardrobe") bedroom1_table = gr.Checkbox(label="Table") bedroom1_tv_unit = gr.Checkbox(label="TV Unit") with gr.Column(): gr.Markdown("**Vanity Dresser:**") bedroom1_van_with_chair = gr.Checkbox(label="With Chair") bedroom1_van_standing_mirror = gr.Checkbox(label="Standing Mirror") bedroom1_van_inside_room = gr.Checkbox(label="Inside Room") bedroom1_van_inside_dressing = gr.Checkbox(label="Inside Dressing") bedroom1_van_notes = gr.Textbox(label="Vanity Notes", lines=2) bedroom1_notes = gr.Textbox(label="Bedroom1 Notes", lines=3) # Add more sections as needed (Bedroom2, Bathrooms, etc.) with gr.Accordion("🛏️ Bedroom 2", open=False): gr.Markdown("*Similar to Bedroom 1 - Add dynamic beds here*") with gr.Accordion("🚿 Master Toilet", open=False): gr.Markdown("*Add Master Toilet fields here*") with gr.Accordion("🚿 Shared Toilet", open=False): gr.Markdown("*Add Shared Toilet fields here*") with gr.Accordion("🛏️ Guest Bedroom", open=False): gr.Markdown("*Add Guest Bedroom fields here*") with gr.Accordion("🕌 Praying Room", open=False): with gr.Row(): praying_mehrab = gr.Checkbox(label="Mehrab") praying_library = gr.Checkbox(label="Library") praying_notes = gr.Textbox(label="Praying Room Notes", lines=3) with gr.Accordion("💼 Office", open=False): with gr.Row(): with gr.Column(): office_library = gr.Checkbox(label="Library") office_tv_unit = gr.Checkbox(label="TV Unit") office_sofa = gr.Checkbox(label="Sofa") with gr.Column(): office_sofa_bed = gr.Checkbox(label="Sofa Bed") office_coffee_corner = gr.Checkbox(label="Coffee Corner") office_closet = gr.Checkbox(label="Closet") office_notes = gr.Textbox(label="Office Notes", lines=3) with gr.Accordion("📝 General Requirements", open=False): general_notes = gr.Textbox(label="General Requirements Notes", lines=5) # Process Button and Output with gr.Row(): process_btn = gr.Button("🔄 Process Form Data", variant="primary", size="lg") # Output Section with gr.Group(): gr.Markdown("## 📋 Generated JSON Output") json_output = gr.Textbox( label="Form Data JSON", lines=20, max_lines=30, show_copy_button=True ) # Connect the process button (simplified version) process_btn.click( fn=process_form_data, inputs=[ mr_name, mrs_name, reception_l_shape, reception_three_seaters, reception_two_seaters, reception_chairs, reception_notes # Add all other inputs here ], outputs=json_output ) # Add bed buttons functionality # add_bed1_btn.click(fn=add_bed_bedroom1, outputs=[]) if __name__ == "__main__": app.launch( share=False, server_name="0.0.0.0", server_port=7860, show_error=True )