update desc and safety checker
Browse files
app.py
CHANGED
@@ -10,14 +10,14 @@ from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDisc
|
|
10 |
|
11 |
#Loading from Diffusers Library
|
12 |
model_id = "timbrooks/instruct-pix2pix"
|
13 |
-
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16"
|
14 |
pipe.to("cuda")
|
15 |
pipe.enable_attention_slicing()
|
16 |
|
17 |
counter = 0
|
18 |
|
19 |
|
20 |
-
help_text = """ Note:
|
21 |
|
22 |
Some notes from the official [instruct-pix2pix](https://huggingface.co/spaces/timbrooks/instruct-pix2pix) Space by the authors
|
23 |
and from the official [Diffusers docs](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix) -
|
@@ -42,53 +42,38 @@ be to the input. This pipeline requires a value of at least `1`. It's possible y
|
|
42 |
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)):
|
43 |
progress(0, desc="Starting...")
|
44 |
#if message == "revert": --to add revert functionality later
|
45 |
-
print(f"counter:{counter_out}, prompt:{prompt}, img_name:{img_name}")
|
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_hid, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
50 |
if os.path.exists(img_name):
|
51 |
-
print("***Image exists and will be deleted***")
|
52 |
os.remove(img_name)
|
53 |
-
temp_img_name = img_name[:-4]+str(int(time.time()))+'.png'
|
54 |
-
print(f"temp_img_name is :{temp_img_name}")
|
55 |
# Create a file-like object
|
56 |
with open(temp_img_name, "wb") as fp:
|
57 |
# Save the image to the file-like object
|
58 |
edited_image.save(fp)
|
59 |
#Get the name of the saved image
|
60 |
saved_image_name = fp.name
|
61 |
-
print(f"SAVED IMAGE NAME : {saved_image_name}, TMP IMAGE NAME : {temp_img_name}")
|
62 |
#edited_image.save(temp_img_name) #, overwrite=True)
|
63 |
counter_out += 1
|
64 |
else:
|
65 |
-
print("FIRST PASS")
|
66 |
seed = random.randint(0, 1000000)
|
67 |
img_name = f"./edited_image_{seed}.png"
|
68 |
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]
|
69 |
if os.path.exists(img_name):
|
70 |
-
print("***First PASS:Image exists and will be deleted***")
|
71 |
os.remove(img_name)
|
72 |
with open(img_name, "wb") as fp:
|
73 |
# Save the image to the file-like object
|
74 |
edited_image.save(fp)
|
75 |
#Get the name of the saved image
|
76 |
saved_image_name2 = fp.name
|
77 |
-
print(f"SAVED IMAGE NAME : {saved_image_name2}, IMAGE NAME : {img_name}")
|
78 |
-
#edited_image.save(img_name) #, overwrite=True) #("/tmp/edited_image.png") #(img_nm)
|
79 |
-
#counter_out += 1
|
80 |
history = history or []
|
81 |
#Resizing (or not) the image for better display and adding supportive sample text
|
82 |
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?"]
|
83 |
if counter_out > 0:
|
84 |
-
|
85 |
-
print(f"You are in {counter_out} pass")
|
86 |
-
response = random.choice(add_text_list) + '<img src="/file=' + saved_image_name + '">' #temp_img_name
|
87 |
history.append((prompt, response))
|
88 |
return history, history, edited_image, temp_img_name, counter_out
|
89 |
else:
|
90 |
-
#response = edited_image
|
91 |
-
print(f"You are in {counter_out} pass or FIRST Pass")
|
92 |
response = random.choice(add_text_list) + '<img src="/file=' + saved_image_name2 + '">' #IMG_NAME
|
93 |
history.append((prompt, response))
|
94 |
counter_out += 1
|
@@ -100,6 +85,10 @@ with gr.Blocks() as demo:
|
|
100 |
<p>For faster inference without waiting in the queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
101 |
<a href="https://huggingface.co/spaces/ysharma/InstructPix2Pix_Chatbot?duplicate=true">
|
102 |
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
|
|
|
|
|
|
|
|
103 |
<p/>""")
|
104 |
with gr.Row():
|
105 |
with gr.Column():
|
|
|
10 |
|
11 |
#Loading from Diffusers Library
|
12 |
model_id = "timbrooks/instruct-pix2pix"
|
13 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16") #, safety_checker=None)
|
14 |
pipe.to("cuda")
|
15 |
pipe.enable_attention_slicing()
|
16 |
|
17 |
counter = 0
|
18 |
|
19 |
|
20 |
+
help_text = """ Note: Functionality to revert your changes to previous/original image can be released in future versions. For now only forward editing is available.
|
21 |
|
22 |
Some notes from the official [instruct-pix2pix](https://huggingface.co/spaces/timbrooks/instruct-pix2pix) Space by the authors
|
23 |
and from the official [Diffusers docs](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix) -
|
|
|
42 |
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)):
|
43 |
progress(0, desc="Starting...")
|
44 |
#if message == "revert": --to add revert functionality later
|
|
|
45 |
if counter_out > 0:
|
|
|
|
|
46 |
edited_image = pipe(prompt, image=image_hid, num_inference_steps=int(in_steps), guidance_scale=float(in_guidance_scale), image_guidance_scale=float(in_img_guidance_scale)).images[0]
|
47 |
if os.path.exists(img_name):
|
|
|
48 |
os.remove(img_name)
|
49 |
+
temp_img_name = img_name[:-4]+str(int(time.time()))+'.png'
|
|
|
50 |
# Create a file-like object
|
51 |
with open(temp_img_name, "wb") as fp:
|
52 |
# Save the image to the file-like object
|
53 |
edited_image.save(fp)
|
54 |
#Get the name of the saved image
|
55 |
saved_image_name = fp.name
|
|
|
56 |
#edited_image.save(temp_img_name) #, overwrite=True)
|
57 |
counter_out += 1
|
58 |
else:
|
|
|
59 |
seed = random.randint(0, 1000000)
|
60 |
img_name = f"./edited_image_{seed}.png"
|
61 |
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]
|
62 |
if os.path.exists(img_name):
|
|
|
63 |
os.remove(img_name)
|
64 |
with open(img_name, "wb") as fp:
|
65 |
# Save the image to the file-like object
|
66 |
edited_image.save(fp)
|
67 |
#Get the name of the saved image
|
68 |
saved_image_name2 = fp.name
|
|
|
|
|
|
|
69 |
history = history or []
|
70 |
#Resizing (or not) the image for better display and adding supportive sample text
|
71 |
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?"]
|
72 |
if counter_out > 0:
|
73 |
+
response = random.choice(add_text_list) + '<img src="/file=' + saved_image_name + '">'
|
|
|
|
|
74 |
history.append((prompt, response))
|
75 |
return history, history, edited_image, temp_img_name, counter_out
|
76 |
else:
|
|
|
|
|
77 |
response = random.choice(add_text_list) + '<img src="/file=' + saved_image_name2 + '">' #IMG_NAME
|
78 |
history.append((prompt, response))
|
79 |
counter_out += 1
|
|
|
85 |
<p>For faster inference without waiting in the queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
86 |
<a href="https://huggingface.co/spaces/ysharma/InstructPix2Pix_Chatbot?duplicate=true">
|
87 |
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
88 |
+
<b>Note: Please be advised that a safety checker has been implemented in this public space.
|
89 |
+
Any attempts to generate inappropriate or NSFW images will result in the display of a black screen
|
90 |
+
as a precautionary measure for the protection of all users. We appreciate your cooperation in
|
91 |
+
maintaining a safe and appropriate environment for all members of our community.</b>
|
92 |
<p/>""")
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|