Spaces:
Running

File size: 12,580 Bytes
75b8f35
 
a2ea301
75b8f35
a2ea301
e251b13
75b8f35
 
 
e251b13
 
 
 
75b8f35
e251b13
 
 
75b8f35
de7b50a
 
 
a94b3eb
0ccae14
a94b3eb
 
 
 
75b8f35
a2ea301
75b8f35
 
 
a2ea301
a94b3eb
 
3bc2c1e
 
 
 
 
 
 
 
a2ea301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a94b3eb
a2ea301
 
 
 
 
 
 
a94b3eb
 
a2ea301
 
 
 
a94b3eb
a2ea301
a94b3eb
 
a2ea301
 
 
a94b3eb
a2ea301
a94b3eb
a2ea301
 
 
 
a94b3eb
a2ea301
a94b3eb
 
a2ea301
 
 
 
 
 
 
a94b3eb
a2ea301
a94b3eb
 
 
 
a2ea301
f0f3f41
a2ea301
f0f3f41
584040f
f0f3f41
 
 
 
 
 
 
 
 
 
584040f
 
f0f3f41
 
 
 
 
 
 
 
 
 
 
 
 
 
584040f
a2ea301
 
 
 
 
 
 
 
 
 
 
ae59194
 
 
 
 
 
 
 
 
 
a2ea301
 
ae59194
 
 
 
a2ea301
500bf83
 
 
 
 
 
 
 
3dbb569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a94b3eb
 
 
500bf83
a2ea301
0ccae14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a1a956
0ccae14
e251b13
d2f93a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e251b13
 
a2ea301
fa61279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dbb569
a2ea301
38a89a1
 
 
 
 
 
 
 
 
 
 
a2ea301
a94b3eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae59194
 
 
 
 
 
a94b3eb
 
de7b50a
 
 
 
 
 
 
 
 
 
 
a94b3eb
 
 
de7b50a
a94b3eb
 
 
 
 
 
 
 
ae59194
a94b3eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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("""
<style>
/* Force white background for HF Spaces compatibility */
.stApp, .main, [data-testid="stAppViewContainer"], [data-testid="stHeader"] {
    background: #FFFFFF !important;
}

/* Main background with World Cup theme - more specific selectors */
.main, [data-testid="stAppViewContainer"] > .main {
    background: #FFFFFF !important;
    min-height: 100vh;
}

/* Overlay for better text readability */
.main::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: -1;
}

/* Enhanced prompt cards */
.prompt-card {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #ffd700;
    border-radius: 12px;
    padding: 16px;
    margin: 8px 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.prompt-card:hover {
    background: rgba(255, 255, 255, 1);
    border-color: #ffed4e;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.prompt-title {
    font-weight: bold;
    color: #1e3c72;
    margin-bottom: 6px;
    font-size: 1.1em;
}

.prompt-description {
    color: #495057;
    font-size: 0.9em;
    margin-bottom: 8px;
    line-height: 1.3;
}

.prompt-template {
    color: #007bff;
    font-size: 0.85em;
    background: rgba(0, 123, 255, 0.1);
    padding: 6px 10px;
    border-radius: 6px;
    margin: 4px 0;
    border-left: 4px solid #007bff;
    line-height: 1.4;
}

.prompt-template-placeholder {
    color: #dc3545;
    font-weight: bold;
}

/* Enhanced title styling - Cross-browser compatible for HF Spaces */
.main-title {
    /* Use solid gold color that works everywhere */
    color: #ffd700 !important;
    /* Multiple text shadows for depth and glow effect */
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.8),
        0 0 10px rgba(255, 215, 0, 0.5),
        0 0 20px rgba(255, 215, 0, 0.3),
        3px 3px 6px rgba(45, 95, 63, 0.6) !important;
    font-weight: 900 !important;
    font-size: 2.5rem !important;
    /* Add subtle animation */
    animation: goldenGlow 3s ease-in-out infinite alternate;
}

@keyframes goldenGlow {
    from {
        text-shadow: 
            2px 2px 4px rgba(0, 0, 0, 0.8),
            0 0 10px rgba(255, 215, 0, 0.5),
            0 0 20px rgba(255, 215, 0, 0.3),
            3px 3px 6px rgba(45, 95, 63, 0.6);
    }
    to {
        text-shadow: 
            2px 2px 4px rgba(0, 0, 0, 0.8),
            0 0 15px rgba(255, 215, 0, 0.7),
            0 0 30px rgba(255, 215, 0, 0.5),
            3px 3px 8px rgba(45, 95, 63, 0.8);
    }
}

/* Enhanced input area */
.stTextArea textarea {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #ffd700;
    border-radius: 8px;
    font-size: 16px;
}

/* Enhanced button styling */
.stButton > button, .stFormSubmitButton > button {
    background: linear-gradient(45deg, #ffd700, #ffed4e) !important;
    border: none !important;
    border-radius: 8px !important;
    color: #1e3c72 !important;
    font-weight: bold !important;
    padding: 10px 20px !important;
    transition: all 0.3s ease !important;
    width: auto !important;
    max-width: 200px !important;
}

.stButton > button:hover, .stFormSubmitButton > button:hover {
    background: linear-gradient(45deg, #ffed4e, #ffd700) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4) !important;
}

/* Custom key handler styles */
#submit-hint {
    font-size: 0.8em;
    color: #666;
    margin-top: 5px;
    font-style: italic;
}

/* Book series section responsive design */
@media (max-width: 768px) {
    .book-series-container {
        padding: 15px !important;
        margin: 15px 0 !important;
    }
    
    .book-series-title {
        font-size: 1.5em !important;
    }
    
    .book-series-buttons {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .book-series-button {
        width: 100% !important;
        text-align: center !important;
    }
}

/* Enhanced book series styling for better visibility */
.book-series-section {
    animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hover effects for book series elements */
.book-series-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}
</style>
""", unsafe_allow_html=True)


# Main content with enhanced styling
st.markdown('''
<div style="display: flex; align-items: center; justify-content: center; gap: 15px;">
    <h1 class="main-title" style="margin: 0;">πŸ† World Cup AI Assistant</h1>
    <span style="
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 5px 15px;
        border-radius: 20px;
        font-size: 14px;
        font-weight: bold;
        position: relative;
        top: -10px;
    ">BETA</span>
</div>
''', 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"""
    <div style="display: inline-block; margin-bottom: 15px;">
        <span style="
            background: {env_info['color']}; 
            color: white; 
            padding: 4px 12px; 
            border-radius: 20px; 
            font-size: 0.8em; 
            font-weight: bold;
            display: inline-flex;
            align-items: center;
            gap: 5px;
        ">
            {env_info['icon']} {env_info['name']}
        </span>
        <span style="
            color: #6c757d; 
            font-size: 0.8em; 
            margin-left: 10px;
            font-style: italic;
        ">
            {env_info['description']}
        </span>
    </div>
    """, 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('<div style="background: #ffd700; color: #1e3c72; padding: 4px 8px; border-radius: 12px; font-size: 0.7em; font-weight: bold; text-align: center;">πŸ“š NEW</div>', unsafe_allow_html=True)
with col2:
    st.markdown('<h4 style="color: #495057; margin: 0; font-size: 1.1em; font-weight: 600;">Book Series: Toward World Cup 2026</h4>', unsafe_allow_html=True)

# Book description
st.markdown('<p style="color: #6c757d; margin: 10px 0; font-size: 0.9em; line-height: 1.4;"><strong>Book 1: Lamine Yamal</strong> - A Golden Boy Who Becomes a Record-Breaking Star: Lessons for Kids</p>', 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('<p style="color: #6c757d; font-size: 0.8em; font-style: italic; margin: 0; padding: 8px 0;">More books coming soon! πŸš€</p>', unsafe_allow_html=True)

# Background music (always visible audio player)
# Removed HEAD request for security - just embed directly
st.markdown(f"""
<div style="margin: 10px 0; padding: 15px; background: #f8f9fa; border-radius: 8px; border: 1px solid #dee2e6;">
    <h4 style="margin: 0 0 10px 0; color: #495057;">🎡 Background Music</h4>
    <audio controls style="width: 100%;">
        <source src="{AUDIO_URLS['world_cup_1990_theme']}" type="audio/mp3">
        Your browser does not support the audio element.
    </audio>
    <p style="margin: 5px 0 0 0; font-size: 0.8em; color: #6c757d;">World Cup 1990 Theme</p>
</div>
""", 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('[', '<span class="prompt-template-placeholder">[').replace(']', ']</span>')
                    templates_html += f'<div class="prompt-template">πŸ’¬ {highlighted_template}</div>'
                
                st.markdown(f"""
                <div class="prompt-card">
                    <div class="prompt-title">{prompt['title']}</div>
                    <div class="prompt-description">{prompt['description']}</div>
                    {templates_html}
                </div>
                """, unsafe_allow_html=True)