EnagantuSruthi14 commited on
Commit
3fb5a7b
verified
1 Parent(s): 0d45cca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -0
app.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
4
+ from jinja2 import Template
5
+ from IPython.display import display, HTML
6
+ # Load the Stable Diffusion model
7
+ sd_model_id = "bhoomikagp/sd2-interior-model-version2"
8
+ scheduler = EulerDiscreteScheduler.from_pretrained(sd_model_id, subfolder="scheduler")
9
+
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ torch_dtype = torch.float16 if device == "cuda" else torch.float32
12
+
13
+ sd_pipeline = StableDiffusionPipeline.from_pretrained(
14
+ sd_model_id,
15
+ torch_dtype=torch_dtype,
16
+ scheduler=scheduler
17
+ ).to(device)
18
+
19
+ # Choices lists
20
+ option_choices = ["Living Room", "Bedroom", "Kitchen", "Dining Room", "Bathroom", "Office Room", "Laundry Room", "Family Room", "Play Room", "Study Room"]
21
+ adj_1_choices = [
22
+ "Large", "Comfortable", "Simple", "Fancy", "New", "Country Style",
23
+ "Rich", "Friendly", "Bright", "Stylish", "Cheerful", "Warm",
24
+ "Peaceful", "Trendy", "Chic"
25
+ ]
26
+ architecture_style_choices = ["New", "Current", "Classic", "Factory", "Scandinavian",
27
+ "Old Style", "Colonial", "Art Style", "Old Classic", "Mediterranean",
28
+ "Pointed", "Fancy", "Japanese", "Rough", "Tropical"]
29
+ aesthetic_choices = ["Free Spirit", "Old", "Simple", "Rich", "Mixed",
30
+ "Mid-Century", "Art Style", "Farmhouse", "Industrial",
31
+ "Worn", "Rustic", "Beach", "City", "Mixed",
32
+ "Classic Modern"]
33
+ accent_color_choices = ["blue", "green", "beige", "grey", "white", "black", "cream", "brown", "taupe", "burgundy", "mustard", "terracotta", "olive", "peach", "navy"]
34
+ wood_finish_choices = ["dark oak", "walnut", "mahogany", "teak", "maple", "cherry", "pine", "birch", "ash", "rosewood", "ebony", "cedar", "hickory", "elm", "red oak"]
35
+ wall_color_choices = ["cream", "off-white", "charcoal", "sage green", "navy blue", "taupe", "light grey", "soft pink", "mustard yellow", "deep teal", "warm beige", "pearl white", "slate blue", "coral", "mint green"]
36
+ tiles_choices = ["marble", "ceramic", "porcelain", "slate", "wooden-look", "mosaic", "granite", "terracotta", "cement", "quartz", "limestone", "onyx", "travertine", "glass", "encaustic"]
37
+
38
+ # Cost Data Links
39
+ cost_data = {
40
+ "Accent Color": {color: f'<a href="https://materialdepot.in/primary%20color%20{color.replace(" ", "%20")}-search">{color}</a>' for color in accent_color_choices},
41
+ "Wood Finish": {wood: f'<a href="https://materialdepot.in/wood%20finish%20{wood.replace(" ", "%20")}-search">{wood}</a>' for wood in wood_finish_choices},
42
+ "Tiles": {tile: f'<a href="https://materialdepot.in/tiles%20{tile.replace(" ", "%20")}-search">{tile}</a>' for tile in tiles_choices},
43
+ "Wall Color": {color: f'<a href="https://materialdepot.in/wall%20color%20{color.replace(" ", "%20")}-search">{color}</a>' for color in wall_color_choices},
44
+ }
45
+ def get_selected_cost_links(accent_color, wood_finish, wall_color, tiles):
46
+ selected_links = [
47
+ f"**Accent Color ({accent_color})**: {cost_data['Accent Color'].get(accent_color, 'No link available')}","\n"
48
+ f"**Wood Finish ({wood_finish})**: {cost_data['Wood Finish'].get(wood_finish, 'No link available')}","\n"
49
+ f"**Wall Color ({wall_color})**: {cost_data['Wall Color'].get(wall_color, 'No link available')}","\n"
50
+ f"**Tiles ({tiles})**: {cost_data['Tiles'].get(tiles, 'No link available')}""\n"
51
+ ]
52
+ return "\n".join(selected_links)
53
+
54
+ # Templates for room descriptions
55
+ templates = {
56
+ room: Template(
57
+ """
58
+ High quality, high resolution, interior render of a {{ adj_1 }} {{ room | lower }}, in {{ architecture_style }} architecture,
59
+ with {{ aesthetic }} style, painted in {{ wall_color }} with {{ accent_color }} accents, {{ wood_finish }} wood finishes,
60
+ and {{ tiles }} flooring.
61
+ """
62
+ ) for room in option_choices
63
+ }
64
+
65
+ def generate_prompt(option, adj_1, architecture_style, aesthetic, accent_color, wood_finish, wall_color, tiles):
66
+ return templates[option].render(
67
+ room=option,
68
+ adj_1=adj_1,
69
+ architecture_style=architecture_style,
70
+ aesthetic=aesthetic,
71
+ accent_color=accent_color,
72
+ wood_finish=wood_finish,
73
+ wall_color=wall_color,
74
+ tiles=tiles
75
+ )
76
+
77
+ def generate_image(option, adj_1, architecture_style, aesthetic, accent_color, wood_finish, wall_color, tiles):
78
+ prompt = generate_prompt(option, adj_1, architecture_style, aesthetic, accent_color, wood_finish, wall_color, tiles)
79
+ generator = torch.manual_seed(torch.randint(0, 2**32, (1,)).item())
80
+ img = sd_pipeline(
81
+ prompt=prompt,
82
+ guidance_scale=7,
83
+ num_inference_steps=20,
84
+ width=640,
85
+ height=640,
86
+ generator=generator
87
+ ).images[0]
88
+ return img
89
+
90
+ # Gradio UI
91
+ with gr.Blocks() as app:
92
+ gr.HTML("<div style='display: flex; justify-content: center; align-items: center;'><img src='https://media-hosting.imagekit.io//43432412d59b4330/DALL路E 2025-02-07 15.41.46 - A minimalist logo design for 'DreamSpace AI'. The logo features a small house outline combined with a glowing futuristic circuit pattern, symbolizing .webp?Expires=1835243070&Key-Pair-Id=K2ZIVPTIP2VGHC&Signature=qiDQGAh0pyv-ltJc5vwaUS4ax~9l1Cq3pLGHava2Lv4s94gyUWuNY3OqQiHsrklChaeVA78PfM7xdBxNlKV5HlKu17xGQaxouZ3BIlLQi93dRVZoqc3Tj4RfFn~7yaYoKTkkG6gjtuQabX~zK3Uzylatyvjl7uO2UCRzN-R2bFpkJPmiu1c2WGgRtTqQhMjUfY4CaVfzRhZgZ~ISdqAxBBR6XqIUgFbEi2DrsezXe59~wzmoFzTAuIxbmOD6CtuivUBNtFMHoInyOwlbPm~vl6pPhuuTe0c2WSDZIW79wu7B-FmFVl-d4bldVPZ4uP~K6-ux4RVg1zO2FnloeuRUmQ__' style='width: 50px; height: auto; margin-right: 10px;'><h1>DREAMSPACE AI</h1></div>")
93
+
94
+
95
+ with gr.Row():
96
+ option = gr.Dropdown(label="Room Type", choices=option_choices, value="Living Room")
97
+ adj_1 = gr.Dropdown(label="Primary Adjective", choices=adj_1_choices, value="Modern")
98
+ architecture_style = gr.Dropdown(label="Architecture Style", choices=architecture_style_choices, value="Modern")
99
+
100
+ with gr.Row():
101
+ aesthetic = gr.Dropdown(label="Interior Theme", choices=aesthetic_choices, value="Minimalist")
102
+ accent_color = gr.Dropdown(label="Primary Color", choices=accent_color_choices, value="White")
103
+ wood_finish = gr.Dropdown(label="Wood Finish", choices=wood_finish_choices, value="Oak")
104
+
105
+ with gr.Row():
106
+ wall_color = gr.Dropdown(label="Wall Color", choices=wall_color_choices, value="Off-White")
107
+ tiles = gr.Dropdown(label="Tile Type", choices=tiles_choices, value="Marble")
108
+
109
+ generate_btn = gr.Button("馃帹 Generate Image")
110
+ output_image = gr.Image(label="Generated Image")
111
+
112
+ calculate_costs_btn = gr.Button("馃挵 Check Costs")
113
+ costs_output = gr.Markdown("\n")
114
+
115
+ generate_btn.click(
116
+ fn=generate_image,
117
+ inputs=[option, adj_1, architecture_style, aesthetic, accent_color, wood_finish, wall_color, tiles],
118
+ outputs=output_image
119
+ )
120
+
121
+ calculate_costs_btn.click(
122
+ fn=get_selected_cost_links,
123
+ inputs=[accent_color, wood_finish, wall_color, tiles],
124
+ outputs=costs_output
125
+ )
126
+
127
+ app.launch(debug=True, share=True)
128
+ display(HTML("<style>#calculate-costs-btn {background-color: #007bff; color: white; border: none; padding: 10px 20px; cursor: pointer;} #calculate-costs-btn:hover {background-color: #0056b3;}</style>"))