Spaces:
Paused
Paused
upate random seed
Browse files
app.py
CHANGED
@@ -11,36 +11,41 @@ def inversion(image_in): #, progress=gr.Progress(track_tqdm=True)):
|
|
11 |
#progress(0, desc="Starting...")
|
12 |
seed = random.randint(0, 1000000)
|
13 |
img_name = f"./input_image_{seed}.png"
|
|
|
14 |
# saving the input image
|
15 |
image_in.save(img_name)
|
16 |
#image_in.save("input_image.png") #("assets/test_images/cats/input_image.png")
|
17 |
# Run the script file
|
18 |
subprocess.run(["python", "src/inversion.py", "--input_image", "input_image.png", "--results_folder", "output/test_cat"])
|
19 |
# Open the text file with blip caption
|
20 |
-
with open("output/test_cat/prompt/
|
21 |
# Read the file
|
22 |
prompt = file.read()
|
23 |
-
return "output/test_cat/inversion/
|
24 |
|
25 |
|
26 |
# Performing image editing with the editing directions
|
27 |
# This will save the edited image as output/test_cat/edit/image-name.png
|
28 |
-
def image_edit(task_name): #, progress=gr.Progress(track_tqdm=True)):
|
29 |
#progress(0, desc="Starting...")
|
|
|
30 |
# Run the script file
|
31 |
-
subprocess.run(["python", "src/edit_real.py", "--inversion", "output/test_cat/inversion/
|
32 |
-
"--prompt", "output/test_cat/prompt/
|
33 |
"--results_folder", "output/test_cat/"])
|
34 |
-
return "output/test_cat/edit/
|
35 |
|
36 |
|
37 |
#Similarly, we can edit the synthetic images generated by Stable Diffusion with the following command.
|
38 |
def synthetic_image_edit(prompt, task_name): #, progress=gr.Progress(track_tqdm=True)):
|
39 |
#progress(0, desc="Starting...")
|
|
|
|
|
|
|
40 |
# Run the script file
|
41 |
subprocess.run(["python", "src/edit_synthetic.py", "--prompt_str", prompt,
|
42 |
"--task", task_name, "--results_folder", "output/synth_editing"])
|
43 |
-
return "output/synth_editing/reconstruction.png", "output/synth_editing/edit.png"
|
44 |
|
45 |
|
46 |
def set_visible_true():
|
@@ -74,6 +79,7 @@ with gr.Blocks() as demo:
|
|
74 |
refresh_direction_html = gr.HTML(value="<h4>👆Click the 'App' button to Refresh the space and try translation again with another Image</h4>", visible=False)
|
75 |
with gr.Row():
|
76 |
image_in = gr.Image(type="pil", label="Start by uploading an image of a Cat or a Dog that you want to translate")
|
|
|
77 |
#with gr.Box():
|
78 |
# gr.Examples( examples=[os.path.join(os.path.dirname(__file__), "dog11.jpg"), os.path.join(os.path.dirname(__file__), "cat11.jpg")],
|
79 |
# inputs=image_in,)
|
@@ -100,7 +106,7 @@ with gr.Blocks() as demo:
|
|
100 |
|
101 |
image_in.change(set_visible_False, [], direction_html)
|
102 |
|
103 |
-
btn_inversion.click(inversion,[image_in],[inversion_file, blip_prompt])
|
104 |
#btn_inversion.click(set_visible_true, [], task_name_radio) #inversion_file, blip_prompt,
|
105 |
btn_inversion.click(set_visible_False, [], btn_inversion)
|
106 |
|
@@ -111,7 +117,7 @@ with gr.Blocks() as demo:
|
|
111 |
task_name_radio.change(set_visible_true, [], image_out)
|
112 |
#task_name_radio.change(set_visible_true, [], html_tag)
|
113 |
|
114 |
-
btn_imageedit.click(image_edit,[task_name_radio],[image_out])
|
115 |
btn_imageedit.click(set_visible_False, [], btn_imageedit)
|
116 |
|
117 |
btn_imageedit.click(set_visible_true, [], html_tag)
|
|
|
11 |
#progress(0, desc="Starting...")
|
12 |
seed = random.randint(0, 1000000)
|
13 |
img_name = f"./input_image_{seed}.png"
|
14 |
+
img_label = f"./input_image_{seed}"
|
15 |
# saving the input image
|
16 |
image_in.save(img_name)
|
17 |
#image_in.save("input_image.png") #("assets/test_images/cats/input_image.png")
|
18 |
# Run the script file
|
19 |
subprocess.run(["python", "src/inversion.py", "--input_image", "input_image.png", "--results_folder", "output/test_cat"])
|
20 |
# Open the text file with blip caption
|
21 |
+
with open(f"output/test_cat/prompt/{img_label}.txt", "r") as file:
|
22 |
# Read the file
|
23 |
prompt = file.read()
|
24 |
+
return f"output/test_cat/inversion/{img_label}.pt", prompt, seed
|
25 |
|
26 |
|
27 |
# Performing image editing with the editing directions
|
28 |
# This will save the edited image as output/test_cat/edit/image-name.png
|
29 |
+
def image_edit(task_name, seed): #, progress=gr.Progress(track_tqdm=True)):
|
30 |
#progress(0, desc="Starting...")
|
31 |
+
img_label = f"./input_image_{seed}"
|
32 |
# Run the script file
|
33 |
+
subprocess.run(["python", "src/edit_real.py", "--inversion", f"output/test_cat/inversion/{img_label}.pt",
|
34 |
+
"--prompt", f"output/test_cat/prompt/{img_label}.txt", "--task_name", task_name,
|
35 |
"--results_folder", "output/test_cat/"])
|
36 |
+
return f"output/test_cat/edit/{img_label}.png"
|
37 |
|
38 |
|
39 |
#Similarly, we can edit the synthetic images generated by Stable Diffusion with the following command.
|
40 |
def synthetic_image_edit(prompt, task_name): #, progress=gr.Progress(track_tqdm=True)):
|
41 |
#progress(0, desc="Starting...")
|
42 |
+
seed = random.randint(0, 1000000)
|
43 |
+
#img_name = f"./input_image_{seed}.png"
|
44 |
+
#img_label = f"./input_image_{seed}"
|
45 |
# Run the script file
|
46 |
subprocess.run(["python", "src/edit_synthetic.py", "--prompt_str", prompt,
|
47 |
"--task", task_name, "--results_folder", "output/synth_editing"])
|
48 |
+
return f"output/synth_editing/reconstruction{seed}.png", f"output/synth_editing/edit{seed}.png"
|
49 |
|
50 |
|
51 |
def set_visible_true():
|
|
|
79 |
refresh_direction_html = gr.HTML(value="<h4>👆Click the 'App' button to Refresh the space and try translation again with another Image</h4>", visible=False)
|
80 |
with gr.Row():
|
81 |
image_in = gr.Image(type="pil", label="Start by uploading an image of a Cat or a Dog that you want to translate")
|
82 |
+
seed = gr.Number(visible=False, Precision=0)
|
83 |
#with gr.Box():
|
84 |
# gr.Examples( examples=[os.path.join(os.path.dirname(__file__), "dog11.jpg"), os.path.join(os.path.dirname(__file__), "cat11.jpg")],
|
85 |
# inputs=image_in,)
|
|
|
106 |
|
107 |
image_in.change(set_visible_False, [], direction_html)
|
108 |
|
109 |
+
btn_inversion.click(inversion,[image_in],[inversion_file, blip_prompt, seed])
|
110 |
#btn_inversion.click(set_visible_true, [], task_name_radio) #inversion_file, blip_prompt,
|
111 |
btn_inversion.click(set_visible_False, [], btn_inversion)
|
112 |
|
|
|
117 |
task_name_radio.change(set_visible_true, [], image_out)
|
118 |
#task_name_radio.change(set_visible_true, [], html_tag)
|
119 |
|
120 |
+
btn_imageedit.click(image_edit,[task_name_radio, seed],[image_out])
|
121 |
btn_imageedit.click(set_visible_False, [], btn_imageedit)
|
122 |
|
123 |
btn_imageedit.click(set_visible_true, [], html_tag)
|