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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# HVAC Blueprint Analyzer - FastAPI + HTML Canvas - 1 Day Build Guide

**Timeline**: 6-8 hours  
**Stack**: FastAPI (backend) + HTML/Canvas (frontend)  
**Deliverable**: Working demo with file upload, analysis, CSV export, and visual floor plan

---

## ⏰ Timeline Breakdown

| Time | Task | Duration |
|------|------|----------|
| 0:00-0:30 | Project setup & dependencies | 30 min |
| 0:30-1:30 | FastAPI server scaffold | 1 hour |
| 1:30-3:00 | HTML UI & Canvas setup | 1.5 hours |
| 3:00-4:30 | CSV exporter integration | 1.5 hours |
| 4:30-5:30 | Testing & bug fixes | 1 hour |
| 5:30-6:00 | Final polish & deployment | 30 min |
| **Total** | | **6 hours** |

---

## πŸ“ Project Structure

```
hvac_project/
β”œβ”€β”€ server.py                 # FastAPI main app
β”œβ”€β”€ requirements.txt          # Dependencies
β”œβ”€β”€ public/                   # Static files
β”‚   β”œβ”€β”€ index.html           # Main UI
β”‚   β”œβ”€β”€ style.css            # Styling
β”‚   β”œβ”€β”€ script.js            # Canvas & interactions
β”‚   └── favicon.ico
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ analyzer.py          # Analysis logic (use existing code)
β”‚   β”œβ”€β”€ csv_exporter.py      # CSV generation
β”‚   └── models.py            # Pydantic models
β”œβ”€β”€ outputs/                 # Generated files (CSVs, PDFs)
└── .env                     # API keys (Gemini, OpenAI)
```

---

## πŸš€ STEP 1: Project Setup (30 min)

### 1.1 Create Virtual Environment
```bash
cd C:\Users\ruchy\OneDrive\Documents\hvac_project

# Create venv
python -m venv venv

# Activate
venv\Scripts\activate

# On Mac/Linux:
# source venv/bin/activate
```

### 1.2 Create requirements.txt
```txt
fastapi==0.104.1
uvicorn[standard]==0.24.0
python-multipart==0.0.6
pydantic==2.5.0
python-dotenv==1.0.0
pandas==2.1.3
openpyxl==3.11.0
fitz==0.0.1.dev2
PyPDF2==3.17.1
pdfplumber==0.10.3
pytesseract==0.3.10
pillow==10.1.0
aiofiles==23.2.1
requests==2.31.0
reportlab==4.0.7
# Add your existing HVAC dependencies
google-generativeai==0.3.0  # For Gemini
openai==1.3.0               # For OpenAI
```

### 1.3 Install Dependencies
```bash
pip install -r requirements.txt
```

### 1.4 Create .env File
```env
# Google Gemini
GEMINI_API_KEY=your_gemini_key_here

# OpenAI
OPENAI_API_KEY=your_openai_key_here

# FastAPI
DEBUG=True
HOST=127.0.0.1
PORT=8000
```

---

## πŸ–₯️ STEP 2: FastAPI Server (1 hour)

### 2.1 Create models.py
```python
# modules/models.py
from pydantic import BaseModel
from typing import List, Optional, Dict, Any
from datetime import datetime

class Unit(BaseModel):
    tag: str
    type: str
    quantity: int
    capacity_btu: Optional[float] = None
    capacity_kw: Optional[float] = None
    location: Optional[str] = None
    detection_status: str = "Detected"
    notes: Optional[str] = None

class Floor(BaseModel):
    floor_number: int
    floor_type: str = "residential"
    units: List[Unit] = []
    unit_count: Optional[int] = None

class AnalysisResult(BaseModel):
    status: str
    file_name: str
    model_used: str
    processing_time_seconds: float
    cost_usd: float
    summary: Dict[str, Any]
    floors: List[Floor]
    equipment_schedule: List[Dict[str, Any]]
    reconciliation: Dict[str, Any]

class AnalysisRequest(BaseModel):
    model_choice: str = "gemini"  # or "openai"
    schedule_mode: str = "auto"   # or "manual"
    confidence_threshold: float = 0.7

class ScheduleUpload(BaseModel):
    floor: int
    unit_id: str
    unit_type: str
    quantity: int
    capacity_btu: Optional[float] = None
    capacity_kw: Optional[float] = None
```

### 2.2 Create csv_exporter.py
```python
# modules/csv_exporter.py
import pandas as pd
from pathlib import Path
from typing import Dict, List, Any
from datetime import datetime

class HVACCSVExporter:
    """Export HVAC analysis to CSV files"""
    
    def __init__(self, output_dir: str = "./outputs"):
        self.output_dir = Path(output_dir)
        self.output_dir.mkdir(exist_ok=True)
    
    def export_all(self, analysis_data: Dict, task_id: str) -> Dict[str, Path]:
        """Export all CSV files"""
        return {
            'floors_units': self.export_floors_units(analysis_data, task_id),
            'equipment_schedule': self.export_equipment_schedule(analysis_data, task_id),
            'reconciliation': self.export_reconciliation(analysis_data, task_id),
        }
    
    def export_floors_units(self, data: Dict, task_id: str) -> Path:
        """Export floor and units breakdown"""
        rows = []
        for floor in data.get('floors', []):
            for unit in floor.get('units', []):
                rows.append({
                    'Floor': floor['floor_number'],
                    'Unit_ID': unit['tag'],
                    'Unit_Type': unit['type'],
                    'Quantity': unit['quantity'],
                    'Capacity_BTU': unit.get('capacity_btu', ''),
                    'Capacity_kW': unit.get('capacity_kw', ''),
                    'Status': unit.get('detection_status', 'Detected'),
                    'Location': unit.get('location', ''),
                    'Notes': unit.get('notes', ''),
                })
        
        if not rows:
            rows = [{'Floor': '', 'Unit_ID': '', 'Unit_Type': ''}]
        
        df = pd.DataFrame(rows)
        path = self.output_dir / f"{task_id}_floors_units.csv"
        df.to_csv(path, index=False)
        return path
    
    def export_equipment_schedule(self, data: Dict, task_id: str) -> Path:
        """Export equipment schedule"""
        schedule = data.get('equipment_schedule', [])
        
        if not schedule:
            schedule = [{'Equipment_ID': '', 'Manufacturer': ''}]
        
        df = pd.DataFrame(schedule)
        path = self.output_dir / f"{task_id}_equipment_schedule.csv"
        df.to_csv(path, index=False)
        return path
    
    def export_reconciliation(self, data: Dict, task_id: str) -> Path:
        """Export reconciliation report"""
        issues = data.get('reconciliation', {}).get('issues', [])
        
        if not issues:
            issues = [{'Issue_Type': 'No issues', 'Severity': 'None'}]
        
        df = pd.DataFrame(issues)
        path = self.output_dir / f"{task_id}_reconciliation.csv"
        df.to_csv(path, index=False)
        return path

# Quick function for FastAPI
def create_exporter() -> HVACCSVExporter:
    return HVACCSVExporter()
```

### 2.3 Create server.py (Main FastAPI App)
```python
# server.py
import os
import uuid
import time
from pathlib import Path
from typing import Dict, Any
from datetime import datetime

from fastapi import FastAPI, UploadFile, File, HTTPException
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
import aiofiles
import zipfile
from io import BytesIO
from dotenv import load_dotenv

# Import your existing analysis module
# from python_files.read_mechanical_plansvs1_4 import analyze_blueprint
from modules.csv_exporter import HVACCSVExporter
from modules.models import AnalysisResult, AnalysisRequest

load_dotenv()

app = FastAPI(
    title="HVAC Blueprint Analyzer",
    description="Analyze HVAC systems from architectural blueprints",
    version="1.0.0"
)

# CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Serve static files
app.mount("/static", StaticFiles(directory="public"), name="static")

# Initialize exporter
exporter = HVACCSVExporter()

# Storage for active analyses (in-memory for now)
active_analyses = {}

@app.get("/")
async def root():
    """Serve main HTML page"""
    return FileResponse("public/index.html")

@app.post("/api/analyze")
async def analyze(
    file: UploadFile = File(...),
    model_choice: str = "gemini",
    schedule_mode: str = "auto"
):
    """
    Analyze uploaded blueprint
    
    Returns task_id for tracking
    """
    if not file.filename.endswith('.pdf'):
        raise HTTPException(status_code=400, detail="Only PDF files allowed")
    
    # Generate task ID
    task_id = str(uuid.uuid4())
    
    # Save uploaded file
    upload_dir = Path("./uploads")
    upload_dir.mkdir(exist_ok=True)
    file_path = upload_dir / f"{task_id}_{file.filename}"
    
    try:
        # Save file
        async with aiofiles.open(file_path, 'wb') as f:
            contents = await file.read()
            await f.write(contents)
        
        # Start analysis (mock for now - replace with your actual analysis)
        start_time = time.time()
        analysis_result = await analyze_blueprint_async(
            file_path, 
            model_choice, 
            schedule_mode
        )
        processing_time = time.time() - start_time
        
        # Add metadata
        analysis_result['task_id'] = task_id
        analysis_result['processing_time_seconds'] = processing_time
        analysis_result['model_used'] = model_choice
        analysis_result['file_name'] = file.filename
        
        # Generate CSVs
        csv_files = exporter.export_all(analysis_result, task_id)
        analysis_result['csv_files'] = {
            name: f"/api/download/csv/{task_id}/{name}" 
            for name in csv_files.keys()
        }
        
        # Store result
        active_analyses[task_id] = analysis_result
        
        return {
            "status": "success",
            "task_id": task_id,
            "result": analysis_result
        }
    
    except Exception as e:
        return {
            "status": "error",
            "task_id": task_id,
            "error": str(e)
        }

@app.get("/api/results/{task_id}")
async def get_results(task_id: str):
    """Get analysis results by task ID"""
    if task_id not in active_analyses:
        raise HTTPException(status_code=404, detail="Task not found")
    
    return active_analyses[task_id]

@app.get("/api/download/csv/{task_id}/{csv_type}")
async def download_csv(task_id: str, csv_type: str):
    """Download specific CSV file"""
    file_path = Path("./outputs") / f"{task_id}_{csv_type}.csv"
    
    if not file_path.exists():
        raise HTTPException(status_code=404, detail="File not found")
    
    return FileResponse(
        file_path,
        filename=f"hvac_{csv_type}.csv",
        media_type="text/csv"
    )

@app.get("/api/download/zip/{task_id}")
async def download_all_zip(task_id: str):
    """Download all outputs as ZIP"""
    if task_id not in active_analyses:
        raise HTTPException(status_code=404, detail="Task not found")
    
    # Create ZIP buffer
    zip_buffer = BytesIO()
    with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zf:
        # Add all CSVs
        for csv_type in ['floors_units', 'equipment_schedule', 'reconciliation']:
            file_path = Path("./outputs") / f"{task_id}_{csv_type}.csv"
            if file_path.exists():
                zf.write(file_path, arcname=file_path.name)
        
        # Add JSON results
        import json
        json_data = json.dumps(active_analyses[task_id], indent=2, default=str)
        zf.writestr(f"{task_id}_results.json", json_data)
    
    zip_buffer.seek(0)
    return StreamingResponse(
        iter([zip_buffer.getvalue()]),
        media_type="application/zip",
        headers={"Content-Disposition": f"attachment; filename=hvac_{task_id}.zip"}
    )

@app.get("/api/health")
async def health():
    """Health check endpoint"""
    return {"status": "ok"}

# ============================================================
# MOCK ANALYSIS FUNCTION - REPLACE WITH YOUR ACTUAL CODE
# ============================================================

async def analyze_blueprint_async(
    file_path: Path,
    model_choice: str = "gemini",
    schedule_mode: str = "auto"
) -> Dict[str, Any]:
    """
    Mock analysis function
    Replace this with your actual HVAC analysis code
    """
    
    # TODO: Replace with actual analysis from your existing code
    # For now, returning mock data
    
    return {
        "status": "success",
        "summary": {
            "total_floors": 3,
            "total_units": 8,
            "total_capacity_btu": 256000,
            "total_capacity_kw": 75.0
        },
        "floors": [
            {
                "floor_number": 1,
                "floor_type": "residential",
                "units": [
                    {
                        "tag": "AC-A",
                        "type": "Ceiling Concealed Ducted",
                        "quantity": 1,
                        "capacity_btu": 36000,
                        "capacity_kw": 10.5,
                        "location": "Living area",
                        "detection_status": "Detected"
                    },
                    {
                        "tag": "AC-B",
                        "type": "Wall Mounted",
                        "quantity": 1,
                        "capacity_btu": 24000,
                        "capacity_kw": 7.0,
                        "location": "Bedroom",
                        "detection_status": "Detected"
                    }
                ]
            },
            {
                "floor_number": 2,
                "floor_type": "residential",
                "units": [
                    {
                        "tag": "AC-C",
                        "type": "Ceiling Concealed Ducted",
                        "quantity": 1,
                        "capacity_btu": 36000,
                        "capacity_kw": 10.5,
                        "location": "Master bedroom",
                        "detection_status": "Detected"
                    },
                    {
                        "tag": "AC-D",
                        "type": "Wall Mounted",
                        "quantity": 2,
                        "capacity_btu": 24000,
                        "capacity_kw": 7.0,
                        "location": "Living areas",
                        "detection_status": "Detected"
                    }
                ]
            },
            {
                "floor_number": 3,
                "floor_type": "commercial",
                "units": [
                    {
                        "tag": "AC-E",
                        "type": "Ceiling Concealed Ducted",
                        "quantity": 1,
                        "capacity_btu": 48000,
                        "capacity_kw": 14.0,
                        "location": "Office zone",
                        "detection_status": "Detected"
                    }
                ]
            }
        ],
        "equipment_schedule": [
            {
                "id": 1,
                "manufacturer": "Carrier",
                "model": "25HNE024A03",
                "type": "Ceiling Cassette",
                "capacity_btu": 24000,
                "voltage": "208-230V",
                "phase": 1,
                "frequency_hz": 60,
                "quantity": 1,
                "floor": 1,
                "unit_tag": "AC-A"
            }
        ],
        "reconciliation": {
            "issues_found": 0,
            "high_severity": 0,
            "medium_severity": 0,
            "low_severity": 0,
            "issues": []
        },
        "cost_usd": 0.08
    }

# ============================================================

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        "server:app",
        host=os.getenv("HOST", "127.0.0.1"),
        port=int(os.getenv("PORT", 8000)),
        reload=os.getenv("DEBUG", True)
    )
```

---

## 🎨 STEP 3: HTML UI & Canvas (1.5 hours)

### 3.1 Create public/index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HVAC Blueprint Analyzer</title>
    <link rel="stylesheet" href="/static/style.css">
</head>
<body>
    <div class="container">
        <header>
            <h1>🏒 HVAC Blueprint Analyzer</h1>
            <p>Analyze HVAC systems from architectural blueprints</p>
        </header>

        <main>
            <!-- Upload Section -->
            <section class="card upload-section">
                <h2>πŸ“€ Upload Blueprint</h2>
                
                <div class="upload-area" id="uploadArea">
                    <svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                        <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
                        <polyline points="17 8 12 3 7 8"></polyline>
                        <line x1="12" y1="3" x2="12" y2="15"></line>
                    </svg>
                    <p>Drag & drop PDF here or click to browse</p>
                    <input type="file" id="fileInput" accept=".pdf" style="display:none;">
                </div>

                <div class="file-info" id="fileInfo" style="display:none;">
                    <span id="fileName"></span>
                    <span id="fileSize"></span>
                </div>

                <div class="config-grid">
                    <div class="config-item">
                        <label>AI Model:</label>
                        <div class="radio-group">
                            <input type="radio" id="gemini" name="model" value="gemini" checked>
                            <label for="gemini">Gemini</label>
                            <input type="radio" id="openai" name="model" value="openai">
                            <label for="openai">OpenAI</label>
                        </div>
                    </div>

                    <div class="config-item">
                        <label>Schedule Mode:</label>
                        <div class="radio-group">
                            <input type="radio" id="auto" name="schedule" value="auto" checked>
                            <label for="auto">Auto-Detect</label>
                            <input type="radio" id="manual" name="schedule" value="manual">
                            <label for="manual">Upload Schedule</label>
                        </div>
                    </div>
                </div>

                <button id="analyzeBtn" class="btn btn-primary" disabled>
                    πŸš€ Analyze Blueprint
                </button>
            </section>

            <!-- Loading Section -->
            <section class="card loading-section" id="loadingSection" style="display:none;">
                <div class="spinner"></div>
                <p id="loadingText">Processing blueprint...</p>
                <div class="progress-bar">
                    <div class="progress-fill" id="progressFill"></div>
                </div>
            </section>

            <!-- Results Section -->
            <section class="card results-section" id="resultsSection" style="display:none;">
                <div class="tabs">
                    <button class="tab-btn active" data-tab="summary">πŸ“Š Summary</button>
                    <button class="tab-btn" data-tab="floors">πŸ—οΈ Floors & Units</button>
                    <button class="tab-btn" data-tab="canvas">🎨 Floor Plan</button>
                    <button class="tab-btn" data-tab="downloads">⬇️ Downloads</button>
                </div>

                <!-- Summary Tab -->
                <div class="tab-content active" id="summary-tab">
                    <div class="stats-grid">
                        <div class="stat-card">
                            <div class="stat-label">Total Floors</div>
                            <div class="stat-value" id="totalFloors">-</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-label">Total Units</div>
                            <div class="stat-value" id="totalUnits">-</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-label">Total Capacity</div>
                            <div class="stat-value" id="totalCapacity">-</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-label">Processing Time</div>
                            <div class="stat-value" id="processingTime">-</div>
                        </div>
                    </div>

                    <div class="info-box">
                        <p><strong>Model Used:</strong> <span id="modelUsed">-</span></p>
                        <p><strong>File:</strong> <span id="fileName2">-</span></p>
                        <p><strong>Cost:</strong> <span id="costUsed">-</span></p>
                    </div>
                </div>

                <!-- Floors & Units Tab -->
                <div class="tab-content" id="floors-tab">
                    <h3>HVAC Units by Floor</h3>
                    <div class="table-container">
                        <table id="floorsTable">
                            <thead>
                                <tr>
                                    <th>Floor</th>
                                    <th>Unit ID</th>
                                    <th>Type</th>
                                    <th>Qty</th>
                                    <th>Capacity (BTU)</th>
                                    <th>Capacity (kW)</th>
                                    <th>Location</th>
                                </tr>
                            </thead>
                            <tbody id="floorsTableBody">
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Canvas/Floor Plan Tab -->
                <div class="tab-content" id="canvas-tab">
                    <h3>Floor Plan Visualization</h3>
                    <canvas id="floorCanvas" width="800" height="600" style="border:1px solid #ddd;"></canvas>
                </div>

                <!-- Downloads Tab -->
                <div class="tab-content" id="downloads-tab">
                    <h3>Download Results</h3>
                    <div class="downloads-grid">
                        <button class="btn btn-download" id="downloadFloors">
                            πŸ“„ Floors & Units (CSV)
                        </button>
                        <button class="btn btn-download" id="downloadSchedule">
                            πŸ“‹ Equipment Schedule (CSV)
                        </button>
                        <button class="btn btn-download" id="downloadReconciliation">
                            βœ”οΈ Reconciliation (CSV)
                        </button>
                        <button class="btn btn-download" id="downloadZip">
                            πŸ“¦ Download All (ZIP)
                        </button>
                    </div>
                </div>
            </section>

            <!-- Error Section -->
            <section class="card error-section" id="errorSection" style="display:none;">
                <h3>❌ Error</h3>
                <p id="errorMessage"></p>
                <button class="btn btn-secondary" onclick="location.reload()">Try Again</button>
            </section>
        </main>
    </div>

    <script src="/static/script.js"></script>
</body>
</html>
```

### 3.2 Create public/style.css
```css
/* style.css */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5em;
    color: var(--primary);
    margin-bottom: 10px;
}

header p {
    color: var(--text-light);
    font-size: 1.1em;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card h2,
.card h3 {
    margin-bottom: 20px;
    color: var(--text);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--primary);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 20px;
    background: #f0f9ff;
}

.upload-area:hover {
    border-color: var(--primary-hover);
    background: #e0f2fe;
}

.upload-area.dragover {
    border-color: var(--success);
    background: #f0fdf4;
}

.upload-icon {
    width: 60px;
    height: 60px;
    color: var(--primary);
    margin-bottom: 10px;
}

.upload-area p {
    color: var(--text-light);
    margin-bottom: 10px;
}

.file-info {
    background: #f1f5f9;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.config-item label {
    display: block;
    font-weight: 500;
    margin-bottom: 10px;
    color: var(--text);
}

.radio-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.radio-group input[type="radio"] {
    margin-right: 5px;
}

.radio-group label {
    display: inline;
    margin: 0;
    font-weight: 400;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:disabled {
    background: var(--border);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-download {
    background: var(--success);
    color: white;
    width: 100%;
    margin-bottom: 10px;
}

.btn-download:hover {
    background: #15803d;
}

/* Loading */
.spinner {
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 15px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    color: var(--text);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
}

/* Info Box */
.info-box {
    background: #f8fafc;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid var(--primary);
}

.info-box p {
    margin: 8px 0;
    font-size: 0.95em;
}

/* Table */
.table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: #f1f5f9;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: #f8fafc;
}

/* Canvas */
canvas {
    max-width: 100%;
    background: white;
    border-radius: 6px;
}

/* Downloads Grid */
.downloads-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

/* Error */
.error-section {
    border-left: 4px solid var(--error);
}

.error-section h3 {
    color: var(--error);
}

/* Responsive */
@media (max-width: 768px) {
    .config-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tabs {
        flex-direction: column;
    }

    .tab-btn {
        width: 100%;
        border-bottom: none;
        border-left: 3px solid transparent;
    }

    .tab-btn.active {
        border-left-color: var(--primary);
        border-bottom: none;
    }
}
```

### 3.3 Create public/script.js
```javascript
// script.js

const API_BASE = '/api';
let currentTaskId = null;
let currentAnalysis = null;

// DOM Elements
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const fileInfo = document.getElementById('fileInfo');
const analyzeBtn = document.getElementById('analyzeBtn');
const loadingSection = document.getElementById('loadingSection');
const resultsSection = document.getElementById('resultsSection');
const errorSection = document.getElementById('errorSection');
const tabs = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');

// ===== FILE UPLOAD =====
uploadArea.addEventListener('click', () => fileInput.click());

uploadArea.addEventListener('dragover', (e) => {
    e.preventDefault();
    uploadArea.classList.add('dragover');
});

uploadArea.addEventListener('dragleave', () => {
    uploadArea.classList.remove('dragover');
});

uploadArea.addEventListener('drop', (e) => {
    e.preventDefault();
    uploadArea.classList.remove('dragover');
    handleFiles(e.dataTransfer.files);
});

fileInput.addEventListener('change', (e) => {
    handleFiles(e.target.files);
});

function handleFiles(files) {
    const file = files[0];
    if (!file) return;

    if (!file.name.endsWith('.pdf')) {
        showError('Please upload a PDF file');
        return;
    }

    // Show file info
    fileInfo.style.display = 'block';
    document.getElementById('fileName').textContent = file.name;
    document.getElementById('fileSize').textContent = `(${(file.size / 1024 / 1024).toFixed(2)} MB)`;

    // Enable analyze button
    analyzeBtn.disabled = false;
    analyzeBtn.onclick = () => analyzeBlueprint(file);
}

// ===== ANALYSIS =====
async function analyzeBlueprint(file) {
    const modelChoice = document.querySelector('input[name="model"]:checked').value;
    const scheduleMode = document.querySelector('input[name="schedule"]:checked').value;

    // Prepare form data
    const formData = new FormData();
    formData.append('file', file);
    formData.append('model_choice', modelChoice);
    formData.append('schedule_mode', scheduleMode);

    // Show loading
    resultsSection.style.display = 'none';
    errorSection.style.display = 'none';
    loadingSection.style.display = 'block';

    // Simulate progress
    let progress = 0;
    const progressInterval = setInterval(() => {
        progress = Math.min(progress + Math.random() * 30, 90);
        document.getElementById('progressFill').style.width = progress + '%';
    }, 200);

    try {
        const response = await fetch(`${API_BASE}/analyze`, {
            method: 'POST',
            body: formData
        });

        clearInterval(progressInterval);

        if (!response.ok) {
            const error = await response.json();
            throw new Error(error.detail || 'Analysis failed');
        }

        document.getElementById('progressFill').style.width = '100%';
        const data = await response.json();

        if (data.status === 'error') {
            throw new Error(data.error);
        }

        currentTaskId = data.task_id;
        currentAnalysis = data.result;

        // Display results
        loadingSection.style.display = 'none';
        displayResults(data.result);
        resultsSection.style.display = 'block';

    } catch (error) {
        clearInterval(progressInterval);
        loadingSection.style.display = 'none';
        showError(error.message);
    }
}

// ===== DISPLAY RESULTS =====
function displayResults(result) {
    // Summary tab
    document.getElementById('totalFloors').textContent = result.summary.total_floors;
    document.getElementById('totalUnits').textContent = result.summary.total_units;
    document.getElementById('totalCapacity').textContent = 
        `${(result.summary.total_capacity_btu / 1000).toFixed(0)}k BTU`;
    document.getElementById('processingTime').textContent = 
        `${result.processing_time_seconds.toFixed(2)}s`;
    document.getElementById('modelUsed').textContent = result.model_used;
    document.getElementById('fileName2').textContent = result.file_name;
    document.getElementById('costUsed').textContent = `$${result.cost_usd.toFixed(4)}`;

    // Floors table
    populateFloorsTable(result.floors);

    // Canvas
    drawFloorPlan(result.floors);

    // Download buttons
    setupDownloadButtons(result.csv_files);
}

function populateFloorsTable(floors) {
    const tbody = document.getElementById('floorsTableBody');
    tbody.innerHTML = '';

    floors.forEach(floor => {
        floor.units.forEach(unit => {
            const row = tbody.insertRow();
            row.innerHTML = `
                <td>${floor.floor_number}</td>
                <td><strong>${unit.tag}</strong></td>
                <td>${unit.type}</td>
                <td>${unit.quantity}</td>
                <td>${unit.capacity_btu || '-'}</td>
                <td>${unit.capacity_kw || '-'}</td>
                <td>${unit.location || '-'}</td>
            `;
        });
    });
}

function drawFloorPlan(floors) {
    const canvas = document.getElementById('floorCanvas');
    const ctx = canvas.getContext('2d');

    // Clear canvas
    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0, 0, canvas.width, canvas.height);

    // Draw background
    ctx.strokeStyle = '#e2e8f0';
    ctx.lineWidth = 1;
    for (let i = 0; i < canvas.width; i += 50) {
        ctx.beginPath();
        ctx.moveTo(i, 0);
        ctx.lineTo(i, canvas.height);
        ctx.stroke();
    }

    // Draw floors
    const floorHeight = canvas.height / (floors.length + 1);
    floors.forEach((floor, floorIndex) => {
        const y = 50 + floorIndex * floorHeight;

        // Floor label
        ctx.fillStyle = '#1e293b';
        ctx.font = 'bold 16px Arial';
        ctx.fillText(`Floor ${floor.floor_number}`, 20, y);

        // Units
        let unitX = 150;
        floor.units.forEach(unit => {
            drawUnit(ctx, unitX, y, unit);
            unitX += 120;
        });

        // Floor line
        ctx.strokeStyle = '#cbd5e1';
        ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(0, y + 40);
        ctx.lineTo(canvas.width, y + 40);
        ctx.stroke();
    });
}

function drawUnit(ctx, x, y, unit) {
    // Unit box
    ctx.fillStyle = '#dbeafe';
    ctx.fillRect(x, y, 100, 30);

    ctx.strokeStyle = '#2563eb';
    ctx.lineWidth = 2;
    ctx.strokeRect(x, y, 100, 30);

    // Unit text
    ctx.fillStyle = '#1e293b';
    ctx.font = 'bold 12px Arial';
    ctx.textAlign = 'center';
    ctx.fillText(unit.tag, x + 50, y + 20);

    // Capacity below
    ctx.font = '10px Arial';
    ctx.fillStyle = '#64748b';
    ctx.fillText(`${unit.quantity}x${Math.round(unit.capacity_btu / 1000)}k`, x + 50, y + 35);
}

function setupDownloadButtons(csvFiles) {
    document.getElementById('downloadFloors').onclick = () => 
        downloadFile(csvFiles.floors_units, 'hvac_floors_units.csv');
    
    document.getElementById('downloadSchedule').onclick = () => 
        downloadFile(csvFiles.equipment_schedule, 'hvac_equipment_schedule.csv');
    
    document.getElementById('downloadReconciliation').onclick = () => 
        downloadFile(csvFiles.reconciliation, 'hvac_reconciliation.csv');
    
    document.getElementById('downloadZip').onclick = () => 
        downloadFile(`${API_BASE}/download/zip/${currentTaskId}`, 'hvac_analysis.zip');
}

function downloadFile(url, filename) {
    const a = document.createElement('a');
    a.href = url;
    a.download = filename;
    a.click();
}

// ===== TABS =====
tabs.forEach(tab => {
    tab.addEventListener('click', () => {
        // Remove active from all
        tabs.forEach(t => t.classList.remove('active'));
        tabContents.forEach(c => c.classList.remove('active'));

        // Add active to clicked
        tab.classList.add('active');
        const tabId = tab.dataset.tab + '-tab';
        document.getElementById(tabId).classList.add('active');
    });
});

// ===== ERROR HANDLING =====
function showError(message) {
    loadingSection.style.display = 'none';
    resultsSection.style.display = 'none';
    errorSection.style.display = 'block';
    document.getElementById('errorMessage').textContent = message;
}
```

---

## πŸ§ͺ STEP 4: CSV Integration (1.5 hours)

Already done in `server.py`! The exporter is integrated into the `/api/analyze` endpoint.

**Tests to run:**
```bash
# Test CSV generation
curl -X POST -F "file=@test.pdf" \
  -F "model_choice=gemini" \
  http://localhost:8000/api/analyze

# Download CSV
curl http://localhost:8000/api/download/csv/{task_id}/floors_units \
  -o floors_units.csv
```

---

## πŸš€ STEP 5: Testing & Bug Fixes (1 hour)

### 5.1 Run FastAPI Server
```bash
cd C:\Users\ruchy\OneDrive\Documents\hvac_project

# Activate venv
venv\Scripts\activate

# Run server
python server.py
```

**Expected output:**
```
INFO:     Uvicorn running on http://127.0.0.1:8000
INFO:     Application startup complete
```

### 5.2 Test in Browser
- Open: http://127.0.0.1:8000
- Upload test PDF
- Click "Analyze"
- Check results display
- Download CSVs

### 5.3 Common Fixes
```python
# If upload fails:
# 1. Check /uploads folder exists
# 2. Check file permissions
# 3. Check PDF is valid

# If CSV not generated:
# 1. Check /outputs folder exists
# 2. Check Pandas is installed
# 3. Check data structure matches

# If canvas not displaying:
# 1. Check browser console for JS errors
# 2. Ensure floor data structure is correct
# 3. Check canvas size
```

---

## πŸ“¦ STEP 6: Polish & Deployment (30 min)

### 6.1 Replace Mock Analysis
In `server.py`, replace the `analyze_blueprint_async()` function with your actual code:

```python
async def analyze_blueprint_async(file_path, model_choice, schedule_mode):
    # Import your actual analyzer
    from python_files.read_mechanical_plansvs1_4 import extract_blueprint_data
    
    # Run analysis
    result = extract_blueprint_data(str(file_path), model_choice)
    
    return result
```

### 6.2 Create .gitignore
```
venv/
__pycache__/
*.pyc
.env
outputs/
uploads/
.DS_Store
.idea/
*.log
```

### 6.3 Deploy to Cloud (Choose One)

**Option A: Heroku (Easiest)**
```bash
# Create requirements.txt
pip freeze > requirements.txt

# Create Procfile
echo "web: uvicorn server:app --host 0.0.0.0 --port $PORT" > Procfile

# Deploy
heroku create hvac-analyzer
git push heroku main
```

**Option B: Google Cloud Run**
```bash
# Create Dockerfile
# Create cloudbuild.yaml
# Deploy via gcloud CLI
gcloud run deploy hvac-analyzer --source .
```

**Option C: Local/VPS**
- Use systemd service
- Run with Gunicorn: `gunicorn -w 4 -k uvicorn.workers.UvicornWorker server:app`
- Configure Nginx reverse proxy

---

## βœ… FINAL CHECKLIST

- [x] FastAPI server running
- [x] HTML UI loads
- [x] File upload works
- [x] Analysis runs (with mock data)
- [x] Results display
- [x] CSV exports work
- [x] Canvas draws floor plan
- [x] Download buttons functional
- [x] Error handling in place
- [x] Responsive on mobile

---

## 🎯 Next Steps (After 1 Day)

1. **Replace mock analysis** with your actual HVAC code
2. **Add Gemini API calls** (if not already done)
3. **Implement OpenAI fallback**
4. **Add A/B testing comparison** tab
5. **Create schedule upload** functionality
6. **Deploy to production** URL
7. **Add monitoring & logging**

---

## πŸ“ Project Layout After Build

```
hvac_project/
β”œβ”€β”€ server.py              βœ…
β”œβ”€β”€ requirements.txt       βœ…
β”œβ”€β”€ .env                   βœ…
β”œβ”€β”€ .gitignore             βœ…
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ index.html        βœ…
β”‚   β”œβ”€β”€ style.css         βœ…
β”‚   └── script.js         βœ…
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ csv_exporter.py   βœ…
β”‚   └── models.py         βœ…
β”œβ”€β”€ uploads/              (auto-created)
β”œβ”€β”€ outputs/              (auto-created)
└── python_files/         (your existing code)
```

---

## πŸŽ‰ Success = Working Demo in 6 Hours!

Once done, you'll have:
- βœ… FastAPI backend running
- βœ… Professional HTML/Canvas UI
- βœ… File upload & processing
- βœ… CSV export (3 files)
- βœ… Floor plan visualization
- βœ… Deployed to cloud

**Ready to show investors/clients!**