update image save step
Browse files
app.py
CHANGED
|
@@ -51,7 +51,11 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
|
|
| 51 |
os.remove(img_name)
|
| 52 |
temp_img_name = img_name
|
| 53 |
print(f"temp_img_name is :{temp_img_name}")
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
counter_out += 1
|
| 56 |
else:
|
| 57 |
print("FIRST PASS")
|
|
@@ -61,20 +65,26 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
|
|
| 61 |
if os.path.exists(img_name):
|
| 62 |
print("***First PASS:Image exists and will be deleted***")
|
| 63 |
os.remove(img_name)
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
#counter_out += 1
|
| 66 |
history = history or []
|
| 67 |
#Resizing (or not) the image for better display and adding supportive sample text
|
| 68 |
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?"]
|
| 69 |
if counter_out > 0:
|
|
|
|
| 70 |
response = random.choice(add_text_list) + '<img src="/file=' + temp_img_name + '">'
|
| 71 |
history.append((prompt, response))
|
| 72 |
return history, history, edited_image, temp_img_name, counter_out
|
| 73 |
else:
|
|
|
|
| 74 |
response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">'
|
| 75 |
history.append((prompt, response))
|
| 76 |
counter_out += 1
|
| 77 |
return history, history, edited_image, img_name, counter_out
|
|
|
|
| 78 |
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions [Apologies for inconvenience, this Space is still very much a work in progress...] </h1></center>
|
|
|
|
| 51 |
os.remove(img_name)
|
| 52 |
temp_img_name = img_name
|
| 53 |
print(f"temp_img_name is :{temp_img_name}")
|
| 54 |
+
# Create a file-like object
|
| 55 |
+
with open(temp_img_name, "wb") as fp:
|
| 56 |
+
# Save the image to the file-like object
|
| 57 |
+
edited_image.save(fp)
|
| 58 |
+
#edited_image.save(temp_img_name) #, overwrite=True)
|
| 59 |
counter_out += 1
|
| 60 |
else:
|
| 61 |
print("FIRST PASS")
|
|
|
|
| 65 |
if os.path.exists(img_name):
|
| 66 |
print("***First PASS:Image exists and will be deleted***")
|
| 67 |
os.remove(img_name)
|
| 68 |
+
with open(img_name, "wb") as fp:
|
| 69 |
+
# Save the image to the file-like object
|
| 70 |
+
edited_image.save(fp)
|
| 71 |
+
#edited_image.save(img_name) #, overwrite=True) #("/tmp/edited_image.png") #(img_nm)
|
| 72 |
#counter_out += 1
|
| 73 |
history = history or []
|
| 74 |
#Resizing (or not) the image for better display and adding supportive sample text
|
| 75 |
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?"]
|
| 76 |
if counter_out > 0:
|
| 77 |
+
#response = edited_image
|
| 78 |
response = random.choice(add_text_list) + '<img src="/file=' + temp_img_name + '">'
|
| 79 |
history.append((prompt, response))
|
| 80 |
return history, history, edited_image, temp_img_name, counter_out
|
| 81 |
else:
|
| 82 |
+
#response = edited_image
|
| 83 |
response = random.choice(add_text_list) + '<img src="/file=' + img_name + '">'
|
| 84 |
history.append((prompt, response))
|
| 85 |
counter_out += 1
|
| 86 |
return history, history, edited_image, img_name, counter_out
|
| 87 |
+
|
| 88 |
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions [Apologies for inconvenience, this Space is still very much a work in progress...] </h1></center>
|