Spaces:
Running
Running
Vivien
commited on
Commit
·
6392199
1
Parent(s):
685c1fb
Improve presentation
Browse files
app.py
CHANGED
|
@@ -194,11 +194,11 @@ def draw_reshape_encode(img, boxes, x, y):
|
|
| 194 |
def get_html(url_list, encoded_images):
|
| 195 |
html = "<div style='margin-top: 20px; max-width: 1200px; display: flex; flex-wrap: wrap; justify-content: space-evenly'>"
|
| 196 |
for i in range(len(url_list)):
|
| 197 |
-
title,
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
html += "</div>"
|
| 203 |
return html
|
| 204 |
|
|
@@ -206,13 +206,13 @@ def get_html(url_list, encoded_images):
|
|
| 206 |
description = """
|
| 207 |
# Search and Detect
|
| 208 |
|
| 209 |
-
This demo illustrates how
|
| 210 |
|
| 211 |
**Enter your query and hit enter**
|
| 212 |
|
| 213 |
**Tip 1**: if your query includes "/", the part left (resp. right) of "/" will be used to retrieve images (resp. locate objects). For example, if you want to retrieve pictures with several cats but locate individual cats, you can type "cats / cat".
|
| 214 |
|
| 215 |
-
**Tip 2**: change the score threshold
|
| 216 |
|
| 217 |
*Built with OpenAI's [CLIP](https://openai.com/blog/clip/) model and Google's [OWL-ViT](https://arxiv.org/abs/2205.06230) model, 🤗 Hugging Face's [transformers library](https://huggingface.co/transformers/), [Streamlit](https://streamlit.io/), 25k images from [Unsplash](https://unsplash.com/) and 8k images from [The Movie Database (TMDB)](https://www.themoviedb.org/)*
|
| 218 |
|
|
@@ -232,7 +232,7 @@ def main():
|
|
| 232 |
.block-container{
|
| 233 |
max-width: 1200px;
|
| 234 |
}
|
| 235 |
-
div.row-widget
|
| 236 |
flex-direction:row;
|
| 237 |
display: flex;
|
| 238 |
justify-content: center;
|
|
@@ -253,20 +253,17 @@ def main():
|
|
| 253 |
#MainMenu {
|
| 254 |
visibility: hidden;
|
| 255 |
}
|
| 256 |
-
footer {
|
| 257 |
-
visibility: hidden;
|
| 258 |
-
}
|
| 259 |
</style>""",
|
| 260 |
unsafe_allow_html=True,
|
| 261 |
)
|
| 262 |
st.sidebar.markdown(description)
|
| 263 |
-
score_threshold = st.sidebar.slider(
|
| 264 |
-
"Score threshold", min_value=0.01, max_value=0.3, value=0.1, step=0.01
|
| 265 |
-
)
|
| 266 |
|
| 267 |
_, c, _ = st.columns((1, 3, 1))
|
| 268 |
query = c.text_input("", value="koala")
|
| 269 |
-
corpus =
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
if len(query) > 0:
|
| 272 |
if "/" in query:
|
|
|
|
| 194 |
def get_html(url_list, encoded_images):
|
| 195 |
html = "<div style='margin-top: 20px; max-width: 1200px; display: flex; flex-wrap: wrap; justify-content: space-evenly'>"
|
| 196 |
for i in range(len(url_list)):
|
| 197 |
+
title, encoded = url_list[i][1], encoded_images[i]
|
| 198 |
+
html = (
|
| 199 |
+
html
|
| 200 |
+
+ f"<img title='{escape(title)}' style='height: {HEIGHT}px; margin: 5px' src='data:image/jpeg;base64,{encoded.decode()}'>"
|
| 201 |
+
)
|
| 202 |
html += "</div>"
|
| 203 |
return html
|
| 204 |
|
|
|
|
| 206 |
description = """
|
| 207 |
# Search and Detect
|
| 208 |
|
| 209 |
+
This demo illustrates how to both retrieve images containing certain objects and locate these objects with a simple text query.
|
| 210 |
|
| 211 |
**Enter your query and hit enter**
|
| 212 |
|
| 213 |
**Tip 1**: if your query includes "/", the part left (resp. right) of "/" will be used to retrieve images (resp. locate objects). For example, if you want to retrieve pictures with several cats but locate individual cats, you can type "cats / cat".
|
| 214 |
|
| 215 |
+
**Tip 2**: change the score threshold to adjust the sensitivity of the object detection step.
|
| 216 |
|
| 217 |
*Built with OpenAI's [CLIP](https://openai.com/blog/clip/) model and Google's [OWL-ViT](https://arxiv.org/abs/2205.06230) model, 🤗 Hugging Face's [transformers library](https://huggingface.co/transformers/), [Streamlit](https://streamlit.io/), 25k images from [Unsplash](https://unsplash.com/) and 8k images from [The Movie Database (TMDB)](https://www.themoviedb.org/)*
|
| 218 |
|
|
|
|
| 232 |
.block-container{
|
| 233 |
max-width: 1200px;
|
| 234 |
}
|
| 235 |
+
div.row-widget > div{
|
| 236 |
flex-direction:row;
|
| 237 |
display: flex;
|
| 238 |
justify-content: center;
|
|
|
|
| 253 |
#MainMenu {
|
| 254 |
visibility: hidden;
|
| 255 |
}
|
|
|
|
|
|
|
|
|
|
| 256 |
</style>""",
|
| 257 |
unsafe_allow_html=True,
|
| 258 |
)
|
| 259 |
st.sidebar.markdown(description)
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
_, c, _ = st.columns((1, 3, 1))
|
| 262 |
query = c.text_input("", value="koala")
|
| 263 |
+
corpus = c.radio("", ["Unsplash", "Movies"])
|
| 264 |
+
score_threshold = c.slider(
|
| 265 |
+
"Score threshold", min_value=0.01, max_value=0.1, value=0.03, step=0.01
|
| 266 |
+
)
|
| 267 |
|
| 268 |
if len(query) > 0:
|
| 269 |
if "/" in query:
|