updated code for bug while second pass
Browse files
app.py
CHANGED
@@ -38,12 +38,12 @@ be to the input. This pipeline requires a value of at least `1`. It's possible y
|
|
38 |
* Cropping the image so the face takes up a larger portion of the frame.
|
39 |
"""
|
40 |
|
41 |
-
def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name, prompt, history, progress=gr.Progress(track_tqdm=True)):
|
42 |
progress(0, desc="Starting...")
|
43 |
-
global counter
|
44 |
-
counter += 1
|
45 |
#if message == "revert": --to add revert functionality later
|
46 |
-
if
|
47 |
# Open the image
|
48 |
image_in = Image.open(img_name) #("edited_image.png") #(img_nm)
|
49 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
@@ -54,13 +54,14 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
|
|
54 |
seed = random.randint(0, 1000000)
|
55 |
img_name = f"edited_image_{seed}.png"
|
56 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
57 |
-
edited_image.save(img_name
|
|
|
58 |
history = history or []
|
59 |
#Resizing (or not) the image for better display and adding supportive sample text
|
60 |
add_text_list = ["There you go", "Enjoy your image!", "Nice work! Wonder what you gonna do next!", "Way to go!", "Does this work for you?", "Something like this?"]
|
61 |
response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">' # style="width: 200px; height: 200px;">'
|
62 |
history.append((prompt, response))
|
63 |
-
return history, history, edited_image, img_name
|
64 |
|
65 |
with gr.Blocks() as demo:
|
66 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions </h1></center>
|
@@ -83,8 +84,9 @@ with gr.Blocks() as demo:
|
|
83 |
in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
|
84 |
image_hid = gr.Image(visible=False,)
|
85 |
img_name_temp_out = gr.Textbox(visible=False)
|
|
|
86 |
chatbot = gr.Chatbot()
|
87 |
-
b1.click(chat,[image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name_temp_out, text_in, state_in], [chatbot, state_in, image_hid, img_name_temp_out]) #, queue=True)
|
88 |
gr.Markdown(help_text)
|
89 |
|
90 |
demo.queue(concurrency_count=10)
|
|
|
38 |
* Cropping the image so the face takes up a larger portion of the frame.
|
39 |
"""
|
40 |
|
41 |
+
def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name, counter_out, prompt, history, progress=gr.Progress(track_tqdm=True)):
|
42 |
progress(0, desc="Starting...")
|
43 |
+
#global counter
|
44 |
+
#counter += 1
|
45 |
#if message == "revert": --to add revert functionality later
|
46 |
+
if counter_out > 0:
|
47 |
# Open the image
|
48 |
image_in = Image.open(img_name) #("edited_image.png") #(img_nm)
|
49 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
|
|
54 |
seed = random.randint(0, 1000000)
|
55 |
img_name = f"edited_image_{seed}.png"
|
56 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
57 |
+
edited_image.save(img_name) #, overwrite=True) #("/tmp/edited_image.png") #(img_nm)
|
58 |
+
counter_out += 1
|
59 |
history = history or []
|
60 |
#Resizing (or not) the image for better display and adding supportive sample text
|
61 |
add_text_list = ["There you go", "Enjoy your image!", "Nice work! Wonder what you gonna do next!", "Way to go!", "Does this work for you?", "Something like this?"]
|
62 |
response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">' # style="width: 200px; height: 200px;">'
|
63 |
history.append((prompt, response))
|
64 |
+
return history, history, edited_image, img_name, counter_out
|
65 |
|
66 |
with gr.Blocks() as demo:
|
67 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions </h1></center>
|
|
|
84 |
in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
|
85 |
image_hid = gr.Image(visible=False,)
|
86 |
img_name_temp_out = gr.Textbox(visible=False)
|
87 |
+
counter_out = gr.Number(visible=False, value=0)
|
88 |
chatbot = gr.Chatbot()
|
89 |
+
b1.click(chat,[image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid, img_name_temp_out,counter_out, text_in, state_in], [chatbot, state_in, image_hid, img_name_temp_out, counter_out]) #, queue=True)
|
90 |
gr.Markdown(help_text)
|
91 |
|
92 |
demo.queue(concurrency_count=10)
|