Force dark theme on the Gradio login page

This commit is contained in:
oobabooga 2025-06-19 12:03:19 -07:00
parent 645463b9f0
commit 3344510553
2 changed files with 30 additions and 0 deletions

View file

@ -351,3 +351,25 @@ function handleMorphdomUpdate(data) {
}
});
}
// Wait for Gradio to finish setting its styles, then force dark theme
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' &&
mutation.target.tagName === 'GRADIO-APP' &&
mutation.attributeName === 'style') {
// Gradio just set its styles, now force dark theme
document.body.classList.add('dark');
observer.disconnect();
}
});
});
// Start observing
observer.observe(document.documentElement, {
attributes: true,
subtree: true,
attributeFilter: ['style']
});

View file

@ -1,5 +1,6 @@
import builtins
import io
import re
import requests
@ -62,6 +63,13 @@ def my_open(*args, **kwargs):
'\n </head>'
)
file_contents = re.sub(
r'@media \(prefers-color-scheme: dark\) \{\s*body \{([^}]*)\}\s*\}',
r'body.dark {\1}',
file_contents,
flags=re.DOTALL
)
if len(args) > 1 and args[1] == 'rb':
file_contents = file_contents.encode('utf-8')
return io.BytesIO(file_contents)