Spaces:
Sleeping
Sleeping
amaye15
commited on
Commit
·
6aadfe2
1
Parent(s):
5ba7154
test
Browse files
app.py
CHANGED
@@ -35,6 +35,7 @@ iface = gr.Interface(
|
|
35 |
title="Image Processor",
|
36 |
description="Upload an image and download a folder with processed images.",
|
37 |
flagging_mode="auto", # Disable the flag button
|
|
|
38 |
)
|
39 |
|
40 |
# Launch the app
|
|
|
35 |
title="Image Processor",
|
36 |
description="Upload an image and download a folder with processed images.",
|
37 |
flagging_mode="auto", # Disable the flag button
|
38 |
+
theme="huggingface",
|
39 |
)
|
40 |
|
41 |
# Launch the app
|
tmp.txt
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Create a readme for the following code:
|
2 |
+
|
3 |
+
app.py
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import os
|
7 |
+
import shutil
|
8 |
+
|
9 |
+
|
10 |
+
def process_image(input_image):
|
11 |
+
# Step 1: Create or clear the 'images' folder
|
12 |
+
images_folder = "images"
|
13 |
+
if os.path.exists(images_folder):
|
14 |
+
shutil.rmtree(images_folder) # Remove the folder if it exists
|
15 |
+
os.makedirs(images_folder) # Create a new 'images' folder
|
16 |
+
|
17 |
+
# Step 2: Save the input image into the 'images' folder
|
18 |
+
input_image_path = os.path.join(images_folder, "input_image.png")
|
19 |
+
input_image.save(input_image_path)
|
20 |
+
|
21 |
+
# # Step 3: Perform some actions (placeholder)
|
22 |
+
os.system("python run_google_lens.py")
|
23 |
+
os.system("python run_clean_images.py")
|
24 |
+
|
25 |
+
# Step 4: Zip the 'images' folder
|
26 |
+
zip_filename = "images.zip"
|
27 |
+
shutil.make_archive("images", "zip", images_folder)
|
28 |
+
shutil.rmtree(images_folder)
|
29 |
+
|
30 |
+
# Step 5: Return the path to the ZIP file
|
31 |
+
return zip_filename
|
32 |
+
|
33 |
+
|
34 |
+
# Set up the Gradio interface using Interface instead of Blocks
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=process_image,
|
37 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
38 |
+
outputs=gr.File(label="Download Images Folder"),
|
39 |
+
title="Image Processor",
|
40 |
+
description="Upload an image and download a folder with processed images.",
|
41 |
+
allow_flagging="auto", # Disable the flag button
|
42 |
+
)
|
43 |
+
|
44 |
+
# Launch the app
|
45 |
+
iface.launch()
|
46 |
+
|
47 |
+
---
|
48 |
+
|
49 |
+
run_clean_images.py
|
50 |
+
|
51 |
+
import os
|
52 |
+
import logging
|
53 |
+
from cleanvision.imagelab import Imagelab
|
54 |
+
|
55 |
+
# Set up logging
|
56 |
+
logging.basicConfig(
|
57 |
+
level=logging.INFO,
|
58 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
59 |
+
)
|
60 |
+
|
61 |
+
|
62 |
+
def delete_images_with_issues(directory):
|
63 |
+
# Initialize Imagelab with the directory of images
|
64 |
+
imagelab = Imagelab(directory)
|
65 |
+
|
66 |
+
# Run the inspection to identify images with issues
|
67 |
+
issues = imagelab.find_issues()
|
68 |
+
issue_columns = imagelab.issues.filter(like="issue")
|
69 |
+
|
70 |
+
# Use where to replace rows that don't have any True value with NaN
|
71 |
+
filtered_df = imagelab.issues.where(issue_columns.any(axis=1))
|
72 |
+
|
73 |
+
# Drop the rows with NaN values (i.e., rows where no issue column was True)
|
74 |
+
filtered_df = filtered_df.dropna()
|
75 |
+
|
76 |
+
# Display the filtered DataFrame
|
77 |
+
filtered_df.index.to_list()
|
78 |
+
|
79 |
+
# Iterate over the issues and delete the corresponding images
|
80 |
+
for issue in filtered_df.index.to_list():
|
81 |
+
image_path = issue
|
82 |
+
try:
|
83 |
+
os.remove(image_path)
|
84 |
+
logging.info(f"Deleted: {image_path}")
|
85 |
+
except Exception as e:
|
86 |
+
logging.error(f"Error deleting {image_path}: {e}")
|
87 |
+
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
# path = "/Users/andrewmayes/Project/document-type-detection/data/non_object"
|
91 |
+
path = "/home/user/app/images/"
|
92 |
+
|
93 |
+
delete_images_with_issues(path)
|
94 |
+
|
95 |
+
---
|
96 |
+
|