jaketae commited on
Commit
1991cb1
1 Parent(s): 2cf3514

fix: close read file

Browse files
Files changed (1) hide show
  1. utils.py +7 -14
utils.py CHANGED
@@ -9,13 +9,13 @@ from koclip import FlaxHybridCLIP
9
  @st.cache(allow_output_mutation=True)
10
  def load_index(img_file):
11
  filenames, embeddings = [], []
12
- lines = open(img_file, "r")
13
- for line in lines:
14
- cols = line.strip().split("\t")
15
- filename = cols[0]
16
- embedding = [float(x) for x in cols[1].split(",")]
17
- filenames.append(filename)
18
- embeddings.append(embedding)
19
  embeddings = np.array(embeddings)
20
  index = nmslib.init(method="hnsw", space="cosinesimil")
21
  index.addDataPointBatch(embeddings)
@@ -34,10 +34,3 @@ def load_model(model_name="koclip/koclip-base"):
34
  "google/vit-large-patch16-224"
35
  )
36
  return model, processor
37
-
38
-
39
- @st.cache(allow_output_mutation=True)
40
- def load_model_v2(model_name="koclip/koclip"):
41
- model = FlaxHybridCLIP.from_pretrained(model_name)
42
- processor = CLIPProcessor.from_pretrained(model_name)
43
- return model, processor
 
9
  @st.cache(allow_output_mutation=True)
10
  def load_index(img_file):
11
  filenames, embeddings = [], []
12
+ with open(img_file, "r") as f:
13
+ for line in f:
14
+ cols = line.strip().split("\t")
15
+ filename = cols[0]
16
+ embedding = [float(x) for x in cols[1].split(",")]
17
+ filenames.append(filename)
18
+ embeddings.append(embedding)
19
  embeddings = np.array(embeddings)
20
  index = nmslib.init(method="hnsw", space="cosinesimil")
21
  index.addDataPointBatch(embeddings)
 
34
  "google/vit-large-patch16-224"
35
  )
36
  return model, processor