update layout
Browse files
app.py
CHANGED
@@ -6,14 +6,37 @@ import random
|
|
6 |
from PIL import Image
|
7 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
8 |
|
|
|
9 |
model_id = "timbrooks/instruct-pix2pix"
|
10 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", safety_checker=None)
|
11 |
pipe.to("cuda")
|
12 |
pipe.enable_attention_slicing()
|
13 |
|
14 |
-
#seed = random.randint(0, 1000000)
|
15 |
counter = 0
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def chat(image_in, message, history, progress=gr.Progress(track_tqdm=True)):
|
19 |
progress(0, desc="Starting...")
|
@@ -40,7 +63,7 @@ def chat(image_in, message, history, progress=gr.Progress(track_tqdm=True)):
|
|
40 |
return history, history
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
-
gr.
|
44 |
<p>For faster inference without waiting in the queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
45 |
<a href="https://huggingface.co/spaces/ysharma/InstructPix2Pix_Chatbot?duplicate=true">
|
46 |
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
|
|
6 |
from PIL import Image
|
7 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
8 |
|
9 |
+
#Loading from Diffusers Library
|
10 |
model_id = "timbrooks/instruct-pix2pix"
|
11 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", safety_checker=None)
|
12 |
pipe.to("cuda")
|
13 |
pipe.enable_attention_slicing()
|
14 |
|
|
|
15 |
counter = 0
|
16 |
+
|
17 |
+
image_guidance_scale (`float`, *optional*, defaults to 1.5):
|
18 |
+
|
19 |
+
help_text = """ Note: I will try to add the functionality to revert your changes to previous/original image in future versions of space. For now only forward editing is available.
|
20 |
+
|
21 |
+
From the official Space by the authors [instruct-pix2pix](https://huggingface.co/spaces/timbrooks/instruct-pix2pix)
|
22 |
+
and from official [Diffusers docs](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix) -
|
23 |
+
|
24 |
+
If you're not getting what you want, there may be a few reasons:
|
25 |
+
1. Is the image not changing enough? Your guidance_scale may be too low. It should be >1. Higher guidance scale encourages to generate images
|
26 |
+
that are closely linked to the text `prompt`, usually at the expense of lower image quality. This value dictates how similar the output should
|
27 |
+
be to the input. This pipeline requires a value of at least `1`. It's possible your edit requires larger changes from the original image.
|
28 |
+
|
29 |
+
2. Alternatively, you can toggle image_guidance_scale. Image guidance scale is to push the generated image towards the inital image. Image guidance
|
30 |
+
scale is enabled by setting `image_guidance_scale > 1`. Higher image guidance scale encourages to generate images that are closely
|
31 |
+
linked to the source image `image`, usually at the expense of lower image quality.
|
32 |
+
|
33 |
+
3. I have observed that rephrasing the instruction sometimes improves results (e.g., "turn him into a dog" vs. "make him a dog" vs. "as a dog").
|
34 |
+
|
35 |
+
4. Increasing the number of steps sometimes improves results.
|
36 |
+
|
37 |
+
5. Do faces look weird? The Stable Diffusion autoencoder has a hard time with faces that are small in the image. Try:
|
38 |
+
* Cropping the image so the face takes up a larger portion of the frame.
|
39 |
+
"""
|
40 |
|
41 |
def chat(image_in, message, history, progress=gr.Progress(track_tqdm=True)):
|
42 |
progress(0, desc="Starting...")
|
|
|
63 |
return history, history
|
64 |
|
65 |
with gr.Blocks() as demo:
|
66 |
+
gr.Markdown("""<h1><center> Chat Interface with InstructPix2Pix: Give Image Editing Instructions </h1></center>
|
67 |
<p>For faster inference without waiting in the queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
68 |
<a href="https://huggingface.co/spaces/ysharma/InstructPix2Pix_Chatbot?duplicate=true">
|
69 |
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|