Spaces:
Sleeping
Sleeping
aryrk commited on
Commit ·
fe4b148
1
Parent(s): 7d9b835
[feat] output validation
Browse files
app.py
CHANGED
|
@@ -28,7 +28,8 @@ def reflection_removal(input_image):
|
|
| 28 |
if not input_image.lower().endswith((".jpg", ".jpeg", ".png")):
|
| 29 |
return ["File is not supported (only .jpg, .jpeg, .png)."]
|
| 30 |
|
| 31 |
-
|
|
|
|
| 32 |
shutil.copy(input_image, file_path)
|
| 33 |
|
| 34 |
cmd = [
|
|
@@ -43,14 +44,18 @@ def reflection_removal(input_image):
|
|
| 43 |
]
|
| 44 |
subprocess.run(cmd, check=True)
|
| 45 |
|
|
|
|
|
|
|
| 46 |
for root, _, files in os.walk(RESULTS_DIR):
|
| 47 |
for file in files:
|
| 48 |
-
if file.endswith("_fake.png"):
|
| 49 |
result_path = os.path.join(root, file)
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def use_sample_image(sample_image_name):
|
| 56 |
sample_image_path = os.path.join(SAMPLE_DIR, sample_image_name)
|
|
|
|
| 28 |
if not input_image.lower().endswith((".jpg", ".jpeg", ".png")):
|
| 29 |
return ["File is not supported (only .jpg, .jpeg, .png)."]
|
| 30 |
|
| 31 |
+
input_file_name = os.path.basename(input_image)
|
| 32 |
+
file_path = os.path.join(UPLOAD_DIR, input_file_name)
|
| 33 |
shutil.copy(input_image, file_path)
|
| 34 |
|
| 35 |
cmd = [
|
|
|
|
| 44 |
]
|
| 45 |
subprocess.run(cmd, check=True)
|
| 46 |
|
| 47 |
+
output_images = []
|
| 48 |
+
|
| 49 |
for root, _, files in os.walk(RESULTS_DIR):
|
| 50 |
for file in files:
|
| 51 |
+
if file.startswith(input_file_name.split('.')[0]) and file.endswith("_fake.png"):
|
| 52 |
result_path = os.path.join(root, file)
|
| 53 |
+
output_images.append(Image.open(result_path))
|
| 54 |
+
|
| 55 |
+
if output_images:
|
| 56 |
+
return output_images
|
| 57 |
+
else:
|
| 58 |
+
return ["No results found."]
|
| 59 |
|
| 60 |
def use_sample_image(sample_image_name):
|
| 61 |
sample_image_path = os.path.join(SAMPLE_DIR, sample_image_name)
|