Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -54
src/streamlit_app.py
CHANGED
|
@@ -288,8 +288,8 @@ def get_similar_content(content, n_recommendations=5):
|
|
| 288 |
st.write("Columns:", list(sample_data['list'][0].keys()))
|
| 289 |
st.write("Sample row:", sample_data['list'][0])
|
| 290 |
|
| 291 |
-
# Try finding by show_id
|
| 292 |
-
query = f'where=(show_id,eq,{show_id})'
|
| 293 |
params = {
|
| 294 |
"where": query
|
| 295 |
}
|
|
@@ -306,60 +306,21 @@ def get_similar_content(content, n_recommendations=5):
|
|
| 306 |
|
| 307 |
if response.status_code == 200:
|
| 308 |
data = response.json()
|
| 309 |
-
if
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
title_query = f'where=(title,eq,{title})' # Remove quotes here too
|
| 313 |
-
title_params = {
|
| 314 |
-
"where": title_query
|
| 315 |
-
}
|
| 316 |
-
response = requests.get(table_url, headers=headers, params=title_params)
|
| 317 |
-
st.write(f"π₯ Title search response status: {response.status_code}")
|
| 318 |
-
st.write("π₯ Title search URL:", response.url)
|
| 319 |
-
if response.status_code == 200:
|
| 320 |
-
data = response.json()
|
| 321 |
-
|
| 322 |
-
# Debug: Print raw response
|
| 323 |
-
try:
|
| 324 |
-
response_json = response.json()
|
| 325 |
-
st.write("Raw response:", response_json)
|
| 326 |
-
|
| 327 |
-
# Additional debugging
|
| 328 |
-
if response_json.get('list'):
|
| 329 |
-
st.write("β
Found entries in response")
|
| 330 |
-
for entry in response_json['list']:
|
| 331 |
st.write(f"Entry title: {entry.get('title')}, show_id: {entry.get('show_id')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
else:
|
| 333 |
-
st.write("β No
|
| 334 |
-
|
| 335 |
-
# Try to get a few random entries to verify data
|
| 336 |
-
sample_params = {
|
| 337 |
-
"limit": 3,
|
| 338 |
-
"shuffle": True
|
| 339 |
-
}
|
| 340 |
-
sample_response = requests.get(table_url, headers=headers, params=sample_params)
|
| 341 |
-
if sample_response.status_code == 200:
|
| 342 |
-
sample_data = sample_response.json()
|
| 343 |
-
st.write("π Random entries from table:")
|
| 344 |
-
for entry in sample_data.get('list', []):
|
| 345 |
-
st.write(f"- {entry.get('title')} (ID: {entry.get('show_id')})")
|
| 346 |
-
|
| 347 |
-
except Exception as e:
|
| 348 |
-
st.write("Could not parse response as JSON:", response.text)
|
| 349 |
-
|
| 350 |
-
if response.status_code == 200:
|
| 351 |
-
data = response_json
|
| 352 |
-
st.write(f"π Found {len(data.get('list', []))} matches in table")
|
| 353 |
-
|
| 354 |
-
if data and len(data.get('list', [])) > 0:
|
| 355 |
-
# Get similar items from stored data
|
| 356 |
-
try:
|
| 357 |
-
table_items = json.loads(data['list'][0]['similar_items'])
|
| 358 |
-
st.write(f"β
Successfully parsed {len(table_items)} similar items")
|
| 359 |
-
similar_items.extend(table_items)
|
| 360 |
-
except Exception as parse_error:
|
| 361 |
-
st.write(f"β Error parsing similar items: {str(parse_error)}")
|
| 362 |
-
st.write("Raw data:", data['list'][0])
|
| 363 |
except Exception as e:
|
| 364 |
st.write(f"β Request error: {str(e)}")
|
| 365 |
|
|
|
|
| 288 |
st.write("Columns:", list(sample_data['list'][0].keys()))
|
| 289 |
st.write("Sample row:", sample_data['list'][0])
|
| 290 |
|
| 291 |
+
# Try finding by both show_id and title
|
| 292 |
+
query = f'where=(show_id,eq,{show_id})~and(title,eq,{title})'
|
| 293 |
params = {
|
| 294 |
"where": query
|
| 295 |
}
|
|
|
|
| 306 |
|
| 307 |
if response.status_code == 200:
|
| 308 |
data = response.json()
|
| 309 |
+
if data.get('list'):
|
| 310 |
+
st.write(f"β
Found exact match")
|
| 311 |
+
for entry in data['list']:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
st.write(f"Entry title: {entry.get('title')}, show_id: {entry.get('show_id')}")
|
| 313 |
+
|
| 314 |
+
# Parse similar items
|
| 315 |
+
try:
|
| 316 |
+
similar_items = json.loads(entry['similar_items'])
|
| 317 |
+
st.write(f"β
Successfully parsed {len(similar_items)} similar items")
|
| 318 |
+
return similar_items
|
| 319 |
+
except Exception as parse_error:
|
| 320 |
+
st.write(f"β Error parsing similar items: {str(parse_error)}")
|
| 321 |
+
st.write("Raw data:", entry)
|
| 322 |
else:
|
| 323 |
+
st.write("β No exact match found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
except Exception as e:
|
| 325 |
st.write(f"β Request error: {str(e)}")
|
| 326 |
|