GlobalBusinessAdvisors
commited on
Commit
•
f2dd871
1
Parent(s):
8e05fd0
Update ui/gradio_ui.py
Browse files- ui/gradio_ui.py +85 -41
ui/gradio_ui.py
CHANGED
@@ -1,46 +1,90 @@
|
|
1 |
import gradio as gr
|
2 |
-
import httpx
|
3 |
-
import asyncio
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
def create_ui():
|
16 |
with gr.Blocks() as demo:
|
17 |
-
with gr.
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
def create_ui():
|
4 |
+
def generate_plan(property_type, retrofit_area, building_age, blueprints, heating_system, cooling_system, insulation_quality, known_issues, energy_source, windows, monthly_bills, mortgage, mortgage_years, gross_income, monthly_expenses, credit_score, financing_term, preferred_term, budget, financing_interest):
|
5 |
+
# Dummy function for generating a retrofit plan
|
6 |
+
retrofit_plan = (
|
7 |
+
f"Property Type: {property_type}\n"
|
8 |
+
f"Retrofit Area: {retrofit_area} sqft\n"
|
9 |
+
f"Building Age: {building_age} years\n"
|
10 |
+
f"Blueprints or Energy Audits: {blueprints}\n"
|
11 |
+
f"Heating System: {heating_system}\n"
|
12 |
+
f"Cooling System: {cooling_system}\n"
|
13 |
+
f"Insulation Quality: {insulation_quality}\n"
|
14 |
+
f"Known Issues: {known_issues}\n"
|
15 |
+
f"Energy Source: {energy_source}\n"
|
16 |
+
f"Windows: {windows}\n"
|
17 |
+
f"Monthly Heating and Electricity Bills: ${monthly_bills}\n"
|
18 |
+
f"Mortgage: {mortgage}\n"
|
19 |
+
f"Mortgage Years Remaining: {mortgage_years} years\n"
|
20 |
+
f"Gross Income: ${gross_income}/month\n"
|
21 |
+
f"Monthly Expenses: ${monthly_expenses}\n"
|
22 |
+
f"Credit Score: {credit_score}\n"
|
23 |
+
f"Financing Term: {financing_term}\n"
|
24 |
+
f"Preferred Financing Term: {preferred_term}\n"
|
25 |
+
f"Budget: {budget}\n"
|
26 |
+
f"Interested in Financing: {financing_interest}\n"
|
27 |
+
)
|
28 |
+
return retrofit_plan
|
29 |
|
30 |
+
def calculate_cost(retrofit_area, insulation_quality, known_issues, energy_source, windows):
|
31 |
+
# Dummy function for calculating retrofit costs
|
32 |
+
base_cost = 5000
|
33 |
+
area_cost = retrofit_area * 10
|
34 |
+
insulation_cost = {'Poor': 3000, 'Average': 2000, 'Good': 1000, 'Excellent': 500}[insulation_quality]
|
35 |
+
issues_cost = 2000 if known_issues == 'Yes' else 0
|
36 |
+
windows_cost = {'Yes': 3000, 'No': 5000, 'Unsure': 4000}[windows]
|
37 |
+
energy_cost = {'Electricity': 1000, 'Natural gas': 2000, 'Oil': 3000, 'Renewable': 500}[energy_source]
|
38 |
+
|
39 |
+
total_cost = base_cost + area_cost + insulation_cost + issues_cost + windows_cost + energy_cost
|
40 |
+
return f"Estimated Retrofit Cost: ${total_cost}"
|
41 |
|
|
|
42 |
with gr.Blocks() as demo:
|
43 |
+
with gr.TabItem("Property Information"):
|
44 |
+
property_type = gr.Dropdown(label="Type of Property", choices=["Single-family home", "Multi-family building", "Other residential"])
|
45 |
+
retrofit_area = gr.Number(label="Retrofit Area (sqft)")
|
46 |
+
building_age = gr.Number(label="Building Age (years)")
|
47 |
+
blueprints = gr.Dropdown(label="Existing Blueprints or Energy Audits", choices=["Yes", "No"])
|
48 |
+
heating_system = gr.Dropdown(label="Heating System", choices=["Furnace", "Boiler", "Heat pump", "None", "Other"])
|
49 |
+
cooling_system = gr.Dropdown(label="Cooling System", choices=["Central air conditioning", "Window units", "None", "Other"])
|
50 |
+
insulation_quality = gr.Dropdown(label="Insulation Quality", choices=["Poor", "Average", "Good", "Excellent"])
|
51 |
+
known_issues = gr.Dropdown(label="Known Issues (e.g., leaks, drafts)", choices=["Yes", "No"])
|
52 |
+
energy_source = gr.Dropdown(label="Primary Energy Source", choices=["Electricity", "Natural gas", "Oil", "Renewable", "Other"])
|
53 |
+
windows = gr.Dropdown(label="Windows Double-Glazed", choices=["Yes", "No", "Unsure"])
|
54 |
+
|
55 |
+
with gr.TabItem("Financial Information"):
|
56 |
+
monthly_bills = gr.Number(label="Average Monthly Heating and Electricity Bills ($)")
|
57 |
+
mortgage = gr.Dropdown(label="Do you have a mortgage?", choices=["Yes", "No"])
|
58 |
+
mortgage_years = gr.Number(label="Years remaining on mortgage", visible=False)
|
59 |
+
gross_income = gr.Number(label="Total Household Monthly Gross Income ($)")
|
60 |
+
monthly_expenses = gr.Number(label="Total Monthly Household Expenses ($)")
|
61 |
+
credit_score = gr.Number(label="Credit Score")
|
62 |
+
financing_term = gr.Dropdown(label="Preferred Financing Term", choices=["Align with mortgage", "Different term"])
|
63 |
+
preferred_term = gr.Dropdown(label="Preferred Term for Financing", choices=["5 years", "10 years", "15 years", "25 years"], visible=False)
|
64 |
+
budget = gr.Dropdown(label="Budget for Retrofit Project", choices=["Under $10,000", "$10,000 to $50,000", "$50,000 to $100,000", "Over $100,000"])
|
65 |
+
financing_interest = gr.Dropdown(label="Interested in Financing Options", choices=["Yes", "No"])
|
66 |
+
|
67 |
+
with gr.TabItem("Generate Plan"):
|
68 |
+
submit_btn = gr.Button("Generate Retrofit Plan")
|
69 |
+
output_plan = gr.Textbox(label="Retrofit Plan")
|
70 |
+
submit_btn.click(
|
71 |
+
fn=generate_plan,
|
72 |
+
inputs=[
|
73 |
+
property_type, retrofit_area, building_age, blueprints, heating_system, cooling_system, insulation_quality, known_issues, energy_source, windows,
|
74 |
+
monthly_bills, mortgage, mortgage_years, gross_income, monthly_expenses, credit_score, financing_term, preferred_term, budget, financing_interest
|
75 |
+
],
|
76 |
+
outputs=output_plan
|
77 |
+
)
|
78 |
+
|
79 |
+
with gr.TabItem("Calculate Cost"):
|
80 |
+
cost_btn = gr.Button("Calculate Retrofit Cost")
|
81 |
+
output_cost = gr.Textbox(label="Estimated Cost")
|
82 |
+
cost_btn.click(
|
83 |
+
fn=calculate_cost,
|
84 |
+
inputs=[retrofit_area, insulation_quality, known_issues, energy_source, windows],
|
85 |
+
outputs=output_cost
|
86 |
+
)
|
87 |
+
|
88 |
+
return demo
|
89 |
+
|
90 |
+
ui = create_ui()
|