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) # for angle in [90, 180, 270]: # rotated_image = input_image.rotate(angle) # rotated_image_path = os.path.join(images_folder, f"rotated_{angle}.png") # rotated_image.save(rotated_image_path) os.system("python run_google_lens.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="never", # Disable the flag button ) # Launch the app iface.launch()