mtoft20 commited on
Commit
a87e594
Β·
verified Β·
1 Parent(s): d60b4a5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -20
src/streamlit_app.py CHANGED
@@ -10,7 +10,7 @@ import re
10
  # =============================================================================
11
  # CONFIGURATION - Using Secrets Management
12
  # =============================================================================
13
- NOCODB_URL = "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mtsx4yp45gi12tm" # Updated with table ID
14
 
15
  # Get sensitive data from Streamlit secrets or environment variables
16
  def get_api_credentials():
@@ -260,28 +260,19 @@ def get_similar_content(content, n_recommendations=5):
260
  "accept": "application/json"
261
  }
262
 
263
- # Debug: Print the title we're searching for
264
  title = content.get('title', '')
265
- # Remove year if it's in parentheses at the end
266
- clean_title = re.sub(r'\s*\(\d{4}\)\s*$', '', title)
267
- st.write(f"πŸ” Searching for similar content to: {clean_title}")
268
-
269
- # First verify the movie exists in the main content table
270
- verify_params = {
271
- "where": f'(title,eq,"{clean_title}")'
272
- }
273
- verify_response = requests.get(NOCODB_URL, headers=headers, params=verify_params)
274
- if verify_response.status_code == 200:
275
- verify_data = verify_response.json()
276
- st.write(f"βœ… Found movie in main content table: {len(verify_data.get('list', []))} matches")
277
 
278
  # Base URL for the NocoDB API
279
  base_url = "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee"
280
 
281
  # URLs for both similarity tables using table IDs
282
  similarity_table_urls = [
283
- f"{base_url}/content_similarities_part_1_csv", # Part 1 similarities
284
- f"{base_url}/content_similarities_part_2_csv" # Part 2 similarities
 
285
  ]
286
 
287
  similar_items = []
@@ -298,9 +289,10 @@ def get_similar_content(content, n_recommendations=5):
298
  if sample_data.get('list'):
299
  st.write(f"πŸ“‹ Table structure for {table_url.split('/')[-1]}:")
300
  st.write("Columns:", list(sample_data['list'][0].keys()))
 
301
 
302
- # Using NocoDB's filter format with quotes around the title
303
- query = f'(title,eq,"{clean_title}")'
304
  params = {
305
  "where": query
306
  }
@@ -350,8 +342,14 @@ def get_similar_content(content, n_recommendations=5):
350
  # Get full content details for each similar item
351
  similar_content = []
352
  for item in similar_items:
353
- # Query main content table for full details
354
- query = f'(title,eq,"{item["title"]}")'
 
 
 
 
 
 
355
  content_params = {
356
  "where": query
357
  }
 
10
  # =============================================================================
11
  # CONFIGURATION - Using Secrets Management
12
  # =============================================================================
13
+ NOCODB_URL = "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/mvtt3arw5ni7uqp" # Updated with table ID
14
 
15
  # Get sensitive data from Streamlit secrets or environment variables
16
  def get_api_credentials():
 
260
  "accept": "application/json"
261
  }
262
 
263
+ # Debug: Print the title and show_id we're searching for
264
  title = content.get('title', '')
265
+ show_id = content.get('show_id', '')
266
+ st.write(f"πŸ” Searching for similar content to: {title} (ID: {show_id})")
 
 
 
 
 
 
 
 
 
 
267
 
268
  # Base URL for the NocoDB API
269
  base_url = "https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee"
270
 
271
  # URLs for both similarity tables using table IDs
272
  similarity_table_urls = [
273
+ f"{base_url}/mp7bnn9tzhojh7k", # Part 1 similarities
274
+ f"{base_url}/m8e5rglns4acmef", # Part 2 similarities
275
+ f"{base_url}/m2driodimid10k6" # Part 3 similarities
276
  ]
277
 
278
  similar_items = []
 
289
  if sample_data.get('list'):
290
  st.write(f"πŸ“‹ Table structure for {table_url.split('/')[-1]}:")
291
  st.write("Columns:", list(sample_data['list'][0].keys()))
292
+ st.write("Sample row:", sample_data['list'][0])
293
 
294
+ # Try finding by show_id
295
+ query = f'(show_id,eq,"{show_id}")'
296
  params = {
297
  "where": query
298
  }
 
342
  # Get full content details for each similar item
343
  similar_content = []
344
  for item in similar_items:
345
+ # Query main content table for full details using show_id if available
346
+ show_id = item.get('show_id', '')
347
+ if show_id:
348
+ query = f'(show_id,eq,"{show_id}")'
349
+ else:
350
+ # Fallback to title if show_id not available
351
+ query = f'(title,eq,"{item["title"]}")'
352
+
353
  content_params = {
354
  "where": query
355
  }