Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image
|
| 2 |
import torch
|
| 3 |
import torch.nn.functional as F
|
|
@@ -62,8 +67,16 @@ def example_inference(image):
|
|
| 62 |
|
| 63 |
|
| 64 |
original_image, binary_image = None, None
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
with gr.Blocks(
|
| 69 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.indigo)) as demo:
|
|
@@ -87,7 +100,18 @@ with gr.Blocks(
|
|
| 87 |
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
-
examples = gr.Examples(examples=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
with gr.Row():
|
| 93 |
submit = gr.Button("Submit")
|
|
@@ -96,7 +120,7 @@ with gr.Blocks(
|
|
| 96 |
|
| 97 |
def generate_img(image, background):
|
| 98 |
orig_img = example_inference(image)
|
| 99 |
-
|
| 100 |
|
| 101 |
background = Image.fromarray(background).resize((width, height))
|
| 102 |
orig_img = Image.fromarray(np.array(orig_img)).resize((width, height))
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Created By: ishwor subedi
|
| 3 |
+
Date: 2024-05-19
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
from PIL import Image
|
| 7 |
import torch
|
| 8 |
import torch.nn.functional as F
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
original_image, binary_image = None, None
|
| 70 |
+
colors = [Image.open(path) for path in
|
| 71 |
+
[os.path.join("bg_images/color", file) for file in os.listdir("bg_images/color")]]
|
| 72 |
+
houses = [Image.open(path) for path in
|
| 73 |
+
[os.path.join("bg_images/house", file) for file in os.listdir("bg_images/house")]]
|
| 74 |
+
natures = [Image.open(path) for path in
|
| 75 |
+
[os.path.join("bg_images/nature", file) for file in os.listdir("bg_images/nature")]]
|
| 76 |
+
studios = [Image.open(path) for path in
|
| 77 |
+
[os.path.join("bg_images/studio", file) for file in os.listdir("bg_images/studio")]]
|
| 78 |
+
walls = [Image.open(path) for path in [os.path.join("bg_images/wall", file) for file in os.listdir("bg_images/wall")]]
|
| 79 |
+
woods = [Image.open(path) for path in [os.path.join("bg_images/wood", file) for file in os.listdir("bg_images/wood")]]
|
| 80 |
|
| 81 |
with gr.Blocks(
|
| 82 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.indigo)) as demo:
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
with gr.Row():
|
| 103 |
+
examples = gr.Examples(examples=studios, inputs=[hidden_img], label="Studio Backgrounds")
|
| 104 |
+
|
| 105 |
+
with gr.Row():
|
| 106 |
+
examples6 = gr.Examples(examples=colors, inputs=[hidden_img], label="Color Backgrounds")
|
| 107 |
+
|
| 108 |
+
with gr.Row():
|
| 109 |
+
examples2 = gr.Examples(examples=walls, inputs=[hidden_img], label="Wall Backgrounds")
|
| 110 |
+
examples3 = gr.Examples(examples=natures, inputs=[hidden_img], label="Nature Backgrounds")
|
| 111 |
+
|
| 112 |
+
with gr.Row():
|
| 113 |
+
examples4 = gr.Examples(examples=houses, inputs=[hidden_img], label="House Backgrounds")
|
| 114 |
+
examples5 = gr.Examples(examples=woods, inputs=[hidden_img], label="Wood Backgrounds")
|
| 115 |
|
| 116 |
with gr.Row():
|
| 117 |
submit = gr.Button("Submit")
|
|
|
|
| 120 |
|
| 121 |
def generate_img(image, background):
|
| 122 |
orig_img = example_inference(image)
|
| 123 |
+
width, height = orig_img.size
|
| 124 |
|
| 125 |
background = Image.fromarray(background).resize((width, height))
|
| 126 |
orig_img = Image.fromarray(np.array(orig_img)).resize((width, height))
|