Google-Lens-6 / app.py
amaye15
App
bbcea60
import gradio as gr
import os
import shutil
custom_css = """
body, .gradio-container {
background-color: #2e2e2e;
color: #ffffff;
}
"""
# .gradio-container input,
# .gradio-container textarea,
# .gradio-container select,
# .gradio-container button {
# background-color: #3c3c3c;
# color: #ffffff;
# border-color: #555555;
# }
# .gradio-container .gr-button {
# background-color: #444444;
# color: #ffffff;
# border-color: #555555;
# }
# .gradio-container .gr-button:hover {
# background-color: #555555;
# }
# .gradio-container .gr-input,
# .gradio-container .gr-output {
# background-color: #3c3c3c;
# color: #ffffff;
# }
# .gradio-container .gr-text-input textarea {
# background-color: #3c3c3c;
# color: #ffffff;
# }
# .gradio-container .gr-slider input {
# background-color: #3c3c3c;
# }
# .gradio-container .gradio-card {
# background-color: #3c3c3c;
# color: #ffffff;
# }
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="Google Lens",
description="Upload an image and download a folder with processed images.",
flagging_mode="auto", # Disable the flag button
css=custom_css,
# theme="dark",
)
# Launch the app
# iface.queue(default_concurrency_limit=1, max_size=1).launch()
iface.launch()