andykr1k commited on
Commit
20560f9
·
1 Parent(s): 7325002

New feed recommender

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -186,15 +186,25 @@ class Recommender:
186
  text = f"{title} {description}".strip()
187
  post_texts.append(text)
188
  post_ids.append(post_id)
189
- post['created_at'] = datetime.fromisoformat(
190
- post['created_at'].replace('Z', '+00:00')
191
- ).astimezone(TIMEZONE)
 
 
 
 
 
 
 
 
 
192
  post['type'] = 'post'
193
  post_metadata[post_id] = post
194
 
195
- embeddings = sentence_model.encode(post_texts, show_progress_bar=True, convert_to_numpy=True)
196
- for post_id, embedding in zip(post_ids, embeddings):
197
- post_features[post_id] = embedding / np.linalg.norm(embedding)
 
198
 
199
  await self.update_interactions()
200
 
 
186
  text = f"{title} {description}".strip()
187
  post_texts.append(text)
188
  post_ids.append(post_id)
189
+
190
+ # Adjust the timestamp to ensure six digits for microseconds
191
+ created_at_str = post['created_at']
192
+ if '.' in created_at_str:
193
+ date_part, time_part = created_at_str.split('T')
194
+ time_part = time_part.split('+')[0] # Remove timezone for now
195
+ if '.' in time_part:
196
+ time_without_micro, micro = time_part.split('.')
197
+ micro = micro.zfill(6) # Pad with zeros to make it six digits
198
+ time_part = f"{time_without_micro}.{micro}"
199
+ created_at_str = f"{date_part}T{time_part}+00:00"
200
+ post['created_at'] = datetime.fromisoformat(created_at_str).astimezone(TIMEZONE)
201
  post['type'] = 'post'
202
  post_metadata[post_id] = post
203
 
204
+ if post_texts:
205
+ embeddings = sentence_model.encode(post_texts, show_progress_bar=True, convert_to_numpy=True)
206
+ for post_id, embedding in zip(post_ids, embeddings):
207
+ post_features[post_id] = embedding / np.linalg.norm(embedding)
208
 
209
  await self.update_interactions()
210