import subprocess from PIL import Image import gradio as gr # First, running the inversion command to obtain the input noise that will reconstruct the image. # It will save the inversion as output/test_cat/inversion/image-name.pt # BLIP-generated caption prompt is saved as output/test_cat/prompt/image-name.txt - eg., a painting of a cat sitting on top of a ball def inversion(image_in, progress=gr.Progress(track_tqdm=True)): progress(0, desc="Starting...") # saving the input image image_in.save("input_image.png") # Run the script file subprocess.run(["python", "src/inversion.py", "--input_image", "input_image.png", "--results_folder", "output/test_cat"]) # Open the text file with blip caption with open("output/test_cat/prompt/input_image.txt", "r") as file: # Read the file prompt = file.read() return "output/test_cat/inversion/input_image.pt", prompt # Performing image editing with the editing directions # This will save the edited image as output/test_cat/edit/image-name.png def image_edit(task_name, progress=gr.Progress(track_tqdm=True)): progress(0, desc="Starting...") # Run the script file subprocess.run(["python", "src/edit_real.py", "--inversion", "output/test_cat/inversion/input_image.pt", "--prompt", "output/test_cat/prompt/input_image.txt", "--task_name", task_name, "--results_folder", "output/test_cat/"]) return "output/test_cat/edit/input_image.png" def set_visible_true(): return gr.update(visible=True) def set_visible_False(): return gr.update(visible=False) #Gradio Blocks API with gr.Blocks() as demo: gr.HTML("""
This is an unofficial demo for Pix2PixZero. Please visit their website and github repo for more details.