Eleanor Zheng
commited on
Commit
·
4de9017
1
Parent(s):
6fc381d
UI Improvement for the search university page.
Browse files
app.py
CHANGED
|
@@ -157,51 +157,37 @@ def main():
|
|
| 157 |
# Main header
|
| 158 |
st.markdown("""
|
| 159 |
<div class="main-header">
|
| 160 |
-
<h1>🎓
|
| 161 |
-
<
|
| 162 |
</div>
|
| 163 |
""", unsafe_allow_html=True)
|
| 164 |
|
| 165 |
# Sidebar
|
| 166 |
with st.sidebar:
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
<div class='language-selection'>
|
| 181 |
-
<h5 style='margin: 0; color: #9b59b6;'>🔧 Embedding Model</h5>
|
| 182 |
-
<p style='margin: 5px 0; font-size: 0.9em;'>BGE-small-en-v1.5</p>
|
| 183 |
-
</div>
|
| 184 |
-
""", unsafe_allow_html=True)
|
| 185 |
-
else:
|
| 186 |
-
st.markdown("""
|
| 187 |
-
<div class='language-selection'>
|
| 188 |
-
<h5 style='margin: 0; color: #9b59b6;'>🔧 Embedding Model</h5>
|
| 189 |
-
<p style='margin: 5px 0; font-size: 0.9em;'>OpenAI Ada-002</p>
|
| 190 |
-
</div>
|
| 191 |
-
""", unsafe_allow_html=True)
|
| 192 |
-
except:
|
| 193 |
-
pass
|
| 194 |
-
|
| 195 |
# Main content based on selected page
|
| 196 |
-
if
|
| 197 |
upload_documents_page()
|
| 198 |
-
elif
|
| 199 |
manage_documents_page()
|
| 200 |
-
elif
|
| 201 |
about_page()
|
| 202 |
else:
|
| 203 |
search_page()
|
| 204 |
|
|
|
|
| 205 |
def upload_documents_page():
|
| 206 |
st.header("📄 Upload University Documents")
|
| 207 |
st.write("Upload PDF documents containing university admission requirements, fees, and program information.")
|
|
@@ -338,197 +324,90 @@ def manage_documents_page():
|
|
| 338 |
|
| 339 |
def search_page():
|
| 340 |
st.header("🔍 Search University Information")
|
| 341 |
-
|
| 342 |
-
# Language selection
|
| 343 |
col1, col2 = st.columns([3, 1])
|
| 344 |
with col1:
|
| 345 |
-
st.write("Ask
|
| 346 |
with col2:
|
| 347 |
response_language = st.selectbox(
|
| 348 |
-
"
|
| 349 |
-
["English", "中文 (Chinese)", "Bahasa Malaysia", "ไทย (Thai)",
|
|
|
|
| 350 |
key="response_language"
|
| 351 |
)
|
| 352 |
-
|
| 353 |
-
# Show language info
|
| 354 |
language_map = {
|
| 355 |
"English": "English",
|
| 356 |
-
"中文 (Chinese)": "Chinese",
|
| 357 |
"Bahasa Malaysia": "Malay",
|
| 358 |
"ไทย (Thai)": "Thai",
|
| 359 |
"Bahasa Indonesia": "Indonesian",
|
| 360 |
"Tiếng Việt (Vietnamese)": "Vietnamese"
|
| 361 |
}
|
| 362 |
-
selected_lang = language_map
|
| 363 |
-
|
| 364 |
if selected_lang != "English":
|
| 365 |
-
st.info(f"🌐
|
| 366 |
-
|
| 367 |
-
#
|
| 368 |
-
st.
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
""", unsafe_allow_html=True)
|
| 379 |
-
|
| 380 |
-
col1, col2 = st.columns(2)
|
| 381 |
-
|
| 382 |
-
with col1:
|
| 383 |
-
st.markdown("**🧠 Complex Queries (Uses Reasoning Model):**")
|
| 384 |
complex_examples = [
|
| 385 |
"Show me universities in Malaysia for master's degrees with tuition under 40,000 RMB per year",
|
| 386 |
"专科毕业,无雅思,想在马来西亚读硕士,学费不超过4万人民币/年",
|
| 387 |
"Compare engineering programs in Thailand and Singapore under $15,000 per year",
|
| 388 |
"Find MBA programs in ASEAN with GMAT requirements and scholarships available"
|
| 389 |
]
|
| 390 |
-
for example in complex_examples:
|
| 391 |
-
st.markdown(f"• {example}")
|
| 392 |
-
|
| 393 |
-
with col2:
|
| 394 |
-
st.markdown("**⚡ Simple Queries (Uses Instruct Model):**")
|
| 395 |
simple_examples = [
|
| 396 |
"What does IELTS stand for?",
|
| 397 |
"Translate 'application deadline' to Chinese",
|
| 398 |
-
"What is the difference between bachelor and master degree?",
|
| 399 |
"How to say 'university' in Thai?"
|
| 400 |
]
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
)
|
| 413 |
-
|
| 414 |
-
# Show search status
|
| 415 |
-
if query.strip():
|
| 416 |
-
st.success("✅ Ready to search! Click the search button when you're ready.")
|
| 417 |
-
else:
|
| 418 |
-
st.info("💭 Enter your question in the text box above to start searching.")
|
| 419 |
-
|
| 420 |
-
# Optional: Quick example selection (just for convenience)
|
| 421 |
-
with st.expander("💡 Example Queries (Click to Use)"):
|
| 422 |
-
# Combine all examples
|
| 423 |
-
all_examples = complex_examples + simple_examples
|
| 424 |
-
|
| 425 |
-
col1, col2 = st.columns(2)
|
| 426 |
-
with col1:
|
| 427 |
-
st.markdown("**🧠 Complex Examples:**")
|
| 428 |
-
for example in complex_examples:
|
| 429 |
-
if st.button(example[:60] + "...", key=f"ex_{hash(example)}", help=f"Click to use: {example}"):
|
| 430 |
-
st.session_state.example_query = example
|
| 431 |
-
|
| 432 |
-
with col2:
|
| 433 |
-
st.markdown("**⚡ Simple Examples:**")
|
| 434 |
-
for example in simple_examples:
|
| 435 |
-
if st.button(example[:60] + "...", key=f"ex_{hash(example)}", help=f"Click to use: {example}"):
|
| 436 |
-
st.session_state.example_query = example
|
| 437 |
-
|
| 438 |
-
# Use selected example if any
|
| 439 |
-
if hasattr(st.session_state, 'example_query') and st.session_state.example_query:
|
| 440 |
query = st.session_state.example_query
|
| 441 |
-
st.info(f"📝 Using example: {query
|
| 442 |
-
# Clear the example after use
|
| 443 |
del st.session_state.example_query
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
|
|
|
| 447 |
col1, col2, col3 = st.columns(3)
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
with col3:
|
| 461 |
-
preferred_countries = st.multiselect(
|
| 462 |
-
"Preferred Countries",
|
| 463 |
-
["Singapore", "Malaysia", "Thailand", "Indonesia", "Philippines", "Vietnam", "Brunei"],
|
| 464 |
-
default=[]
|
| 465 |
-
)
|
| 466 |
-
|
| 467 |
-
# Search button - enabled as soon as there's text in the query
|
| 468 |
-
search_disabled = not query.strip()
|
| 469 |
-
button_text = "🔍 Search" if not search_disabled else "🔍 Search (Enter a question first)"
|
| 470 |
-
|
| 471 |
-
if st.button(button_text, type="primary", disabled=search_disabled):
|
| 472 |
-
if not query.strip():
|
| 473 |
-
st.error("Please enter a question.")
|
| 474 |
-
return
|
| 475 |
-
|
| 476 |
-
# Get the language code for processing
|
| 477 |
-
language_map = {
|
| 478 |
-
"English": "English",
|
| 479 |
-
"中文 (Chinese)": "Chinese",
|
| 480 |
-
"Bahasa Malaysia": "Malay",
|
| 481 |
-
"ไทย (Thai)": "Thai",
|
| 482 |
-
"Bahasa Indonesia": "Indonesian",
|
| 483 |
-
"Tiếng Việt (Vietnamese)": "Vietnamese"
|
| 484 |
-
}
|
| 485 |
-
language_code = language_map.get(response_language, "English")
|
| 486 |
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
rag_system = RAGSystem()
|
| 491 |
-
|
| 492 |
-
# Show which model will be used
|
| 493 |
-
from rag_system import classify_query_type
|
| 494 |
-
query_type = classify_query_type(query)
|
| 495 |
-
|
| 496 |
-
if query_type == "complex":
|
| 497 |
-
st.info("🧠 **Using SEA-LION Reasoning Model (v3.5)** - Complex query detected")
|
| 498 |
-
else:
|
| 499 |
-
st.info("⚡ **Using SEA-LION Instruct Model (v3)** - Simple query/translation detected")
|
| 500 |
-
|
| 501 |
-
# Show translation status if not English
|
| 502 |
-
if response_language != "English":
|
| 503 |
-
st.info(f"🌐 **Translating response to {response_language}**")
|
| 504 |
-
|
| 505 |
-
# Add filters to query if specified
|
| 506 |
-
enhanced_query = query
|
| 507 |
-
if budget_range != "Any" or study_level or preferred_countries:
|
| 508 |
-
filters = []
|
| 509 |
-
if budget_range != "Any":
|
| 510 |
-
filters.append(f"budget range: {budget_range}")
|
| 511 |
-
if study_level:
|
| 512 |
-
filters.append(f"study levels: {', '.join(study_level)}")
|
| 513 |
-
if preferred_countries:
|
| 514 |
-
filters.append(f"countries: {', '.join(preferred_countries)}")
|
| 515 |
-
|
| 516 |
-
enhanced_query += f"\n\nAdditional filters: {'; '.join(filters)}"
|
| 517 |
-
|
| 518 |
-
# Get response
|
| 519 |
-
result = rag_system.query(enhanced_query, language_code)
|
| 520 |
-
|
| 521 |
-
if result:
|
| 522 |
-
# Save query result for sharing
|
| 523 |
-
save_query_result(result)
|
| 524 |
-
|
| 525 |
-
# Display results
|
| 526 |
-
display_query_result(result, show_share_link=True)
|
| 527 |
-
else:
|
| 528 |
-
st.error("No results found. Try rephrasing your question or upload more documents.")
|
| 529 |
-
|
| 530 |
-
except Exception as e:
|
| 531 |
-
st.error(f"Error searching: {str(e)}")
|
| 532 |
|
| 533 |
def display_query_result(result, show_share_link=False):
|
| 534 |
"""Display query results in a formatted way."""
|
|
|
|
| 157 |
# Main header
|
| 158 |
st.markdown("""
|
| 159 |
<div class="main-header">
|
| 160 |
+
<h1>🎓 Top.Edu</h1>
|
| 161 |
+
<h5>Unlock ASEAN Education with AI-Powered Search</h5>
|
| 162 |
</div>
|
| 163 |
""", unsafe_allow_html=True)
|
| 164 |
|
| 165 |
# Sidebar
|
| 166 |
with st.sidebar:
|
| 167 |
+
|
| 168 |
+
# Define the pages
|
| 169 |
+
pages = ["🔍 Search Universities", "📄 Upload Documents", "🗂 Manage Documents", "ℹ️ About Top.Edu"]
|
| 170 |
+
|
| 171 |
+
# Initialize session state if needed
|
| 172 |
+
if "current_page" not in st.session_state:
|
| 173 |
+
st.session_state.current_page = pages[0]
|
| 174 |
+
|
| 175 |
+
# Create buttons for each page
|
| 176 |
+
for p in pages:
|
| 177 |
+
if st.button(p, use_container_width=True):
|
| 178 |
+
st.session_state.current_page = p
|
| 179 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
# Main content based on selected page
|
| 181 |
+
if st.session_state.current_page == "📄 Upload Documents":
|
| 182 |
upload_documents_page()
|
| 183 |
+
elif st.session_state.current_page == "🗂 Manage Documents":
|
| 184 |
manage_documents_page()
|
| 185 |
+
elif st.session_state.current_page == "ℹ️ About":
|
| 186 |
about_page()
|
| 187 |
else:
|
| 188 |
search_page()
|
| 189 |
|
| 190 |
+
|
| 191 |
def upload_documents_page():
|
| 192 |
st.header("📄 Upload University Documents")
|
| 193 |
st.write("Upload PDF documents containing university admission requirements, fees, and program information.")
|
|
|
|
| 324 |
|
| 325 |
def search_page():
|
| 326 |
st.header("🔍 Search University Information")
|
| 327 |
+
|
| 328 |
+
# --- Language selection ---
|
| 329 |
col1, col2 = st.columns([3, 1])
|
| 330 |
with col1:
|
| 331 |
+
st.write("Ask about admissions, fees, scholarships, and programs.")
|
| 332 |
with col2:
|
| 333 |
response_language = st.selectbox(
|
| 334 |
+
"Language",
|
| 335 |
+
["English", "中文 (Chinese)", "Bahasa Malaysia", "ไทย (Thai)",
|
| 336 |
+
"Bahasa Indonesia", "Tiếng Việt (Vietnamese)"],
|
| 337 |
key="response_language"
|
| 338 |
)
|
| 339 |
+
|
|
|
|
| 340 |
language_map = {
|
| 341 |
"English": "English",
|
| 342 |
+
"中文 (Chinese)": "Chinese",
|
| 343 |
"Bahasa Malaysia": "Malay",
|
| 344 |
"ไทย (Thai)": "Thai",
|
| 345 |
"Bahasa Indonesia": "Indonesian",
|
| 346 |
"Tiếng Việt (Vietnamese)": "Vietnamese"
|
| 347 |
}
|
| 348 |
+
selected_lang = language_map[response_language]
|
| 349 |
+
|
| 350 |
if selected_lang != "English":
|
| 351 |
+
st.info(f"🌐 Responses will be in **{selected_lang}**")
|
| 352 |
+
|
| 353 |
+
# --- Query input ---
|
| 354 |
+
query = st.text_area(
|
| 355 |
+
"Your question:",
|
| 356 |
+
height=80,
|
| 357 |
+
placeholder="e.g., Master's in Malaysia under 40,000 RMB/year",
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
# --- Example queries ---
|
| 361 |
+
with st.expander("💡 See Example Queries"):
|
| 362 |
+
tab1, tab2 = st.tabs(["🧠 Complex Queries", "⚡ Simple Queries"])
|
| 363 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
complex_examples = [
|
| 365 |
"Show me universities in Malaysia for master's degrees with tuition under 40,000 RMB per year",
|
| 366 |
"专科毕业,无雅思,想在马来西亚读硕士,学费不超过4万人民币/年",
|
| 367 |
"Compare engineering programs in Thailand and Singapore under $15,000 per year",
|
| 368 |
"Find MBA programs in ASEAN with GMAT requirements and scholarships available"
|
| 369 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
simple_examples = [
|
| 371 |
"What does IELTS stand for?",
|
| 372 |
"Translate 'application deadline' to Chinese",
|
| 373 |
+
"What is the difference between bachelor and master degree?",
|
| 374 |
"How to say 'university' in Thai?"
|
| 375 |
]
|
| 376 |
+
|
| 377 |
+
for ex in complex_examples:
|
| 378 |
+
if tab1.button(ex, key=f"complex_{hash(ex)}"):
|
| 379 |
+
st.session_state.example_query = ex
|
| 380 |
+
|
| 381 |
+
for ex in simple_examples:
|
| 382 |
+
if tab2.button(ex, key=f"simple_{hash(ex)}"):
|
| 383 |
+
st.session_state.example_query = ex
|
| 384 |
+
|
| 385 |
+
# --- Use clicked example ---
|
| 386 |
+
if 'example_query' in st.session_state:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
query = st.session_state.example_query
|
| 388 |
+
st.info(f"📝 Using example: {query}")
|
|
|
|
| 389 |
del st.session_state.example_query
|
| 390 |
+
# Optionally auto-trigger search
|
| 391 |
+
|
| 392 |
+
# --- Optional filters ---
|
| 393 |
+
with st.expander("🔧 Advanced Filters"):
|
| 394 |
col1, col2, col3 = st.columns(3)
|
| 395 |
+
budget_range = col1.select_slider(
|
| 396 |
+
"Budget (USD/year)",
|
| 397 |
+
options=["Any", "<10k", "10k-20k", "20k-30k", "30k-40k", ">40k"],
|
| 398 |
+
value="Any"
|
| 399 |
+
)
|
| 400 |
+
study_level = col2.multiselect(
|
| 401 |
+
"Study Level", ["Diploma", "Bachelor", "Master", "PhD"]
|
| 402 |
+
)
|
| 403 |
+
preferred_countries = col3.multiselect(
|
| 404 |
+
"Preferred Countries",
|
| 405 |
+
["Singapore", "Malaysia", "Thailand", "Indonesia", "Philippines", "Vietnam", "Brunei"]
|
| 406 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
+
# --- Search button ---
|
| 409 |
+
if st.button("🔍 Search", type="primary", disabled=not query.strip()):
|
| 410 |
+
st.success("Searching...") # Placeholder for your RAGSystem logic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
def display_query_result(result, show_share_link=False):
|
| 413 |
"""Display query results in a formatted way."""
|