aryrk commited on
Commit
220be7c
·
1 Parent(s): c55e3ef

[feat] make a preprocess an option

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -33,7 +33,7 @@ def clear_uploaded_images():
33
  if os.path.isfile(file_path):
34
  os.remove(file_path)
35
 
36
- def reflection_removal(input_image):
37
  if not input_image.lower().endswith((".jpg", ".jpeg", ".png")):
38
  return ["File is not supported (only .jpg, .jpeg, .png)."]
39
 
@@ -52,7 +52,7 @@ def reflection_removal(input_image):
52
  "--norm", "batch", "--epoch", "310",
53
  "--num_test", str(count_files(UPLOAD_DIR)),
54
  "--gpu_ids", "-1",
55
- "--preprocess", "scale_width_and_crop",
56
  ]
57
  subprocess.run(cmd, check=True)
58
 
@@ -80,16 +80,16 @@ sample_images = [
80
  if file.endswith((".jpg", ".jpeg", ".png"))
81
  ]
82
 
83
- iface = gr.Interface(
84
- fn=reflection_removal,
85
- inputs=[gr.Image(type="filepath", label="Upload Image (JPG/PNG)")],
86
- outputs=gr.Gallery(label="Results after Reflection Removal"),
87
- examples=[
88
- os.path.join("sample_images", img) for img in os.listdir("sample_images") if img.endswith((".jpg", ".jpeg", ".png"))
89
- ],
90
- title="Reflection Remover with Pix2Pix",
91
- description="Upload images to remove reflections using a Pix2Pix model. You can also try the sample images below."
92
- )
93
 
94
  if __name__ == "__main__":
95
- iface.launch()
 
33
  if os.path.isfile(file_path):
34
  os.remove(file_path)
35
 
36
+ def reflection_removal(input_image, preprocess_type="resize_and_crop"):
37
  if not input_image.lower().endswith((".jpg", ".jpeg", ".png")):
38
  return ["File is not supported (only .jpg, .jpeg, .png)."]
39
 
 
52
  "--norm", "batch", "--epoch", "310",
53
  "--num_test", str(count_files(UPLOAD_DIR)),
54
  "--gpu_ids", "-1",
55
+ "--preprocess", preprocess_type
56
  ]
57
  subprocess.run(cmd, check=True)
58
 
 
80
  if file.endswith((".jpg", ".jpeg", ".png"))
81
  ]
82
 
83
+ def gradio_interface():
84
+ preprocess_options = ["resize_and_crop", "crop", "scale_width", "scale_width_and_crop", "none"]
85
+ gr.Interface(
86
+ fn=reflection_removal,
87
+ inputs=[
88
+ gr.inputs.Image(type="file", label="Input Image"),
89
+ gr.inputs.Dropdown(preprocess_options, label="Preprocess Type")
90
+ ],
91
+ outputs=gr.outputs.Image(type="pil", label="Output Image")
92
+ ).launch()
93
 
94
  if __name__ == "__main__":
95
+ gradio_interface()