wuzengcheng commited on
Commit
9bffa8a
·
1 Parent(s): a9dc8b2

[fix] modify save folder

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -77,8 +77,8 @@ def predict(files):
77
  y_offset += img.height
78
 
79
  new_img_hash = hashlib.md5(new_img.tobytes()).hexdigest()
80
- if not os.path.exists(f'./pkl_files/pdf_images/{new_img_hash}.pkl'):
81
- with open(f'./pkl_files/pdf_images/{new_img_hash}.pkl', 'wb') as f:
82
  pickle.dump(new_img, f)
83
 
84
  file_hashes.append(new_img_hash)
@@ -100,34 +100,34 @@ def predict(files):
100
  img_features = model.encode_image(img_batch)
101
 
102
  if request_type == 0:
103
- if os.path.exists(f'./pkl_files/img_features/{new_img_hash}.pkl'):
104
  continue
105
- with open(f'./pkl_files/img_features/{new_img_hash}.pkl', 'wb') as f:
106
  pickle.dump(img_features.cpu().numpy(), f)
107
 
108
  if request_type == 0:
109
 
110
  file_names_dict = dict(zip(file_hashes, file_names))
111
- with open('./pkl_files/file_names.pkl', 'wb') as f:
112
  pickle.dump(file_names_dict, f)
113
 
114
  return vis_images[0]
115
 
116
  if request_type == 1:
117
 
118
- with open('./pkl_files/file_names.pkl', 'rb') as f:
119
  base_file_names = pickle.load(f)
120
 
121
  base_img_hashes = []
122
  base_img_features = []
123
  base_pdf_images = {}
124
- for img_file_name in os.listdir('./pkl_files/img_features'):
125
  img_hash = img_file_name.split('.')[0]
126
- with open(f'./pkl_files/img_features/{img_file_name}', 'rb') as f:
127
  base_img_hashes.append(img_hash)
128
  base_img_features.append(pickle.load(f))
129
 
130
- with open(f'./pkl_files/pdf_images/{img_file_name}', 'rb') as f:
131
  base_pdf_images[img_hash] = pickle.load(f)
132
 
133
  base_img_features = torch.from_numpy(np.concatenate(np.array(base_img_features), axis=0)).to(device)
@@ -148,7 +148,7 @@ def predict(files):
148
  print(file_name, value[i])
149
  return base_pdf_images[file_hash]
150
  else:
151
- return Image.open('assets/not_found.png')
152
 
153
 
154
 
 
77
  y_offset += img.height
78
 
79
  new_img_hash = hashlib.md5(new_img.tobytes()).hexdigest()
80
+ if not os.path.exists(f'/home/user/app/pkl_files/pdf_images/{new_img_hash}.pkl'):
81
+ with open(f'/home/user/app/pkl_files/pdf_images/{new_img_hash}.pkl', 'wb') as f:
82
  pickle.dump(new_img, f)
83
 
84
  file_hashes.append(new_img_hash)
 
100
  img_features = model.encode_image(img_batch)
101
 
102
  if request_type == 0:
103
+ if os.path.exists(f'/home/user/app/pkl_files/img_features/{new_img_hash}.pkl'):
104
  continue
105
+ with open(f'/home/user/app/pkl_files/img_features/{new_img_hash}.pkl', 'wb') as f:
106
  pickle.dump(img_features.cpu().numpy(), f)
107
 
108
  if request_type == 0:
109
 
110
  file_names_dict = dict(zip(file_hashes, file_names))
111
+ with open('/home/user/app/pkl_files/file_names.pkl', 'wb') as f:
112
  pickle.dump(file_names_dict, f)
113
 
114
  return vis_images[0]
115
 
116
  if request_type == 1:
117
 
118
+ with open('/home/user/app/pkl_files/file_names.pkl', 'rb') as f:
119
  base_file_names = pickle.load(f)
120
 
121
  base_img_hashes = []
122
  base_img_features = []
123
  base_pdf_images = {}
124
+ for img_file_name in os.listdir('/home/user/app/pkl_files/img_features'):
125
  img_hash = img_file_name.split('.')[0]
126
+ with open(f'/home/user/app/pkl_files/img_features/{img_file_name}', 'rb') as f:
127
  base_img_hashes.append(img_hash)
128
  base_img_features.append(pickle.load(f))
129
 
130
+ with open(f'/home/user/app/pkl_files/pdf_images/{img_file_name}', 'rb') as f:
131
  base_pdf_images[img_hash] = pickle.load(f)
132
 
133
  base_img_features = torch.from_numpy(np.concatenate(np.array(base_img_features), axis=0)).to(device)
 
148
  print(file_name, value[i])
149
  return base_pdf_images[file_hash]
150
  else:
151
+ return Image.open('/home/user/app/assets/not_found.png')
152
 
153
 
154