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