aryrk commited on
Commit
7ba731c
·
1 Parent(s): 95b14fb

[fix] add try attemp

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -39,9 +39,7 @@ def clear_session_files(session_id):
39
  shutil.rmtree(session_dir)
40
 
41
  def reflection_removal(input_image, preprocess_type="resize_and_crop"):
42
- if preprocess_type == "":
43
- preprocess_type = "resize_and_crop"
44
-
45
  session_id = generate_session_id()
46
  session_dir = os.path.join(UPLOAD_DIR, session_id)
47
  upload_dir = os.path.join(session_dir, "uploads")
@@ -67,7 +65,25 @@ def reflection_removal(input_image, preprocess_type="resize_and_crop"):
67
  "--gpu_ids", "-1",
68
  "--preprocess", preprocess_type
69
  ]
70
- subprocess.run(cmd, check=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  output_image = None
73
  for root, _, files in os.walk(RESULTS_DIR):
@@ -114,7 +130,6 @@ iface = gr.Interface(
114
  ],
115
  title="Reflection Remover with Pix2Pix",
116
  description="Upload images to remove reflections using a Pix2Pix model. You can also try the sample images below.",
117
- live=True
118
  )
119
 
120
  if __name__ == "__main__":
 
39
  shutil.rmtree(session_dir)
40
 
41
  def reflection_removal(input_image, preprocess_type="resize_and_crop"):
42
+
 
 
43
  session_id = generate_session_id()
44
  session_dir = os.path.join(UPLOAD_DIR, session_id)
45
  upload_dir = os.path.join(session_dir, "uploads")
 
65
  "--gpu_ids", "-1",
66
  "--preprocess", preprocess_type
67
  ]
68
+ attempt = 0
69
+ while True:
70
+ attempt += 1
71
+ try:
72
+ subprocess.run(cmd, check=True)
73
+ break
74
+ except subprocess.CalledProcessError as e:
75
+ cmd = [
76
+ "python", "test.py",
77
+ "--dataroot", upload_dir,
78
+ "--name", "SingleImageReflectionRemoval",
79
+ "--model", "test", "--netG", "unet_256",
80
+ "--direction", "AtoB", "--dataset_mode", "single",
81
+ "--norm", "batch", "--epoch", "310",
82
+ "--num_test", "1",
83
+ "--gpu_ids", "-1",
84
+ ]
85
+ if attempt > 2:
86
+ return "No results found. Please try again with a different image."
87
 
88
  output_image = None
89
  for root, _, files in os.walk(RESULTS_DIR):
 
130
  ],
131
  title="Reflection Remover with Pix2Pix",
132
  description="Upload images to remove reflections using a Pix2Pix model. You can also try the sample images below.",
 
133
  )
134
 
135
  if __name__ == "__main__":