add img2img
Browse files
app.py
CHANGED
|
@@ -5,8 +5,10 @@ import re
|
|
| 5 |
import gradio as gr
|
| 6 |
from diffusers import AutoPipelineForText2Image
|
| 7 |
import torch
|
| 8 |
-
|
|
|
|
| 9 |
pipeline_text2image = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
|
|
|
| 10 |
pipeline_text2image = pipeline_text2image.to("cuda")
|
| 11 |
|
| 12 |
|
|
@@ -14,6 +16,12 @@ def text2img(prompt = "A cinematic shot of a baby racoon wearing an intricate it
|
|
| 14 |
image = pipeline_text2image(prompt=prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
| 15 |
return image
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
gradio_app_text2img = gr.Interface(
|
| 18 |
fn=text2img,
|
| 19 |
inputs=[
|
|
@@ -24,8 +32,18 @@ gradio_app_text2img = gr.Interface(
|
|
| 24 |
outputs="image",
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
demo = gr.TabbedInterface([gradio_app_text2img], ["text2img"])
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
demo.launch()
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
from diffusers import AutoPipelineForText2Image
|
| 7 |
import torch
|
| 8 |
+
from diffusers import AutoPipelineForImage2Image
|
| 9 |
+
from diffusers.utils import load_image, make_image_grid
|
| 10 |
pipeline_text2image = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
| 11 |
+
pipeline_image2image = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cuda")
|
| 12 |
pipeline_text2image = pipeline_text2image.to("cuda")
|
| 13 |
|
| 14 |
|
|
|
|
| 16 |
image = pipeline_text2image(prompt=prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
| 17 |
return image
|
| 18 |
|
| 19 |
+
def img2img(image,prompt=prompt, guidance_scale=0.0, num_inference_steps=1,strength=0.5):
|
| 20 |
+
init_image = load_image(image)
|
| 21 |
+
init_image = init_image.resize((512, 512))
|
| 22 |
+
image = pipeline_image2image(prompt, image=init_image, strength=strength, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
| 23 |
+
return image
|
| 24 |
+
|
| 25 |
gradio_app_text2img = gr.Interface(
|
| 26 |
fn=text2img,
|
| 27 |
inputs=[
|
|
|
|
| 32 |
outputs="image",
|
| 33 |
)
|
| 34 |
|
| 35 |
+
gradio_app_img2img = gr.Interface(
|
| 36 |
+
fn=text2img,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.Image(type='filepath'),
|
| 39 |
+
gr.Text(),
|
| 40 |
+
gr.Slider(0.0, 10.0, value=1,step=0.1),
|
| 41 |
+
gr.Slider(0.0, 10.0, value=1,step=1)
|
| 42 |
+
],
|
| 43 |
+
outputs="image",
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
demo = gr.TabbedInterface([gradio_app_text2img,gradio_app_img2img], ["text2img","img2img"])
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
demo.launch()
|