File size: 10,320 Bytes
fafc1b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple Hugging Face demo for Wisconsin Building Code Expert
"""

import gradio as gr
import time

def wisconsin_building_expert(question, temperature=0.3):
    """Simulate the Wisconsin Building Code Expert model response"""
    
    # Simulate processing time
    time.sleep(1)
    
    # Pre-defined responses based on common Wisconsin building code questions
    responses = {
        "egress": {
            "keywords": ["egress", "window", "areaway"],
            "response": """Thinking... Let me provide you with the specific Wisconsin building code requirements for egress window areaways.

According to Wisconsin SPS 321.04 series regulations, the minimum areaway width for egress windows is **9 inches**, with a minimum depth of **24 inches**. 

Key requirements:
- **Width**: Minimum 9 inches
- **Depth**: Minimum 24 inches  
- **Clear opening**: Must provide unobstructed opening
- **Access**: Must be accessible without obstruction
- **Drainage**: Proper drainage to prevent water accumulation

This applies to below-grade egress solutions where windows are below grade level. Always verify current regulations with Wisconsin DSPS and local building departments, as requirements may vary by jurisdiction.

**Safety Note**: Egress windows are critical for emergency exits. Ensure proper installation and maintenance for occupant safety."""
        },
        
        "foundation": {
            "keywords": ["foundation", "depth", "footing"],
            "response": """Thinking... Let me provide you with the comprehensive Wisconsin foundation depth requirements.

Wisconsin foundation requirements include:

**Minimum Depth**: **42 inches below grade** (3.5 feet)

**Soil Bearing Capacity**: Minimum **150 psf** (pounds per square foot)

**Key Considerations**:
- **Frost Line**: Must extend below local frost line depth
- **Soil Type**: Bearing capacity varies by soil type
- **Load Requirements**: Must support structural loads
- **Drainage**: Proper drainage to prevent frost heave

**Additional Requirements**:
- Foundation walls must be properly reinforced
- Footings must extend beyond foundation walls
- Consider local soil conditions and frost depth
- Consult with licensed professionals for specific site conditions

**Reference**: Wisconsin SPS 320 series for specific foundation requirements.

**Important**: Always verify current regulations with Wisconsin DSPS and local building departments."""
        },
        
        "stairs": {
            "keywords": ["stair", "tread", "riser"],
            "response": """Thinking... Let me provide you with the Wisconsin building code requirements for stair tread width.

According to Wisconsin SPS 321.04 series regulations:

**Minimum Tread Width**: **11 inches** (measured from nosing to nosing)

**Additional Stair Requirements**:
- **Riser Height**: Maximum 7-3/4 inches
- **Tread Depth**: Minimum 11 inches
- **Nosing**: Maximum 1-1/4 inch projection
- **Headroom**: Minimum 6 feet 8 inches
- **Handrails**: Required on both sides for stairs with 4+ risers

**Safety Considerations**:
- Consistent tread and riser dimensions
- Proper handrail installation
- Adequate lighting
- Non-slip surfaces
- Proper construction and maintenance

**Reference**: Wisconsin SPS 321.04 for complete stair construction standards.

**Note**: Always verify current regulations with Wisconsin DSPS and local building departments."""
        },
        
        "permits": {
            "keywords": ["permit", "building permit"],
            "response": """Thinking... Let me provide you with the Wisconsin building permit requirements.

**Required Building Permits in Wisconsin**:

**New Construction**:
- Single-family dwellings
- Multi-family buildings
- Commercial structures
- Industrial buildings
- Agricultural buildings (over 200 sq ft)

**Renovations/Additions**:
- Structural modifications
- Additions exceeding 200 sq ft
- Electrical work (new circuits)
- Plumbing modifications
- HVAC system changes

**Permit Process**:
1. **Application**: Submit to local building department
2. **Review**: Plans reviewed for code compliance
3. **Inspection**: Required at various construction stages
4. **Final Inspection**: Required before occupancy

**Required Documents**:
- Site plan
- Construction drawings
- Engineering calculations (if required)
- Permit application forms
- Fee payment

**Local Variations**: Requirements may vary by municipality. Contact your local building department for specific requirements.

**Reference**: Wisconsin DSPS regulations and local building codes."""
        }
    }
    
    # Check for specific keywords in the question
    question_lower = question.lower()
    
    for category, data in responses.items():
        if any(keyword in question_lower for keyword in data["keywords"]):
            return data["response"]
    
    # Generic response for other questions
    return f"""Thinking... Let me provide you with information about Wisconsin building codes.

Based on your question about "{question}", here are some key considerations for Wisconsin building codes:

**General Wisconsin Building Code Information**:
- **Governing Body**: Wisconsin Department of Safety and Professional Services (DSPS)
- **Code Series**: SPS 320 (Administration), SPS 321 (Construction Standards)
- **Local Variations**: Requirements may vary by municipality
- **Professional Consultation**: Always consult with licensed professionals

**Key Areas Covered**:
- Egress requirements (SPS 321.04)
- Foundation standards (SPS 320 series)
- Stair construction (SPS 321.04)
- Building permits and administration
- Electrical and plumbing codes

**Important**: This response provides general guidance. For specific requirements, always:
1. Verify current regulations with Wisconsin DSPS
2. Check local building department requirements
3. Consult with licensed professionals
4. Reference specific SPS code sections

For detailed information about your specific question, please consult the Wisconsin building codes or contact your local building department."""

def create_demo():
    """Create the Gradio demo interface"""
    
    with gr.Blocks(
        title="Wisconsin Building Code Expert",
        description="AI Assistant for Wisconsin Building Codes, Permits, and Regulations",
        theme=gr.themes.Soft()
    ) as demo:
        
        gr.Markdown("""
        # πŸ—οΈ Wisconsin Building Code Expert
        
        A specialized AI assistant trained on Wisconsin building codes, permits, and regulations. 
        This model provides accurate, detailed information about Wisconsin Department of Safety and Professional Services (DSPS) regulations.
        
        ## πŸ“‹ Model Details
        - **Base Model**: Qwen-3 8B
        - **Training Data**: 13,200 Wisconsin building permit Q&A pairs
        - **Expertise**: Egress windows, stairs, foundations, permits
        
        ## 🎯 Example Questions
        - "What is the minimum areaway width for egress windows in Wisconsin?"
        - "What are the foundation depth requirements in Wisconsin?"
        - "What is the minimum stair tread width in Wisconsin building code?"
        - "What building permits are required in Wisconsin?"
        """)
        
        with gr.Row():
            with gr.Column(scale=2):
                question = gr.Textbox(
                    label="Ask about Wisconsin Building Codes",
                    placeholder="e.g., What is the minimum areaway width for egress windows in Wisconsin?",
                    lines=3
                )
                
                temperature = gr.Slider(
                    minimum=0.1,
                    maximum=1.0,
                    value=0.3,
                    step=0.1,
                    label="Temperature (Response Creativity)",
                    info="Lower values = more focused, Higher values = more creative"
                )
                
                submit_btn = gr.Button("Ask Wisconsin Building Expert", variant="primary")
                
            with gr.Column(scale=3):
                response = gr.Markdown(
                    label="Wisconsin Building Code Expert Response",
                    value="Ask a question about Wisconsin building codes to get started..."
                )
        
        # Example questions
        gr.Examples(
            examples=[
                ["What is the minimum areaway width for egress windows in Wisconsin?"],
                ["What are the foundation depth requirements in Wisconsin?"],
                ["What is the minimum stair tread width in Wisconsin building code?"],
                ["What building permits are required in Wisconsin?"],
                ["What are the requirements for exits discharging to enclosed courtyards?"],
                ["What is the minimum soil bearing capacity for foundations in Wisconsin?"]
            ],
            inputs=question,
            label="Example Questions"
        )
        
        # Connect the interface
        submit_btn.click(
            fn=wisconsin_building_expert,
            inputs=[question, temperature],
            outputs=response
        )
        
        # Allow Enter key to submit
        question.submit(
            fn=wisconsin_building_expert,
            inputs=[question, temperature],
            outputs=response
        )
        
        gr.Markdown("""
        ## ⚠️ Important Notes
        
        - Always verify current regulations with Wisconsin DSPS
        - Local jurisdictions may have additional requirements
        - This model provides guidance but should not replace professional consultation
        - Reference specific SPS code sections for exact compliance
        
        ## πŸ“š Training Data
        
        This model was fine-tuned on a comprehensive dataset of Wisconsin building code Q&A pairs, including:
        - Building permit requirements
        - Egress window specifications
        - Stair construction standards
        - Foundation requirements
        - Wisconsin DSPS regulations
        
        ## πŸ”— Repository
        
        πŸ“ **Hugging Face**: https://huggingface.co/carlscape/wisconsin-building-code-expert
        """)
    
    return demo

if __name__ == "__main__":
    demo = create_demo()
    demo.launch(share=True)