Spaces:
Sleeping
Sleeping
tensorkelechi
commited on
Commit
•
44883c6
1
Parent(s):
bb57dce
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ripple
|
2 |
+
import streamlit as stl
|
3 |
+
from tqdm.auto import tqdm
|
4 |
+
|
5 |
+
# streamlit app
|
6 |
+
stl.set_page_config(
|
7 |
+
page_title="Ripple",
|
8 |
+
)
|
9 |
+
|
10 |
+
stl.title("ripple search")
|
11 |
+
stl.write(
|
12 |
+
"An app that uses text input to search for described images, using embeddings of selected image datasets. Uses contrastive learning models(CLIP) and the sentence transformers library"
|
13 |
+
)
|
14 |
+
stl.link_button(
|
15 |
+
label="link to github and full library code",
|
16 |
+
url="https://github.com/kelechi-c/ripple_net",
|
17 |
+
)
|
18 |
+
|
19 |
+
dataset = stl.selectbox(
|
20 |
+
"choose huggingface dataset(bgger datasets take more time to embed..)",
|
21 |
+
options=[
|
22 |
+
"huggan/wikiart(1k)",
|
23 |
+
"huggan/wikiart(11k)",
|
24 |
+
"zh-plus/tiny-imagenet(110k)",
|
25 |
+
"lambdalabs/naruto-blip-captions(1k)",
|
26 |
+
"detection-datasets/fashionpedia(45k)",
|
27 |
+
],
|
28 |
+
)
|
29 |
+
# initalized global variables
|
30 |
+
|
31 |
+
embedded_data = None
|
32 |
+
embedder = None
|
33 |
+
text_search = None
|
34 |
+
|
35 |
+
ret_images = []
|
36 |
+
scores = []
|
37 |
+
|
38 |
+
|
39 |
+
if dataset and stl.button("embed image dataset"):
|
40 |
+
with stl.spinner("Initializing and creating image embeddings from dataset"):
|
41 |
+
embedder = ripple.ImageEmbedder(
|
42 |
+
dataset, retrieval_type="text-image", dataset_type="huggingface"
|
43 |
+
)
|
44 |
+
|
45 |
+
embedded_data = embedder.create_embeddings(device="cpu")
|
46 |
+
stl.success("Sucessfully embedded and dcreated image index")
|
47 |
+
|
48 |
+
if embedded_data is not None:
|
49 |
+
text_search = ripple.TextSearch(embedded_data, embedder.embed_model)
|
50 |
+
stl.success("Initialized text search class")
|
51 |
+
|
52 |
+
search_term = stl.text_input("Text description/search for image")
|
53 |
+
|
54 |
+
if search_term:
|
55 |
+
with stl.spinner("retrieving images with description.."):
|
56 |
+
scores, ret_images = text_search.get_similar_images(
|
57 |
+
search_term, k_images=4)
|
58 |
+
stl.success(f"sucessfully retrieved {len(ret_images)}")
|
59 |
+
|
60 |
+
for count, score, image in tqdm(zip(range(len(ret_images)), scores, ret_images)):
|
61 |
+
stl.image(image["image"][count])
|
62 |
+
stl.write(score)
|