mtoft20 commited on
Commit
7ae5ce5
Β·
verified Β·
1 Parent(s): 1480a63

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +23 -2
src/streamlit_app.py CHANGED
@@ -259,6 +259,9 @@ def get_similar_content(content, n_recommendations=5):
259
  "accept": "application/json"
260
  }
261
 
 
 
 
262
  # URLs for both similarity tables
263
  similarity_table_urls = [
264
  "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mtsx4yp45gi12tm",
@@ -273,14 +276,28 @@ def get_similar_content(content, n_recommendations=5):
273
  "where": f"(title,eq,\"{content['title']}\")"
274
  }
275
 
 
 
 
276
  response = requests.get(table_url, headers=headers, params=params)
277
 
 
 
278
  if response.status_code == 200:
279
  data = response.json()
 
 
280
  if data and len(data.get('list', [])) > 0:
281
  # Get similar items from stored data
282
- table_items = json.loads(data['list'][0]['similar_items'])
283
- similar_items.extend(table_items)
 
 
 
 
 
 
 
284
 
285
  if similar_items:
286
  # Sort by similarity score and limit to requested number
@@ -302,12 +319,16 @@ def get_similar_content(content, n_recommendations=5):
302
  content_dict = content_data['list'][0]
303
  content_dict['similarity'] = f"{item['similarity']:.2%}"
304
  similar_content.append(content_dict)
 
 
 
305
 
306
  return similar_content
307
 
308
  return []
309
  except Exception as e:
310
  st.error(f"Error fetching similar content: {str(e)}")
 
311
  return []
312
 
313
  # =============================================================================
 
259
  "accept": "application/json"
260
  }
261
 
262
+ # Debug: Print the title we're searching for
263
+ st.write(f"πŸ” Searching for similar content to: {content.get('title')}")
264
+
265
  # URLs for both similarity tables
266
  similarity_table_urls = [
267
  "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mtsx4yp45gi12tm",
 
276
  "where": f"(title,eq,\"{content['title']}\")"
277
  }
278
 
279
+ # Debug: Print the request details
280
+ st.write(f"πŸ“‘ Querying table: {table_url.split('/')[-1]}")
281
+
282
  response = requests.get(table_url, headers=headers, params=params)
283
 
284
+ # Debug: Print response status and content
285
+ st.write(f"πŸ“₯ Response status: {response.status_code}")
286
  if response.status_code == 200:
287
  data = response.json()
288
+ st.write(f"πŸ“Š Found {len(data.get('list', []))} matches in table")
289
+
290
  if data and len(data.get('list', [])) > 0:
291
  # Get similar items from stored data
292
+ try:
293
+ table_items = json.loads(data['list'][0]['similar_items'])
294
+ st.write(f"βœ… Successfully parsed {len(table_items)} similar items")
295
+ similar_items.extend(table_items)
296
+ except Exception as parse_error:
297
+ st.write(f"❌ Error parsing similar items: {str(parse_error)}")
298
+ st.write("Raw data:", data['list'][0])
299
+
300
+ st.write(f"πŸ“ Total similar items found: {len(similar_items)}")
301
 
302
  if similar_items:
303
  # Sort by similarity score and limit to requested number
 
319
  content_dict = content_data['list'][0]
320
  content_dict['similarity'] = f"{item['similarity']:.2%}"
321
  similar_content.append(content_dict)
322
+ st.write(f"βœ… Found details for: {item['title']}")
323
+ else:
324
+ st.write(f"❌ No content details found for: {item['title']}")
325
 
326
  return similar_content
327
 
328
  return []
329
  except Exception as e:
330
  st.error(f"Error fetching similar content: {str(e)}")
331
+ st.write("Full error details:", e)
332
  return []
333
 
334
  # =============================================================================