Spaces:
Runtime error
Runtime error
Commit Β·
1150a3a
1
Parent(s): 7f72add
fix: minor errors
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
### FINAL COMBINED
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
|
| 4 |
import os
|
|
@@ -17,7 +16,6 @@ import spaces
|
|
| 17 |
choker_images = [Image.open(os.path.join("choker", x)) for x in os.listdir("choker")]
|
| 18 |
person_images = [Image.open(os.path.join("without_necklace", x)) for x in os.listdir("without_necklace")]
|
| 19 |
|
| 20 |
-
# initialising the stable diffusion model
|
| 21 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
| 22 |
pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 23 |
model_id, torch_dtype=torch.float16
|
|
@@ -25,15 +23,13 @@ pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
|
| 25 |
pipeline = pipeline.to("cuda")
|
| 26 |
|
| 27 |
|
| 28 |
-
|
| 29 |
-
def clearFunc():
|
| 30 |
torch.cuda.empty_cache()
|
| 31 |
gc.collect()
|
| 32 |
|
| 33 |
|
| 34 |
-
# SD Model
|
| 35 |
@spaces.GPU
|
| 36 |
-
def
|
| 37 |
image = np.array(image)
|
| 38 |
copy_image = image.copy()
|
| 39 |
jewellery = np.array(jewellery)
|
|
@@ -154,12 +150,10 @@ def sd_inpaint(image, jewellery):
|
|
| 154 |
results = [
|
| 155 |
Image.fromarray(np.bitwise_or(x, np.array(jewellery_mask))) for x in results
|
| 156 |
]
|
| 157 |
-
|
| 158 |
return results[0]
|
| 159 |
|
| 160 |
|
| 161 |
-
# interface
|
| 162 |
-
|
| 163 |
with gr.Blocks() as interface:
|
| 164 |
with gr.Row():
|
| 165 |
inputImage = gr.Image(label="Input Image", type="pil", image_mode="RGB", interactive=True)
|
|
@@ -172,6 +166,6 @@ with gr.Blocks() as interface:
|
|
| 172 |
with gr.Row():
|
| 173 |
submit = gr.Button("Enter")
|
| 174 |
|
| 175 |
-
submit.click(fn=
|
| 176 |
|
| 177 |
interface.launch(debug=True)
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline
|
| 3 |
import os
|
|
|
|
| 16 |
choker_images = [Image.open(os.path.join("choker", x)) for x in os.listdir("choker")]
|
| 17 |
person_images = [Image.open(os.path.join("without_necklace", x)) for x in os.listdir("without_necklace")]
|
| 18 |
|
|
|
|
| 19 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
| 20 |
pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 21 |
model_id, torch_dtype=torch.float16
|
|
|
|
| 23 |
pipeline = pipeline.to("cuda")
|
| 24 |
|
| 25 |
|
| 26 |
+
def clear_func():
|
|
|
|
| 27 |
torch.cuda.empty_cache()
|
| 28 |
gc.collect()
|
| 29 |
|
| 30 |
|
|
|
|
| 31 |
@spaces.GPU
|
| 32 |
+
def clothing_try_on_n_necklace_try_on(image, jewellery):
|
| 33 |
image = np.array(image)
|
| 34 |
copy_image = image.copy()
|
| 35 |
jewellery = np.array(jewellery)
|
|
|
|
| 150 |
results = [
|
| 151 |
Image.fromarray(np.bitwise_or(x, np.array(jewellery_mask))) for x in results
|
| 152 |
]
|
| 153 |
+
clear_func()
|
| 154 |
return results[0]
|
| 155 |
|
| 156 |
|
|
|
|
|
|
|
| 157 |
with gr.Blocks() as interface:
|
| 158 |
with gr.Row():
|
| 159 |
inputImage = gr.Image(label="Input Image", type="pil", image_mode="RGB", interactive=True)
|
|
|
|
| 166 |
with gr.Row():
|
| 167 |
submit = gr.Button("Enter")
|
| 168 |
|
| 169 |
+
submit.click(fn=clothing_try_on_n_necklace_try_on, inputs=[inputImage, selectedNecklace], outputs=[outputOne])
|
| 170 |
|
| 171 |
interface.launch(debug=True)
|