bhlewis commited on
Commit
6744e1a
1 Parent(s): 257c33f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -6,21 +6,28 @@ import json
6
  from sentence_transformers import SentenceTransformer
7
 
8
  def load_data():
9
- with h5py.File('path_to_your_embeddings_file.h5', 'r') as f:
10
- embeddings = f['embeddings'][:]
11
- patent_numbers = f['patent_numbers'][:]
12
-
13
- metadata = {}
14
- with open('path_to_your_metadata_file.jsonl', 'r') as f:
15
- for line in f:
16
- data = json.loads(line)
17
- metadata[data['patent_number']] = data
18
-
19
- print(f"Embedding shape: {embeddings.shape}")
20
- print(f"Number of patent numbers: {len(patent_numbers)}")
21
- print(f"Number of metadata entries: {len(metadata)}")
22
-
23
- return embeddings, patent_numbers, metadata
 
 
 
 
 
 
 
24
 
25
  embeddings, patent_numbers, metadata = load_data()
26
 
 
6
  from sentence_transformers import SentenceTransformer
7
 
8
  def load_data():
9
+ try:
10
+ with h5py.File('patent_embeddings.h5', 'r') as f:
11
+ embeddings = f['embeddings'][:]
12
+ patent_numbers = f['patent_numbers'][:]
13
+
14
+ metadata = {}
15
+ with open('patent_metadata.jsonl', 'r') as f:
16
+ for line in f:
17
+ data = json.loads(line)
18
+ metadata[data['patent_number']] = data
19
+
20
+ print(f"Embedding shape: {embeddings.shape}")
21
+ print(f"Number of patent numbers: {len(patent_numbers)}")
22
+ print(f"Number of metadata entries: {len(metadata)}")
23
+
24
+ return embeddings, patent_numbers, metadata
25
+ except FileNotFoundError as e:
26
+ print(f"Error: Could not find file. {e}")
27
+ raise
28
+ except Exception as e:
29
+ print(f"An unexpected error occurred while loading data: {e}")
30
+ raise
31
 
32
  embeddings, patent_numbers, metadata = load_data()
33