dimentox commited on
Commit
aa2d466
1 Parent(s): e7fb5b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -34
app.py CHANGED
@@ -1,4 +1,27 @@
1
  from __future__ import annotations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import math
4
  import random
@@ -8,12 +31,9 @@ import torch
8
  from PIL import Image, ImageOps
9
  from diffusers import StableDiffusionPipeline
10
 
11
-
12
  help_text = """
13
-
14
  """
15
 
16
-
17
  example_instructions = [
18
  "A river"
19
  ]
@@ -23,15 +43,16 @@ model_id = "dimentox/heightmapstyle"
23
 
24
  def main():
25
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
26
- #example_image = Image.open("imgs/example.jpg").convert("RGB")
 
27
 
28
  def load_example(
29
- steps: int,
30
- randomize_seed: bool,
31
- seed: int,
32
- randomize_cfg: bool,
33
- text_cfg_scale: float,
34
- image_cfg_scale: float,
35
  ):
36
  example_instruction = random.choice(example_instructions)
37
  return [example_instruction] + generate(
@@ -45,27 +66,27 @@ def main():
45
  )
46
 
47
  def generate(
48
- instruction: str,
49
- steps: int,
50
- randomize_seed: bool,
51
- seed: int,
52
- randomize_cfg: bool,
53
- text_cfg_scale: float,
54
- image_cfg_scale: float,
55
  ):
56
  seed = random.randint(0, 100000) if randomize_seed else seed
57
  text_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scale
58
  image_cfg_scale = round(random.uniform(1.2, 1.8), ndigits=2) if randomize_cfg else image_cfg_scale
59
 
60
- width, height = input_image.size
61
- factor = 512 / max(width, height)
62
- factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height)
63
- width = int((width * factor) // 64) * 64
64
- height = int((height * factor) // 64) * 64
65
- input_image = ImageOps.fit(input_image, (width, height), method=Image.Resampling.LANCZOS)
66
 
67
  if instruction == "":
68
- return [input_image, seed]
69
 
70
  generator = torch.manual_seed(seed)
71
  edited_image = pipe(
@@ -80,7 +101,7 @@ def main():
80
 
81
  with gr.Blocks() as demo:
82
  gr.HTML("""
83
-
84
  """)
85
  with gr.Row():
86
  with gr.Column(scale=1, min_width=100):
@@ -92,7 +113,6 @@ def main():
92
  with gr.Column(scale=3):
93
  instruction = gr.Textbox(lines=1, label="Edit Instruction", interactive=True)
94
 
95
-
96
  with gr.Row():
97
  steps = gr.Number(value=50, precision=0, label="Steps", interactive=True)
98
  randomize_seed = gr.Radio(
@@ -125,7 +145,7 @@ def main():
125
  text_cfg_scale,
126
  image_cfg_scale,
127
  ],
128
- outputs=[ instruction, seed, text_cfg_scale, image_cfg_scale, edited_image],
129
  )
130
  generate_button.click(
131
  fn=generate,
@@ -154,12 +174,12 @@ def main():
154
  if __name__ == "__main__":
155
  main()
156
 
157
-
158
-
159
  import gradio as gr
 
160
  gr.Examples(
161
- [["heightmapsstyle", "a lake with a river"], ["heightmapsstyle","greyscale", "a river running though flat planes"]],
162
- [txt, txt_2],
163
- cache_examples=True,
164
- )
165
- gr.load().launch()
 
 
1
  from __future__ import annotations
2
+ import os
3
+ import zipfile
4
+ from os.path import basename
5
+
6
+ import numpy as np
7
+ from PIL import Image
8
+ import matplotlib
9
+
10
+ from pipeline import Model_GAN, noise
11
+
12
+ matplotlib.use('Agg')
13
+ from math import floor
14
+ from io import BytesIO
15
+ import base64
16
+ import tempfile
17
+
18
+ from keras.layers import Conv2D, LeakyReLU, BatchNormalization, Dense, AveragePooling2D, GaussianNoise
19
+ from keras.layers import Reshape, UpSampling2D, Activation, Dropout, Flatten, Conv2DTranspose
20
+ from keras.models import model_from_json, Sequential
21
+ from keras.optimizers import Adam
22
+
23
+ import cv2
24
+
25
 
26
  import math
27
  import random
 
31
  from PIL import Image, ImageOps
32
  from diffusers import StableDiffusionPipeline
33
 
 
34
  help_text = """
 
35
  """
36
 
 
37
  example_instructions = [
38
  "A river"
39
  ]
 
43
 
44
  def main():
45
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
46
+
47
+ # example_image = Image.open("imgs/example.jpg").convert("RGB")
48
 
49
  def load_example(
50
+ steps: int,
51
+ randomize_seed: bool,
52
+ seed: int,
53
+ randomize_cfg: bool,
54
+ text_cfg_scale: float,
55
+ image_cfg_scale: float,
56
  ):
57
  example_instruction = random.choice(example_instructions)
58
  return [example_instruction] + generate(
 
66
  )
67
 
68
  def generate(
69
+ instruction: str,
70
+ steps: int,
71
+ randomize_seed: bool,
72
+ seed: int,
73
+ randomize_cfg: bool,
74
+ text_cfg_scale: float,
75
+ image_cfg_scale: float,
76
  ):
77
  seed = random.randint(0, 100000) if randomize_seed else seed
78
  text_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scale
79
  image_cfg_scale = round(random.uniform(1.2, 1.8), ndigits=2) if randomize_cfg else image_cfg_scale
80
 
81
+ # width, height = input_image.size
82
+ # factor = 512 / max(width, height)
83
+ # factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height)
84
+ # width = int((width * factor) // 64) * 64
85
+ # height = int((height * factor) // 64) * 64
86
+ # input_image = ImageOps.fit(input_image, (width, height), method=Image.Resampling.LANCZOS)
87
 
88
  if instruction == "":
89
+ return [seed]
90
 
91
  generator = torch.manual_seed(seed)
92
  edited_image = pipe(
 
101
 
102
  with gr.Blocks() as demo:
103
  gr.HTML("""
104
+
105
  """)
106
  with gr.Row():
107
  with gr.Column(scale=1, min_width=100):
 
113
  with gr.Column(scale=3):
114
  instruction = gr.Textbox(lines=1, label="Edit Instruction", interactive=True)
115
 
 
116
  with gr.Row():
117
  steps = gr.Number(value=50, precision=0, label="Steps", interactive=True)
118
  randomize_seed = gr.Radio(
 
145
  text_cfg_scale,
146
  image_cfg_scale,
147
  ],
148
+ outputs=[instruction, seed, text_cfg_scale, image_cfg_scale, edited_image],
149
  )
150
  generate_button.click(
151
  fn=generate,
 
174
  if __name__ == "__main__":
175
  main()
176
 
 
 
177
  import gradio as gr
178
+
179
  gr.Examples(
180
+ [["heightmapsstyle", "a lake with a river"],
181
+ ["heightmapsstyle", "greyscale", "a river running though flat planes"]],
182
+ [txt, txt_2],
183
+ cache_examples=True,
184
+ )
185
+ gr.load().launch()