Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionXLImg2ImgPipeline
|
4 |
from diffusers.utils import load_image
|
5 |
-
|
6 |
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
7 |
"stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
8 |
)
|
@@ -13,11 +13,29 @@ def run_fn(img_url):
|
|
13 |
prompt = "a photo of an astronaut riding a horse on mars"
|
14 |
image = pipe(prompt, image=init_image).images
|
15 |
return image
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionXLImg2ImgPipeline
|
4 |
from diffusers.utils import load_image
|
5 |
+
'''
|
6 |
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
7 |
"stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
8 |
)
|
|
|
13 |
prompt = "a photo of an astronaut riding a horse on mars"
|
14 |
image = pipe(prompt, image=init_image).images
|
15 |
return image
|
16 |
+
|
17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
19 |
+
pipe = pipe.to(device)
|
20 |
+
'''
|
21 |
+
def resize(value,img):
|
22 |
+
img = Image.open(img)
|
23 |
+
img = img.resize((value,value))
|
24 |
+
return img
|
25 |
+
|
26 |
+
def infer(source_img, prompt, negative_prompt, guide, steps, seed, Strength):
|
27 |
+
source_img = load_image(source_img).convert("RGB")
|
28 |
+
|
29 |
+
generator = torch.Generator(device).manual_seed(seed)
|
30 |
+
source_image = resize(768, source_img)
|
31 |
+
source_image.save('source.png')
|
32 |
+
image = pipe(prompt, negative_prompt=negative_prompt, image=source_image, strength=Strength, guidance_scale=guide, num_inference_steps=steps).images[0]
|
33 |
+
return image
|
34 |
+
|
35 |
+
gr.Interface(fn=infer, inputs=[gr.Image(source="upload", type="filepath", label="Raw Image. Must Be .png"), gr.Textbox(label = 'Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'), gr.Textbox(label='What you Do Not want the AI to generate.'),
|
36 |
+
gr.Slider(2, 15, value = 7, label = 'Guidance Scale'),
|
37 |
+
gr.Slider(1, 25, value = 10, step = 1, label = 'Number of Iterations'),
|
38 |
+
gr.Slider(label = "Seed", minimum = 0, maximum = 987654321987654321, step = 1, randomize = True),
|
39 |
+
gr.Slider(label='Strength', minimum = 0, maximum = 1, step = .05, value = .5)],
|
40 |
+
outputs='image').launch()
|
41 |
|