sialnoman318 commited on
Commit
bd68ea4
·
verified ·
1 Parent(s): 9c9d0eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ import random
4
+ import os
5
+
6
+ # Function to generate a room layout based on dimensions and desired upgrades
7
+ def generate_room_plan(dimensions, current_use, upgrades):
8
+ try:
9
+ width, height = map(float, dimensions.split('x'))
10
+ except ValueError:
11
+ return "Error: Room dimensions must be in 'width x height' format (e.g., 15x12)."
12
+
13
+ # Create a figure
14
+ fig, ax = plt.subplots(figsize=(8, 6))
15
+ ax.set_xlim(0, width)
16
+ ax.set_ylim(0, height)
17
+
18
+ # Draw room boundary
19
+ ax.plot([0, width, width, 0, 0], [0, 0, height, height, 0], color="black", linewidth=2, label="Room Boundary")
20
+
21
+ # Add furniture placement based on upgrades
22
+ if "bed" in upgrades.lower():
23
+ bed_width, bed_height = width * 0.3, height * 0.2
24
+ ax.add_patch(plt.Rectangle((1, 1), bed_width, bed_height, color="blue", alpha=0.5, label="Bed"))
25
+ if "sofa" in upgrades.lower():
26
+ sofa_width, sofa_height = width * 0.3, height * 0.1
27
+ ax.add_patch(plt.Rectangle((width - sofa_width - 1, 1), sofa_width, sofa_height, color="green", alpha=0.5, label="Sofa"))
28
+ if "table" in upgrades.lower():
29
+ table_width, table_height = width * 0.2, height * 0.15
30
+ ax.add_patch(plt.Rectangle((width / 2 - table_width / 2, height / 2 - table_height / 2), table_width, table_height, color="brown", alpha=0.5, label="Table"))
31
+
32
+ # Add labels and legend
33
+ ax.set_title(f"{current_use.capitalize()} Layout with Upgrades")
34
+ ax.legend(loc="upper right")
35
+ ax.axis('off')
36
+
37
+ # Save the figure to a file
38
+ output_path = "room_layout.png"
39
+ plt.savefig(output_path)
40
+ plt.close(fig)
41
+
42
+ # Return the file path
43
+ return output_path
44
+
45
+ # Function to estimate renovation costs
46
+ def estimate_cost(dimensions, upgrades):
47
+ try:
48
+ width, height = map(float, dimensions.split('x'))
49
+ except ValueError:
50
+ return "Error: Room dimensions must be in 'width x height' format (e.g., 15x12)."
51
+
52
+ area = width * height
53
+ base_cost = area * 50 # Basic cost per square foot
54
+
55
+ upgrade_costs = {
56
+ "bed": 500,
57
+ "sofa": 300,
58
+ "table": 200,
59
+ "paint": 150,
60
+ "lighting": 250
61
+ }
62
+
63
+ total_cost = base_cost
64
+ for upgrade in upgrades.split(','):
65
+ upgrade = upgrade.strip().lower()
66
+ if upgrade in upgrade_costs:
67
+ total_cost += upgrade_costs[upgrade]
68
+
69
+ return f"Estimated Renovation Cost: ${total_cost:.2f}"
70
+
71
+ # Gradio interface
72
+ def renovation_planner(dimensions, current_use, upgrades):
73
+ layout = generate_room_plan(dimensions, current_use, upgrades)
74
+ cost = estimate_cost(dimensions, upgrades)
75
+ return layout, cost
76
+
77
+ interface = gr.Interface(
78
+ fn=renovation_planner,
79
+ inputs=[
80
+ gr.Textbox(label="Room Dimensions (e.g., 15x12)"),
81
+ gr.Textbox(label="Current Use (e.g., Bedroom, Living Room)"),
82
+ gr.Textbox(label="Desired Upgrades (e.g., Bed, Sofa, Paint, Lighting)"),
83
+ ],
84
+ outputs=[
85
+ gr.Image(label="Room Layout"),
86
+ gr.Textbox(label="Renovation Cost Estimate"),
87
+ ],
88
+ title="Single-Room Renovation Planner",
89
+ description="Provide room dimensions, current use, and desired upgrades to get a layout and cost estimate."
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ interface.launch()