xp3857 commited on
Commit
af10642
·
1 Parent(s): 70ff87d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -35
app.py CHANGED
@@ -11,6 +11,8 @@ import torchvision.transforms as transforms
11
  from PIL import Image
12
  import torch
13
  import dlib
 
 
14
  #os.system("pip install dlib")
15
  os.system('bash setup.sh')
16
 
@@ -130,11 +132,11 @@ def run_cmd(command):
130
  def run(image,Restoration_mode, Colorizaition_mode):
131
  if Restoration_mode == "BOPBTL":
132
 
133
- if os.path.isdir("Temp"):
134
- shutil.rmtree("Temp")
135
 
136
- os.makedirs("Temp")
137
- os.makedirs("Temp/input")
138
  print(type(image))
139
  h,w,c=image.shape
140
  max = 600
@@ -147,45 +149,21 @@ def run(image,Restoration_mode, Colorizaition_mode):
147
  else:
148
  dim = (w,h)
149
  pass
150
- '''
151
- if width is None:
152
- # calculate the ratio of the height and construct the
153
- # dimensions
154
- r = height / float(h)
155
- dim = (int(w * r), height)
156
-
157
- # otherwise, the height is None
158
- else:
159
- # calculate the ratio of the width and construct the
160
- # dimensions
161
- r = width / float(w)
162
- dim = (width, int(h * r))
163
- '''
164
-
165
-
166
 
167
-
168
-
169
- #if h > 800:
170
- #h1 = int(h/2)
171
- #w1 = int(w/2)
172
  image=cv2.resize(image, dsize=(dim), interpolation=cv2.INTER_LANCZOS4)
173
- #max_size=(800,800)
174
- #image=image.thumbnail(max_size)
175
- #image=np.array(image)
176
- #image=cv2.imread(image)
177
- cv2.imwrite("Temp/input/input_img.png", image)
178
 
179
  command = ("python run.py --input_folder "
180
- + "Temp/input"
181
  + " --output_folder "
182
- + "Temp"
183
  + " --GPU "
184
  + "-1"
185
  + " --with_scratch")
186
  run_cmd(command)
187
 
188
- result_restoration = Image.open("Temp/final_output/input_img.png")
189
  shutil.rmtree("Temp")
190
 
191
  elif Restoration_mode == "Pix2Pix":
@@ -202,8 +180,8 @@ with gr.Blocks() as app:
202
  gr.Column()
203
  with gr.Column():
204
  im = gr.Image(label="Input Image")
205
- rad1 = gr.Radio(["BOPBTL", "Pix2Pix"])
206
- rad2 = gr.Radio(["Deoldify", "Pix2Pix Resnet 9block","Pix2Pix Unet 256"])
207
 
208
  im_btn=gr.Button(label="Restore")
209
  out_im = gr.Image(label="Restored Image")
 
11
  from PIL import Image
12
  import torch
13
  import dlib
14
+ import uuid
15
+ uid=uuid.uuid4()
16
  #os.system("pip install dlib")
17
  os.system('bash setup.sh')
18
 
 
132
  def run(image,Restoration_mode, Colorizaition_mode):
133
  if Restoration_mode == "BOPBTL":
134
 
135
+ if os.path.isdir(f"Temp{uid}"):
136
+ shutil.rmtree(f"Temp{uid}")
137
 
138
+ os.makedirs(f"Temp{uid}")
139
+ os.makedirs(f"Temp{uid}/input")
140
  print(type(image))
141
  h,w,c=image.shape
142
  max = 600
 
149
  else:
150
  dim = (w,h)
151
  pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
 
 
 
 
 
153
  image=cv2.resize(image, dsize=(dim), interpolation=cv2.INTER_LANCZOS4)
154
+
155
+ cv2.imwrite(f"Temp{uid}/input/input_img.png", image)
 
 
 
156
 
157
  command = ("python run.py --input_folder "
158
+ + f"Temp{uid}/input"
159
  + " --output_folder "
160
+ + f"Temp{uid}"
161
  + " --GPU "
162
  + "-1"
163
  + " --with_scratch")
164
  run_cmd(command)
165
 
166
+ result_restoration = Image.open(f"Temp{uid}/final_output/input_img.png")
167
  shutil.rmtree("Temp")
168
 
169
  elif Restoration_mode == "Pix2Pix":
 
180
  gr.Column()
181
  with gr.Column():
182
  im = gr.Image(label="Input Image")
183
+ rad1 = gr.Radio(["BOPBTL", "Pix2Pix"], value="BOPBTL")
184
+ rad2 = gr.Radio(["Deoldify", "Pix2Pix Resnet 9block","Pix2Pix Unet 256"],value="Deoldify")
185
 
186
  im_btn=gr.Button(label="Restore")
187
  out_im = gr.Image(label="Restored Image")