import streamlit as st import requests import os from dotenv import load_dotenv from media_config import AUDIO_URLS from environments import get_current_config, get_environment, get_environment_display_info load_dotenv() # Get current environment configuration ENVIRONMENT = get_environment() config = get_current_config() env_info = get_environment_display_info() # Use configuration for URLs AGENT_URL = config["agent_url"] MCP_SERVER_URL = config["mcp_server_url"] # API Key for agent authentication (set in HF Space secrets for production) # AGENT_API_KEY is optional for local development st.set_page_config( page_title="World Cup AI Assistant (Beta)", page_icon="🏆", layout="wide", # Use full width initial_sidebar_state="collapsed" # Hide sidebar to save space ) # Initialize session state if "chat_history" not in st.session_state: st.session_state.chat_history = [] # Enhanced CSS with background styling st.markdown(""" """, unsafe_allow_html=True) # Main content with enhanced styling st.markdown('''

🏆 World Cup AI Assistant

BETA
''', unsafe_allow_html=True) # Beta notice banner st.info(""" **🚧 Beta Version** - We're actively improving this app. Some features are still in development. Your feedback helps us make it better! Known limitations: Agent memory is missing, and response times may vary. """) # Environment badge (hidden in production) if ENVIRONMENT != "prod": st.markdown(f"""
{env_info['icon']} {env_info['name']} {env_info['description']}
""", unsafe_allow_html=True) st.write(f"Ask any question about World Cup history and get an AI-powered answer!") # Book Series Section - Toward World Cup 2026 (Clean Integration) # Header with NEW badge and title col1, col2 = st.columns([1, 4]) with col1: st.markdown('
📚 NEW
', unsafe_allow_html=True) with col2: st.markdown('

Book Series: Toward World Cup 2026

', unsafe_allow_html=True) # Book description st.markdown('

Book 1: Lamine Yamal - A Golden Boy Who Becomes a Record-Breaking Star: Lessons for Kids

', unsafe_allow_html=True) # Buttons and teaser col1, col2, col3 = st.columns([1, 1, 2]) with col1: st.link_button("🛒 Amazon", "https://www.amazon.com/Yamal-Golden-Becomes-Record-Breaking-Lessons/dp/B0DPCRK64H/ref=tmm_pap_swatch_0?_encoding=UTF8&dib_tag=se&dib=eyJ2IjoiMSJ9.oXOBH7gVGsbO-2qUWdAdBA.qtAKMcQoOdUgIdIDUHYywjKRDvtOJsZTgn5Pe6ds7bo&qid=1755559111&sr=8-1", use_container_width=True) with col2: st.link_button("📖 Blog", "https://dzungdoan.com/2025/08/18/toward-world-cup-2026-book-series-first-book-lamine-yamal/", use_container_width=True) with col3: st.markdown('

More books coming soon! 🚀

', unsafe_allow_html=True) # Background music (always visible audio player) # Removed HEAD request for security - just embed directly st.markdown(f"""

🎵 Background Music

World Cup 1990 Theme

""", unsafe_allow_html=True) # Fetch available prompts from MCP server @st.cache_data(ttl=300) # Cache for 5 minutes def get_available_prompts(): """Fetch available prompts from MCP server""" try: response = requests.get(f"{MCP_SERVER_URL}/prompts", timeout=5) if response.status_code == 200: return response.json().get("prompts", []) else: return [] except Exception as e: st.warning(f"Could not fetch prompts: {e}") return [] # Get prompts prompts = get_available_prompts() # Main layout with input and prompts side by side col1, col2 = st.columns([2, 1]) # 2:1 ratio for better space utilization in wide layout with col1: # Main input area with form for proper submission with st.form(key="question_form", clear_on_submit=True): user_input = st.text_area("Your question:", height=100, placeholder="Type your question here...") submit_button = st.form_submit_button("Ask") if submit_button and user_input: with st.spinner("Thinking..."): try: # Get API key from environment (optional for local development) api_key = os.getenv("AGENT_API_KEY") headers = {} if api_key: # Production mode - include API key headers = {"Authorization": f"Bearer {api_key}"} else: # Local development mode - no API key required st.info("🔓 Local development mode - no API key required") response = requests.post( f"{AGENT_URL}/ask", json={"question": user_input}, headers=headers, timeout=15 ) response.raise_for_status() answer = response.json().get("answer", "No answer received.") except Exception as e: answer = f"Error: {e}" st.session_state.chat_history.append((user_input, answer)) # Chat history if st.session_state.chat_history: st.subheader("Chat History") for q, a in reversed(st.session_state.chat_history): st.markdown(f"**You:** {q}") st.markdown(f"**AI:** {a}") st.markdown("---") with col2: # Display prompts if available if prompts: st.markdown("### 💡 **What can I help you with?**") for prompt in prompts: with st.container(): # Highlight placeholders in templates templates_html = "" for template in prompt['templates']: # Replace [placeholder] with highlighted version highlighted_template = template.replace('[', '[').replace(']', ']') templates_html += f'
💬 {highlighted_template}
' st.markdown(f"""
{prompt['title']}
{prompt['description']}
{templates_html}
""", unsafe_allow_html=True)