update layout, bug fix for parallel usage
Browse files
app.py
CHANGED
|
@@ -37,25 +37,27 @@ be to the input. This pipeline requires a value of at least `1`. It's possible y
|
|
| 37 |
* Cropping the image so the face takes up a larger portion of the frame.
|
| 38 |
"""
|
| 39 |
|
| 40 |
-
def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, prompt, history, progress=gr.Progress(track_tqdm=True)):
|
| 41 |
-
progress(0, desc="Starting...")
|
| 42 |
global counter
|
| 43 |
counter += 1
|
| 44 |
#if message == "revert": --to add revert functionality later
|
| 45 |
if counter > 1:
|
| 46 |
# Open the image
|
| 47 |
-
image_in = Image.open("edited_image.png")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
history = history or []
|
| 52 |
-
#
|
| 53 |
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?"]
|
| 54 |
-
|
| 55 |
-
#response = random.choice(add_text_list) + '<img src="/file=edited_image.png" style="width: 350px; height: 350px;">'
|
| 56 |
-
response = random.choice(add_text_list) + '<img src="/file=edited_image.png">' # style="width: 350px; height: 350px;">'
|
| 57 |
history.append((prompt, response))
|
| 58 |
-
return history, history
|
| 59 |
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions </h1></center>
|
|
@@ -76,8 +78,10 @@ with gr.Blocks() as demo:
|
|
| 76 |
in_steps = gr.Number(label="Enter the number of Inference steps", value = 20)
|
| 77 |
in_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Guidance scale", value=7.5)
|
| 78 |
in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
|
|
|
|
|
|
|
| 79 |
chatbot = gr.Chatbot()
|
| 80 |
-
b1.click(chat,[image_in, in_steps, in_guidance_scale, in_img_guidance_scale, text_in, state_in], [chatbot, state_in]) #, queue=True)
|
| 81 |
gr.Markdown(help_text)
|
| 82 |
|
| 83 |
demo.queue(concurrency_count=10)
|
|
|
|
| 37 |
* Cropping the image so the face takes up a larger portion of the frame.
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
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)):
|
| 41 |
+
#progress(0, desc="Starting...")
|
| 42 |
global counter
|
| 43 |
counter += 1
|
| 44 |
#if message == "revert": --to add revert functionality later
|
| 45 |
if counter > 1:
|
| 46 |
# Open the image
|
| 47 |
+
image_in = Image.open(img_name) #("edited_image.png") #(img_nm)
|
| 48 |
+
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]
|
| 49 |
+
edited_image.save(img_name)
|
| 50 |
+
else:
|
| 51 |
+
seed = random.randint(0, 1000000)
|
| 52 |
+
img_name = f"edited_image_{seed}.png"
|
| 53 |
+
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 |
+
edited_image.save(img_name) #("/tmp/edited_image.png") #(img_nm)
|
| 55 |
history = history or []
|
| 56 |
+
#Resizing (or not) the image for better display and adding supportive sample text
|
| 57 |
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?"]
|
| 58 |
+
response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">' # style="width: 200px; height: 200px;">'
|
|
|
|
|
|
|
| 59 |
history.append((prompt, response))
|
| 60 |
+
return history, history, edited_image, img_name
|
| 61 |
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions </h1></center>
|
|
|
|
| 78 |
in_steps = gr.Number(label="Enter the number of Inference steps", value = 20)
|
| 79 |
in_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Guidance scale", value=7.5)
|
| 80 |
in_img_guidance_scale = gr.Slider(1,10, step=0.5, label="Set Image Guidance scale", value=1.5)
|
| 81 |
+
image_hid = gr.Image(visible=False,)
|
| 82 |
+
img_name_temp_out = gr.Textbox(visible=False)
|
| 83 |
chatbot = gr.Chatbot()
|
| 84 |
+
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)
|
| 85 |
gr.Markdown(help_text)
|
| 86 |
|
| 87 |
demo.queue(concurrency_count=10)
|