Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -12
src/streamlit_app.py
CHANGED
|
@@ -218,6 +218,19 @@ Please provide a helpful, accurate response based on the data provided. Keep you
|
|
| 218 |
except Exception as e:
|
| 219 |
raise Exception(f"Together AI Error: {str(e)}")
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
# =============================================================================
|
| 222 |
# MAIN APP
|
| 223 |
# =============================================================================
|
|
@@ -272,6 +285,10 @@ def main():
|
|
| 272 |
if genre.strip()
|
| 273 |
)))
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
# Sidebar filters
|
| 276 |
st.sidebar.header("🔍 Filter Content")
|
| 277 |
|
|
@@ -329,18 +346,22 @@ def main():
|
|
| 329 |
else:
|
| 330 |
duration_range = (0, 1000) # Fallback values
|
| 331 |
|
| 332 |
-
# Director filter
|
| 333 |
-
|
| 334 |
-
"
|
| 335 |
-
|
| 336 |
-
|
|
|
|
|
|
|
| 337 |
)
|
| 338 |
|
| 339 |
-
# Cast filter
|
| 340 |
-
|
| 341 |
-
"Cast
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
| 344 |
)
|
| 345 |
|
| 346 |
# Submit button
|
|
@@ -353,8 +374,8 @@ def main():
|
|
| 353 |
'genres': selected_genres,
|
| 354 |
'year_range': year_range,
|
| 355 |
'duration_range': duration_range,
|
| 356 |
-
'director':
|
| 357 |
-
'cast':
|
| 358 |
}
|
| 359 |
|
| 360 |
# Only apply filters when the button is clicked
|
|
|
|
| 218 |
except Exception as e:
|
| 219 |
raise Exception(f"Together AI Error: {str(e)}")
|
| 220 |
|
| 221 |
+
def extract_unique_names(content_list, field):
|
| 222 |
+
"""Extract unique names from a comma-separated field in content list"""
|
| 223 |
+
unique_names = set()
|
| 224 |
+
for content in content_list:
|
| 225 |
+
names = content.get(field, '')
|
| 226 |
+
if names:
|
| 227 |
+
# Split by comma and clean each name
|
| 228 |
+
for name in names.split(','):
|
| 229 |
+
cleaned_name = name.strip()
|
| 230 |
+
if cleaned_name: # Only add non-empty names
|
| 231 |
+
unique_names.add(cleaned_name)
|
| 232 |
+
return sorted(list(unique_names))
|
| 233 |
+
|
| 234 |
# =============================================================================
|
| 235 |
# MAIN APP
|
| 236 |
# =============================================================================
|
|
|
|
| 285 |
if genre.strip()
|
| 286 |
)))
|
| 287 |
|
| 288 |
+
# Extract unique directors and cast members
|
| 289 |
+
all_directors = extract_unique_names(all_content, 'director')
|
| 290 |
+
all_cast_members = extract_unique_names(all_content, 'cast')
|
| 291 |
+
|
| 292 |
# Sidebar filters
|
| 293 |
st.sidebar.header("🔍 Filter Content")
|
| 294 |
|
|
|
|
| 346 |
else:
|
| 347 |
duration_range = (0, 1000) # Fallback values
|
| 348 |
|
| 349 |
+
# Director filter with autocomplete
|
| 350 |
+
selected_directors = st.multiselect(
|
| 351 |
+
"Directors",
|
| 352 |
+
options=all_directors,
|
| 353 |
+
default=[],
|
| 354 |
+
help="Select one or more directors (searchable)",
|
| 355 |
+
placeholder="Start typing to search directors..."
|
| 356 |
)
|
| 357 |
|
| 358 |
+
# Cast filter with autocomplete
|
| 359 |
+
selected_cast = st.multiselect(
|
| 360 |
+
"Cast Members",
|
| 361 |
+
options=all_cast_members,
|
| 362 |
+
default=[],
|
| 363 |
+
help="Select one or more cast members (searchable)",
|
| 364 |
+
placeholder="Start typing to search cast members..."
|
| 365 |
)
|
| 366 |
|
| 367 |
# Submit button
|
|
|
|
| 374 |
'genres': selected_genres,
|
| 375 |
'year_range': year_range,
|
| 376 |
'duration_range': duration_range,
|
| 377 |
+
'director': ','.join(selected_directors) if selected_directors else '',
|
| 378 |
+
'cast': ','.join(selected_cast) if selected_cast else ''
|
| 379 |
}
|
| 380 |
|
| 381 |
# Only apply filters when the button is clicked
|