xp3857 commited on
Commit
b786aa7
·
1 Parent(s): 085466f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -10,6 +10,7 @@ from skimage import color
10
  import torchvision.transforms as transforms
11
  from PIL import Image
12
  import torch
 
13
 
14
  os.system("pip install dlib")
15
  os.system('bash setup.sh')
@@ -124,32 +125,34 @@ def run_cmd(command):
124
  sys.exit(1)
125
 
126
  def run(image,Restoration_mode, Colorizaition_mode):
 
127
  Restoration_mode == "BOPBTL"
128
- if os.path.isdir("Temp"):
129
- shutil.rmtree("Temp")
130
 
131
- os.makedirs("Temp")
132
- os.makedirs("Temp/input")
133
  print(type(image))
134
- cv2.imwrite("Temp/input/input_img.png", image)
135
 
136
  command = ("python run.py --input_folder "
137
- + "Temp/input"
138
  + " --output_folder "
139
- + "Temp"
140
  + " --GPU "
141
  + "-1"
142
  + " --with_scratch")
143
  run_cmd(command)
144
 
145
- result_restoration = Image.open("Temp/final_output/input_img.png")
146
- shutil.rmtree("Temp")
147
 
148
  result_colorization = inferColorization(result_restoration)
149
 
150
  return result_colorization
151
  with gr.Blocks() as app:
152
- im = gr.Image(label="Input Image")
 
153
  im_btn=gr.Button(label="Restore")
154
  out_im = gr.Image(label="Restored Image")
155
  im_btn.click(run,im,out_im)
 
10
  import torchvision.transforms as transforms
11
  from PIL import Image
12
  import torch
13
+ import uuid
14
 
15
  os.system("pip install dlib")
16
  os.system('bash setup.sh')
 
125
  sys.exit(1)
126
 
127
  def run(image,Restoration_mode, Colorizaition_mode):
128
+ uid = uuid.uuid4()
129
  Restoration_mode == "BOPBTL"
130
+ if os.path.isdir(f"Temp{uid}"):
131
+ shutil.rmtree(f"Temp{uid}")
132
 
133
+ os.makedirs(f"Temp{uid}")
134
+ os.makedirs(f"Temp{uid}/input")
135
  print(type(image))
136
+ cv2.imwrite(f"Temp{uid}/input/input_img.png", image)
137
 
138
  command = ("python run.py --input_folder "
139
+ + f"Temp{uid}/input"
140
  + " --output_folder "
141
+ + f"Temp{uid}"
142
  + " --GPU "
143
  + "-1"
144
  + " --with_scratch")
145
  run_cmd(command)
146
 
147
+ result_restoration = Image.open(f"Temp{uid}/final_output/input_img.png")
148
+ shutil.rmtree(f"Temp{uid}")
149
 
150
  result_colorization = inferColorization(result_restoration)
151
 
152
  return result_colorization
153
  with gr.Blocks() as app:
154
+ #im = gr.Image(label="Input Image")
155
+ im = gr.Textbox()
156
  im_btn=gr.Button(label="Restore")
157
  out_im = gr.Image(label="Restored Image")
158
  im_btn.click(run,im,out_im)