fix: image display
Browse files- .gitignore +6 -0
- app.py +20 -14
- requirements.txt +0 -2
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# env files
|
2 |
+
.env
|
3 |
+
.venv
|
4 |
+
|
5 |
+
# cache
|
6 |
+
*pycache*
|
app.py
CHANGED
@@ -6,7 +6,6 @@ import streamlit as st
|
|
6 |
import torch
|
7 |
import torch.nn.functional as F
|
8 |
from briarmbg import BriaRMBG
|
9 |
-
from gradio_imageslider import ImageSlider
|
10 |
from PIL import Image
|
11 |
from torchvision.transforms.functional import normalize
|
12 |
|
@@ -20,7 +19,7 @@ def resize_image(image):
|
|
20 |
|
21 |
def process(image):
|
22 |
# prepare input
|
23 |
-
orig_image = Image.
|
24 |
w, h = orig_image.size
|
25 |
image = resize_image(orig_image)
|
26 |
im_np = np.array(image)
|
@@ -58,28 +57,35 @@ def main():
|
|
58 |
unsafe_allow_html=True,
|
59 |
)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
cols = st.columns(2)
|
62 |
|
63 |
with cols[0]:
|
64 |
-
with st.container(border=True, height=
|
65 |
-
img_file = st.file_uploader(
|
66 |
-
label="Upload image",
|
67 |
-
type=["jpg", "png", "jpeg"],
|
68 |
-
key="image_file_uploader",
|
69 |
-
)
|
70 |
if img_file:
|
71 |
-
st.
|
|
|
|
|
72 |
sub_btn = st.button("Remove bg", key="sub_btn")
|
|
|
73 |
with cols[1]:
|
74 |
-
with st.container(border=True, height=
|
75 |
if sub_btn and img_file:
|
76 |
-
processed_img = process(img_file
|
77 |
-
st.
|
78 |
else:
|
79 |
st.write("Waiting for image...")
|
80 |
|
81 |
-
with st.container(border=True, height=
|
82 |
-
st.
|
|
|
83 |
|
84 |
|
85 |
if __name__ == "__main__":
|
|
|
6 |
import torch
|
7 |
import torch.nn.functional as F
|
8 |
from briarmbg import BriaRMBG
|
|
|
9 |
from PIL import Image
|
10 |
from torchvision.transforms.functional import normalize
|
11 |
|
|
|
19 |
|
20 |
def process(image):
|
21 |
# prepare input
|
22 |
+
orig_image = Image.open(image)
|
23 |
w, h = orig_image.size
|
24 |
image = resize_image(orig_image)
|
25 |
im_np = np.array(image)
|
|
|
57 |
unsafe_allow_html=True,
|
58 |
)
|
59 |
|
60 |
+
# sidebar
|
61 |
+
with st.sidebar:
|
62 |
+
img_file = st.file_uploader(
|
63 |
+
label="Upload image",
|
64 |
+
type=["jpg", "png", "jpeg"],
|
65 |
+
key="image_file_uploader",
|
66 |
+
)
|
67 |
+
|
68 |
cols = st.columns(2)
|
69 |
|
70 |
with cols[0]:
|
71 |
+
with st.container(border=True, height=600):
|
|
|
|
|
|
|
|
|
|
|
72 |
if img_file:
|
73 |
+
st.image(img_file)
|
74 |
+
else:
|
75 |
+
st.info("Drag and drop the sample image into upload sidebar", icon="💡")
|
76 |
sub_btn = st.button("Remove bg", key="sub_btn")
|
77 |
+
|
78 |
with cols[1]:
|
79 |
+
with st.container(border=True, height=600):
|
80 |
if sub_btn and img_file:
|
81 |
+
processed_img = process(img_file)
|
82 |
+
st.image(processed_img)
|
83 |
else:
|
84 |
st.write("Waiting for image...")
|
85 |
|
86 |
+
with st.container(border=True, height=400):
|
87 |
+
st.write("Sample image")
|
88 |
+
st.image("input.jpg")
|
89 |
|
90 |
|
91 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
gradio
|
2 |
-
gradio_imageslider
|
3 |
torch
|
4 |
torchvision
|
5 |
pillow
|
|
|
|
|
|
|
1 |
torch
|
2 |
torchvision
|
3 |
pillow
|