Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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
|
| 270 |
similarity_table_urls = [
|
| 271 |
-
"https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/
|
| 272 |
-
"https://mtoft20-potm.hf.space/api/v1/db/data/noco/p9pozkcw81t9aee/
|
| 273 |
]
|
| 274 |
|
| 275 |
similar_items = []
|
| 276 |
|
| 277 |
# Check both tables for similarities
|
| 278 |
for table_url in similarity_table_urls:
|
| 279 |
-
#
|
| 280 |
-
|
| 281 |
-
"title": {
|
| 282 |
-
"eq": clean_title
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
params = {
|
| 286 |
-
"where":
|
| 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 |
-
|
| 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 |
-
|
| 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 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 330 |
-
|
| 331 |
-
"title": {
|
| 332 |
-
"eq": item['title']
|
| 333 |
-
}
|
| 334 |
-
}
|
| 335 |
content_params = {
|
| 336 |
-
"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 |
|