leedoming commited on
Commit
f0cd321
·
verified ·
1 Parent(s): 82ca7db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -11,11 +11,15 @@ import cv2
11
  import chromadb
12
  from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation
13
  import torch.nn as nn
 
 
 
 
14
 
15
  # Load CLIP model and tokenizer
16
  @st.cache_resource
17
  def load_clip_model():
18
- model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:Marqo/marqo-fashionSigLIP')
19
  tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')
20
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
21
  model.to(device)
@@ -46,9 +50,14 @@ def load_image_from_url(url, max_retries=3):
46
  else:
47
  return None
48
 
49
- #Load chromaDB
50
- client = chromadb.PersistentClient(path="./clothesDB")
51
- collection = client.get_collection(name="clothes_items_ver3")
 
 
 
 
 
52
 
53
  def get_image_embedding(image):
54
  image_tensor = preprocess_val(image).unsqueeze(0).to(device)
@@ -229,4 +238,7 @@ else: # Text search
229
  st.write(f"Discount: {img['info']['discount']}%")
230
  st.write(f"Similarity: {img['similarity']:.2f}")
231
  else:
232
- st.warning("Please enter a search text.")
 
 
 
 
11
  import chromadb
12
  from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation
13
  import torch.nn as nn
14
+ import warnings
15
+
16
+ # Suppress specific warnings
17
+ warnings.filterwarnings("ignore", category=UserWarning, module="transformers.utils.deprecation")
18
 
19
  # Load CLIP model and tokenizer
20
  @st.cache_resource
21
  def load_clip_model():
22
+ model, _, preprocess_val = open_clip.create_model_and_transforms('hf-hub:Marqo/marqo-fashionSigLIP')
23
  tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')
24
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
25
  model.to(device)
 
50
  else:
51
  return None
52
 
53
+ # Load ChromaDB
54
+ @st.cache_resource
55
+ def load_chromadb():
56
+ client = chromadb.PersistentClient(path="./clothesDB")
57
+ collection = client.get_collection(name="clothes_items_ver3")
58
+ return collection
59
+
60
+ collection = load_chromadb()
61
 
62
  def get_image_embedding(image):
63
  image_tensor = preprocess_val(image).unsqueeze(0).to(device)
 
238
  st.write(f"Discount: {img['info']['discount']}%")
239
  st.write(f"Similarity: {img['similarity']:.2f}")
240
  else:
241
+ st.warning("Please enter a search text.")
242
+
243
+ # Display ChromaDB vacuum message
244
+ st.sidebar.warning("If you've upgraded ChromaDB from a version below 0.6, you may benefit from vacuuming your database. Run 'chromadb utils vacuum --help' for more information.")