maria355 commited on
Commit
902a263
·
verified ·
1 Parent(s): 260fa6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -133
app.py CHANGED
@@ -1167,8 +1167,8 @@ def create_chatbot():
1167
 
1168
  # Create CSS with theme variables
1169
  custom_css = """
1170
- /* Theme variables - will be applied based on user's theme preference */
1171
- .light-theme {
1172
  --primary-color: #4a6fa5;
1173
  --secondary-color: #6c757d;
1174
  --success-color: #28a745;
@@ -1183,41 +1183,21 @@ def create_chatbot():
1183
  --info-box-bg: #e7f5fe;
1184
  }
1185
 
1186
- .dark-theme {
1187
- --primary-color: #5b88c7;
1188
- --secondary-color: #adb5bd;
1189
- --success-color: #48c774;
1190
- --bg-color: #1a1a1a;
1191
- --text-color: #f1f1f1;
1192
- --card-bg: #2d2d2d;
1193
- --card-border: #444444;
1194
- --input-bg: #333333;
1195
- --highlight-color: #193652;
1196
- --accent-color: #3291ff;
1197
- --completed-color: #204829;
1198
- --info-box-bg: #193652;
1199
- }
1200
-
1201
- /* Automatically detect theme preference and apply appropriate theme class */
1202
  @media (prefers-color-scheme: dark) {
1203
- body {
1204
- color-scheme: dark;
1205
- }
1206
-
1207
- body:not(.light-theme):not(.force-light) {
1208
- background-color: var(--bg-color);
1209
- color: var(--text-color);
1210
- }
1211
- }
1212
-
1213
- @media (prefers-color-scheme: light) {
1214
- body {
1215
- color-scheme: light;
1216
- }
1217
-
1218
- body:not(.dark-theme):not(.force-dark) {
1219
- background-color: var(--bg-color);
1220
- color: var(--text-color);
1221
  }
1222
  }
1223
 
@@ -1358,43 +1338,42 @@ def create_chatbot():
1358
  }
1359
  """
1360
 
1361
- # JavaScript to detect and apply theme
1362
  theme_script = """
1363
  <script>
1364
- // Function to detect and apply theme
1365
- function applyTheme() {
1366
- // Check if user has a saved preference
1367
- const savedTheme = localStorage.getItem('preferredTheme');
1368
-
1369
- if (savedTheme) {
1370
- // Apply saved preference
1371
- document.body.classList.add(savedTheme + '-theme');
1372
- } else {
1373
- // Check system preference
1374
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
1375
- document.body.classList.add('dark-theme');
1376
- } else {
1377
- document.body.classList.add('light-theme');
1378
- }
 
 
 
 
 
 
 
 
 
 
1379
  }
1380
 
1381
- // Listen for theme changes
1382
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
1383
- // Only apply if no saved preference
1384
- if (!savedTheme) {
1385
- document.body.classList.remove('light-theme', 'dark-theme');
1386
- document.body.classList.add(event.matches ? 'dark-theme' : 'light-theme');
1387
- }
1388
- });
1389
- }
1390
-
1391
- // Apply theme when DOM is loaded
1392
- document.addEventListener('DOMContentLoaded', applyTheme);
1393
-
1394
- // For Gradio that might load content dynamically
1395
- if (document.readyState === 'complete' || document.readyState === 'interactive') {
1396
- setTimeout(applyTheme, 1);
1397
- }
1398
  </script>
1399
  """
1400
 
@@ -1515,70 +1494,6 @@ def create_chatbot():
1515
 
1516
  generate_plan_btn = gr.Button("Generate Study Plan", variant="primary")
1517
  plan_output = gr.Markdown(label="Personalized Study Plan")
1518
-
1519
- # Theme Selector Tab (New)
1520
- with gr.Tab("Settings"):
1521
- with gr.Column(elem_classes=["card"]):
1522
- gr.HTML("<h3>App Settings</h3>")
1523
-
1524
- theme_selector = gr.Radio(
1525
- choices=["System Default", "Light Theme", "Dark Theme"],
1526
- label="Theme Preference",
1527
- value="System Default"
1528
- )
1529
-
1530
- # Add JavaScript to handle theme changes
1531
- theme_js = """
1532
- <script>
1533
- // Get the radio input once it exists
1534
- function setupThemeSelector() {
1535
- const radioInputs = document.querySelectorAll('input[type="radio"][name="theme"]');
1536
- if (radioInputs.length === 0) {
1537
- setTimeout(setupThemeSelector, 300);
1538
- return;
1539
- }
1540
-
1541
- // Set initial value based on stored preference
1542
- const savedTheme = localStorage.getItem('preferredTheme');
1543
- if (savedTheme === 'light') {
1544
- radioInputs[1].checked = true;
1545
- } else if (savedTheme === 'dark') {
1546
- radioInputs[2].checked = true;
1547
- } else {
1548
- radioInputs[0].checked = true;
1549
- }
1550
-
1551
- // Add event listeners
1552
- radioInputs.forEach(input => {
1553
- input.addEventListener('change', function() {
1554
- const body = document.body;
1555
- body.classList.remove('light-theme', 'dark-theme', 'force-light', 'force-dark');
1556
-
1557
- if (this.value === "Light Theme") {
1558
- body.classList.add('light-theme', 'force-light');
1559
- localStorage.setItem('preferredTheme', 'light');
1560
- } else if (this.value === "Dark Theme") {
1561
- body.classList.add('dark-theme', 'force-dark');
1562
- localStorage.setItem('preferredTheme', 'dark');
1563
- } else {
1564
- localStorage.removeItem('preferredTheme');
1565
- applyTheme(); // Reapply system theme
1566
- }
1567
- });
1568
- });
1569
- }
1570
-
1571
- // Start setup
1572
- setupThemeSelector();
1573
- </script>
1574
- """
1575
- gr.HTML(theme_js)
1576
-
1577
- gr.HTML("""
1578
- <div class="info-box">
1579
- <p>These settings will be saved in your browser for future visits.</p>
1580
- </div>
1581
- """)
1582
 
1583
  gr.HTML("""<div class="footer">
1584
  AI Teaching Assistant | Version 2.0 | © 2025 | Powered by Groq AI
 
1167
 
1168
  # Create CSS with theme variables
1169
  custom_css = """
1170
+ /* Base variable definitions that work across themes */
1171
+ :root {
1172
  --primary-color: #4a6fa5;
1173
  --secondary-color: #6c757d;
1174
  --success-color: #28a745;
 
1183
  --info-box-bg: #e7f5fe;
1184
  }
1185
 
1186
+ /* Dark mode overrides */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
  @media (prefers-color-scheme: dark) {
1188
+ :root {
1189
+ --primary-color: #5b88c7; /* Lighter blue for better visibility */
1190
+ --secondary-color: #adb5bd; /* Lighter gray for better visibility */
1191
+ --success-color: #48c774; /* Brighter green for dark mode */
1192
+ --bg-color: #1a1a1a; /* Dark background */
1193
+ --text-color: #f1f1f1; /* Light text for dark backgrounds */
1194
+ --card-bg: #2d2d2d; /* Dark card background */
1195
+ --card-border: #444444; /* Dark border */
1196
+ --input-bg: #333333; /* Dark input background */
1197
+ --highlight-color: #193652; /* Dark highlight */
1198
+ --accent-color: #3291ff; /* Bright accent */
1199
+ --completed-color: #204829; /* Dark green for completed */
1200
+ --info-box-bg: #193652; /* Dark info box */
 
 
 
 
 
1201
  }
1202
  }
1203
 
 
1338
  }
1339
  """
1340
 
1341
+ # JavaScript to detect and apply theme - simplified version without manual toggle
1342
  theme_script = """
1343
  <script>
1344
+ // Simple script to ensure proper theme handling on Hugging Face
1345
+ document.addEventListener('DOMContentLoaded', function() {
1346
+ // Force update of any elements that might not respect theme automatically
1347
+ function updateElementsForTheme() {
1348
+ const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
1349
+
1350
+ // Force any specific elements that might need extra help
1351
+ const codeBlocks = document.querySelectorAll('pre code');
1352
+ codeBlocks.forEach(block => {
1353
+ block.style.color = isDarkMode ? '#f1f1f1' : '#212529';
1354
+ block.style.backgroundColor = isDarkMode ? '#2d2d2d' : '#f8f9fa';
1355
+ });
1356
+
1357
+ // Ensure markdown-rendered content is visible
1358
+ const markdownContent = document.querySelectorAll('.prose *');
1359
+ markdownContent.forEach(element => {
1360
+ // Skip elements that already have specific styling
1361
+ if (element.tagName === 'A' ||
1362
+ element.tagName.match(/^H[1-6]$/) ||
1363
+ element.tagName === 'CODE') {
1364
+ return;
1365
+ }
1366
+
1367
+ element.style.color = isDarkMode ? '#f1f1f1' : '#212529';
1368
+ });
1369
  }
1370
 
1371
+ // Run once on load
1372
+ updateElementsForTheme();
1373
+
1374
+ // Also update when system theme changes
1375
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateElementsForTheme);
1376
+ });
 
 
 
 
 
 
 
 
 
 
 
1377
  </script>
1378
  """
1379
 
 
1494
 
1495
  generate_plan_btn = gr.Button("Generate Study Plan", variant="primary")
1496
  plan_output = gr.Markdown(label="Personalized Study Plan")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1497
 
1498
  gr.HTML("""<div class="footer">
1499
  AI Teaching Assistant | Version 2.0 | © 2025 | Powered by Groq AI