mtoft20 commited on
Commit
7e91872
Β·
verified Β·
1 Parent(s): d5dc6d6

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +37 -40
src/streamlit_app.py CHANGED
@@ -266,55 +266,56 @@ def get_similar_content(content, n_recommendations=5):
266
  clean_title = re.sub(r'\s*\(\d{4}\)\s*$', '', title)
267
  st.write(f"πŸ” Searching for similar content to: {clean_title}")
268
 
269
- # URLs for both similarity tables - using the correct table names
270
  similarity_table_urls = [
271
- "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/content_similarities_part_1_csv",
272
- "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/content_similarities_part_2_csv"
273
  ]
274
 
275
  similar_items = []
276
 
277
  # Check both tables for similarities
278
  for table_url in similarity_table_urls:
279
- # Format query according to NocoDB API specs
280
- where_condition = {
281
- "title": {
282
- "eq": clean_title
283
- }
284
- }
285
  params = {
286
- "where": json.dumps(where_condition)
287
  }
288
 
289
  # Debug: Print the request details
290
  st.write(f"πŸ“‘ Querying table: {table_url.split('/')[-1]}")
291
  st.write(f"πŸ” Query params: {params}")
292
 
293
- response = requests.get(table_url, headers=headers, params=params)
294
-
295
- # Debug: Print response status and content
296
- st.write(f"πŸ“₯ Response status: {response.status_code}")
297
-
298
- # Debug: Print raw response
299
  try:
300
- response_json = response.json()
301
- st.write("Raw response:", response_json)
302
- except Exception as e:
303
- st.write("Could not parse response as JSON:", response.text)
304
-
305
- if response.status_code == 200:
306
- data = response_json
307
- st.write(f"πŸ“Š Found {len(data.get('list', []))} matches in table")
308
 
309
- if data and len(data.get('list', [])) > 0:
310
- # Get similar items from stored data
311
- try:
312
- table_items = json.loads(data['list'][0]['similar_items'])
313
- st.write(f"βœ… Successfully parsed {len(table_items)} similar items")
314
- similar_items.extend(table_items)
315
- except Exception as parse_error:
316
- st.write(f"❌ Error parsing similar items: {str(parse_error)}")
317
- st.write("Raw data:", data['list'][0])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
  st.write(f"πŸ“ Total similar items found: {len(similar_items)}")
320
 
@@ -326,14 +327,10 @@ def get_similar_content(content, n_recommendations=5):
326
  # Get full content details for each similar item
327
  similar_content = []
328
  for item in similar_items:
329
- # Format query for content lookup
330
- content_where = {
331
- "title": {
332
- "eq": item['title']
333
- }
334
- }
335
  content_params = {
336
- "where": json.dumps(content_where)
337
  }
338
  content_response = requests.get(NOCODB_URL, headers=headers, params=content_params)
339
 
 
266
  clean_title = re.sub(r'\s*\(\d{4}\)\s*$', '', title)
267
  st.write(f"πŸ” Searching for similar content to: {clean_title}")
268
 
269
+ # URLs for both similarity tables using table IDs
270
  similarity_table_urls = [
271
+ "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mtsx4yp45gi12tm", # Part 1
272
+ "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mca47f9wyoubouk" # Part 2
273
  ]
274
 
275
  similar_items = []
276
 
277
  # Check both tables for similarities
278
  for table_url in similarity_table_urls:
279
+ # Using NocoDB's filter format
280
+ query = f"(title,eq,{clean_title})"
 
 
 
 
281
  params = {
282
+ "where": query
283
  }
284
 
285
  # Debug: Print the request details
286
  st.write(f"πŸ“‘ Querying table: {table_url.split('/')[-1]}")
287
  st.write(f"πŸ” Query params: {params}")
288
 
289
+ # Make the request
 
 
 
 
 
290
  try:
291
+ response = requests.get(table_url, headers=headers, params=params)
 
 
 
 
 
 
 
292
 
293
+ # Debug: Print response status and content
294
+ st.write(f"πŸ“₯ Response status: {response.status_code}")
295
+ st.write("πŸ“₯ Request URL:", response.url)
296
+
297
+ # Debug: Print raw response
298
+ try:
299
+ response_json = response.json()
300
+ st.write("Raw response:", response_json)
301
+ except Exception as e:
302
+ st.write("Could not parse response as JSON:", response.text)
303
+
304
+ if response.status_code == 200:
305
+ data = response_json
306
+ st.write(f"πŸ“Š Found {len(data.get('list', []))} matches in table")
307
+
308
+ if data and len(data.get('list', [])) > 0:
309
+ # Get similar items from stored data
310
+ try:
311
+ table_items = json.loads(data['list'][0]['similar_items'])
312
+ st.write(f"βœ… Successfully parsed {len(table_items)} similar items")
313
+ similar_items.extend(table_items)
314
+ except Exception as parse_error:
315
+ st.write(f"❌ Error parsing similar items: {str(parse_error)}")
316
+ st.write("Raw data:", data['list'][0])
317
+ except Exception as e:
318
+ st.write(f"❌ Request error: {str(e)}")
319
 
320
  st.write(f"πŸ“ Total similar items found: {len(similar_items)}")
321
 
 
327
  # Get full content details for each similar item
328
  similar_content = []
329
  for item in similar_items:
330
+ # Query main content table for full details
331
+ query = f"(title,eq,{item['title']})"
 
 
 
 
332
  content_params = {
333
+ "where": query
334
  }
335
  content_response = requests.get(NOCODB_URL, headers=headers, params=content_params)
336