mahmoud22565 commited on
Commit
e8155a8
Β·
verified Β·
1 Parent(s): 483d338

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +117 -20
app.py CHANGED
@@ -1,43 +1,140 @@
1
- import gradio as gr
2
- from PIL import Image
3
  import torch
 
4
  from diffusers import StableDiffusionImg2ImgPipeline
 
5
 
 
 
 
6
  model_id = "runwayml/stable-diffusion-v1-5"
7
 
8
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
9
  model_id,
 
10
  safety_checker=None
11
  )
12
 
13
  pipe = pipe.to("cpu")
14
 
15
- def generate(image, prompt):
16
- image = image.convert("RGB").resize((512, 512))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  result = pipe(
19
  prompt=prompt,
 
20
  image=image,
21
- strength=0.55,
22
- guidance_scale=7.5,
23
- num_inference_steps=25
24
  ).images[0]
25
 
26
  return result
27
 
28
 
29
- demo = gr.Interface(
30
- fn=generate,
31
- inputs=[
32
- gr.Image(type="pil", label="Upload Image"),
33
- gr.Textbox(
34
- label="Prompt",
35
- placeholder="Ω…Ψ«Ψ§Ω„: realistic architectural rendering, ultra high quality, cinematic lighting"
36
- )
37
- ],
38
- outputs=gr.Image(label="Result"),
39
- title="Mahmoud AI",
40
- description="High quality image-to-image enhancement (free CPU version)"
41
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  demo.launch()
 
 
 
1
  import torch
2
+ import gradio as gr
3
  from diffusers import StableDiffusionImg2ImgPipeline
4
+ from PIL import Image
5
 
6
+ # =========================
7
+ # Load model (CPU friendly)
8
+ # =========================
9
  model_id = "runwayml/stable-diffusion-v1-5"
10
 
11
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
12
  model_id,
13
+ torch_dtype=torch.float32,
14
  safety_checker=None
15
  )
16
 
17
  pipe = pipe.to("cpu")
18
 
19
+ # =========================
20
+ # Default Prompts (PRO)
21
+ # =========================
22
+ DEFAULT_PROMPT = (
23
+ "Ultra high-end photorealistic architectural visualization, "
24
+ "keep the exact same building structure, proportions, and facade, "
25
+ "modern luxury interior furniture visible through windows, "
26
+ "warm interior lighting turned on in all rooms, "
27
+ "realistic interior details behind glass, "
28
+ "dusk to night realistic lighting, "
29
+ "high-end real estate photography, "
30
+ "physically accurate lighting, "
31
+ "realistic glass reflections, "
32
+ "sharp edges, clean geometry, "
33
+ "cinematic but realistic, "
34
+ "no change to architecture"
35
+ )
36
+
37
+ NEGATIVE_PROMPT = (
38
+ "distorted architecture, warped geometry, melted building, "
39
+ "curved walls, broken symmetry, bad proportions, "
40
+ "cartoon, illustration, sketch, anime, "
41
+ "blurry, low quality, noisy, "
42
+ "overexposed windows, glowing mess, "
43
+ "fantasy lighting, unreal interior"
44
+ )
45
+
46
+ # =========================
47
+ # Image Generation Function
48
+ # =========================
49
+ def enhance_image(
50
+ input_image,
51
+ prompt,
52
+ strength,
53
+ guidance_scale,
54
+ steps
55
+ ):
56
+ if input_image is None:
57
+ return None
58
+
59
+ image = input_image.convert("RGB")
60
 
61
  result = pipe(
62
  prompt=prompt,
63
+ negative_prompt=NEGATIVE_PROMPT,
64
  image=image,
65
+ strength=strength,
66
+ guidance_scale=guidance_scale,
67
+ num_inference_steps=steps
68
  ).images[0]
69
 
70
  return result
71
 
72
 
73
+ # =========================
74
+ # Gradio UI
75
+ # =========================
76
+ with gr.Blocks(title="Mahmoud AI – Ultra Real Estate Enhancer") as demo:
77
+ gr.Markdown("""
78
+ # πŸ—οΈ Mahmoud AI – Architectural Image Enhancer
79
+ **Ultra-Realistic | Interior Lighting | Luxury Finish**
80
+ Upload ➜ Generate ➜ Download
81
+ """)
82
+
83
+ with gr.Row():
84
+ with gr.Column():
85
+ input_image = gr.Image(
86
+ label="Upload Image",
87
+ type="pil"
88
+ )
89
+
90
+ prompt = gr.Textbox(
91
+ label="Prompt",
92
+ value=DEFAULT_PROMPT,
93
+ lines=6
94
+ )
95
+
96
+ strength = gr.Slider(
97
+ label="Strength (Preserve Architecture)",
98
+ minimum=0.20,
99
+ maximum=0.40,
100
+ value=0.32,
101
+ step=0.01
102
+ )
103
+
104
+ guidance_scale = gr.Slider(
105
+ label="Guidance Scale (Quality)",
106
+ minimum=6,
107
+ maximum=10,
108
+ value=8.5,
109
+ step=0.1
110
+ )
111
+
112
+ steps = gr.Slider(
113
+ label="Steps (Detail Level)",
114
+ minimum=20,
115
+ maximum=50,
116
+ value=40,
117
+ step=1
118
+ )
119
+
120
+ generate_btn = gr.Button("πŸš€ Generate Ultra Quality")
121
+
122
+ with gr.Column():
123
+ output_image = gr.Image(
124
+ label="Result",
125
+ type="pil"
126
+ )
127
+
128
+ generate_btn.click(
129
+ fn=enhance_image,
130
+ inputs=[
131
+ input_image,
132
+ prompt,
133
+ strength,
134
+ guidance_scale,
135
+ steps
136
+ ],
137
+ outputs=output_image
138
+ )
139
 
140
  demo.launch()