update temp file problem
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import torch
|
|
5 |
import gradio as gr
|
6 |
import random
|
7 |
from PIL import Image
|
8 |
-
|
9 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
10 |
|
11 |
model_id = "timbrooks/instruct-pix2pix"
|
@@ -13,30 +12,28 @@ pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dt
|
|
13 |
pipe.to("cuda")
|
14 |
pipe.enable_attention_slicing()
|
15 |
|
16 |
-
|
17 |
-
#image = PIL.ImageOps.exif_transpose(image)
|
18 |
-
#image = image.convert("RGB")
|
19 |
-
#image
|
20 |
-
#prompt = "turn him into cyborg"
|
21 |
-
#pipe(prompt, image=image, num_inference_steps=20, image_guidance_scale=1).images[0]
|
22 |
-
|
23 |
counter = 0
|
24 |
|
25 |
def chat(image_in, message, history): #, progress=gr.Progress(track_tqdm=True)):
|
26 |
#progress(0, desc="Starting...")
|
27 |
global counter
|
|
|
|
|
28 |
counter += 1
|
|
|
29 |
#if message == "revert": --to add revert functionality later
|
30 |
if counter > 1:
|
31 |
# Open the image
|
32 |
-
image_in = Image.open("./edited_image.png")
|
33 |
prompt = message #eg - "turn him into cyborg"
|
34 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=20, image_guidance_scale=1).images[0]
|
35 |
-
edited_image.save("edited_image.png") #("./edited_image.png")
|
36 |
history = history or []
|
37 |
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? "]
|
38 |
#Resizing the image for better display
|
39 |
-
response =
|
|
|
40 |
history.append((message, response))
|
41 |
return history, history
|
42 |
|
|
|
5 |
import gradio as gr
|
6 |
import random
|
7 |
from PIL import Image
|
|
|
8 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
9 |
|
10 |
model_id = "timbrooks/instruct-pix2pix"
|
|
|
12 |
pipe.to("cuda")
|
13 |
pipe.enable_attention_slicing()
|
14 |
|
15 |
+
seed = random.randint(0, 1000000)
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
counter = 0
|
17 |
|
18 |
def chat(image_in, message, history): #, progress=gr.Progress(track_tqdm=True)):
|
19 |
#progress(0, desc="Starting...")
|
20 |
global counter
|
21 |
+
global seed
|
22 |
+
img_nm = f"./edited_image_{seed}.png"
|
23 |
counter += 1
|
24 |
+
|
25 |
#if message == "revert": --to add revert functionality later
|
26 |
if counter > 1:
|
27 |
# Open the image
|
28 |
+
image_in = Image.open(img_nm) #("./edited_image.png")
|
29 |
prompt = message #eg - "turn him into cyborg"
|
30 |
edited_image = pipe(prompt, image=image_in, num_inference_steps=20, image_guidance_scale=1).images[0]
|
31 |
+
edited_image.save(img_nm) #("edited_image.png") #("./edited_image.png")
|
32 |
history = history or []
|
33 |
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? "]
|
34 |
#Resizing the image for better display
|
35 |
+
response = random.choice(add_text_list) + '<img src="/file=' + img_nm[2:] + '" style="width: 200px; height: 200px;">'
|
36 |
+
#response = random.choice(add_text_list) + '<img src="/file=edited_image.png" style="width: 200px; height: 200px;">'
|
37 |
history.append((message, response))
|
38 |
return history, history
|
39 |
|