Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,13 +13,16 @@ os.environ['CUDA_VISIBLE_DEVICES'] = ''
|
|
| 13 |
|
| 14 |
|
| 15 |
st.markdown("## Finder!")
|
| 16 |
-
st.markdown("### Get a segmentation mask by a text describtion or a reference image
|
| 17 |
st.markdown("DISCLAIMER: this is working much longer because of cpu :(")
|
| 18 |
st.markdown("<img width=200px src='https://rozetked.me/images/uploads/dwoilp3BVjlE.jpg'>", unsafe_allow_html=True)
|
| 19 |
# ^-- можно показывать пользователю текст, картинки, ограниченное подмножество html - всё как в jupyter
|
| 20 |
|
| 21 |
|
| 22 |
-
uploaded_file = st.file_uploader(
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
|
@@ -120,26 +123,26 @@ def get_top_mask(image_bytes, text=None, ref_image=None):
|
|
| 120 |
|
| 121 |
if uploaded_file is not None:
|
| 122 |
image_bytes = uploaded_file.getvalue()
|
| 123 |
-
option = st.selectbox('Find by?', ('Text', 'Image'))
|
| 124 |
to_show = Image.open(io.BytesIO(uploaded_file.getvalue()))
|
| 125 |
|
| 126 |
text = ""
|
| 127 |
ref_image_file = None
|
| 128 |
|
| 129 |
if option == 'Text':
|
| 130 |
-
text = st.text_input('
|
| 131 |
_, mask = get_top_mask(image_bytes, text=text)
|
| 132 |
elif option == 'Image':
|
| 133 |
-
ref_image_file = st.file_uploader("
|
| 134 |
if ref_image_file:
|
| 135 |
ref_image_bytes = ref_image_file.getvalue()
|
| 136 |
ref_image = Image.open(io.BytesIO(ref_image_bytes))
|
| 137 |
-
st.image(ref_image, caption='
|
| 138 |
_, mask = get_top_mask(image_bytes, ref_image=ref_image)
|
| 139 |
|
| 140 |
if (option == 'Text' and text != "") or (option=='Image' and (ref_image_file is not None)):
|
| 141 |
to_show = Image.fromarray(
|
| 142 |
np.clip(np.array([1, 0, 0]) * mask[:, :, None] * 100 + np.array(to_show, dtype=int), a_min = 0, a_max = 255).astype(np.uint8)
|
| 143 |
)
|
| 144 |
-
st.image(to_show, caption='
|
| 145 |
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
st.markdown("## Finder!")
|
| 16 |
+
st.markdown("### Get a segmentation mask by a text describtion or a reference image.")
|
| 17 |
st.markdown("DISCLAIMER: this is working much longer because of cpu :(")
|
| 18 |
st.markdown("<img width=200px src='https://rozetked.me/images/uploads/dwoilp3BVjlE.jpg'>", unsafe_allow_html=True)
|
| 19 |
# ^-- можно показывать пользователю текст, картинки, ограниченное подмножество html - всё как в jupyter
|
| 20 |
|
| 21 |
|
| 22 |
+
uploaded_file = st.file_uploader(
|
| 23 |
+
"Provide an image where you want to find something",
|
| 24 |
+
type=['png', 'jpg', 'jpeg']
|
| 25 |
+
)
|
| 26 |
|
| 27 |
|
| 28 |
|
|
|
|
| 123 |
|
| 124 |
if uploaded_file is not None:
|
| 125 |
image_bytes = uploaded_file.getvalue()
|
| 126 |
+
option = st.selectbox('Find a segmentation mask by what mode of reference?', ('Text', 'Image'))
|
| 127 |
to_show = Image.open(io.BytesIO(uploaded_file.getvalue()))
|
| 128 |
|
| 129 |
text = ""
|
| 130 |
ref_image_file = None
|
| 131 |
|
| 132 |
if option == 'Text':
|
| 133 |
+
text = st.text_input('Textual describtion of an object of interest')
|
| 134 |
_, mask = get_top_mask(image_bytes, text=text)
|
| 135 |
elif option == 'Image':
|
| 136 |
+
ref_image_file = st.file_uploader("Reference image of an object of interest", type=['png', 'jpg', 'jpeg'])
|
| 137 |
if ref_image_file:
|
| 138 |
ref_image_bytes = ref_image_file.getvalue()
|
| 139 |
ref_image = Image.open(io.BytesIO(ref_image_bytes))
|
| 140 |
+
st.image(ref_image, caption='Your reference image')
|
| 141 |
_, mask = get_top_mask(image_bytes, ref_image=ref_image)
|
| 142 |
|
| 143 |
if (option == 'Text' and text != "") or (option=='Image' and (ref_image_file is not None)):
|
| 144 |
to_show = Image.fromarray(
|
| 145 |
np.clip(np.array([1, 0, 0]) * mask[:, :, None] * 100 + np.array(to_show, dtype=int), a_min = 0, a_max = 255).astype(np.uint8)
|
| 146 |
)
|
| 147 |
+
st.image(to_show, caption='Input image with highlighted mask')
|
| 148 |
|