Spaces:
Sleeping
Sleeping
File size: 20,656 Bytes
33ec7ea a57f11f 33ec7ea 561af0a 59f8abf 561af0a 33ec7ea |
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
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
) |