Update app.py
Browse files
app.py
CHANGED
@@ -97,8 +97,128 @@ Format your answer with clear headings and subheadings. Use markdown formatting
|
|
97 |
except Exception as e:
|
98 |
return f"Error: {str(e)}"
|
99 |
|
100 |
-
#
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
gr.Markdown("""
|
103 |
# π Competitive Programming Assistant
|
104 |
|
@@ -169,6 +289,30 @@ with gr.Blocks(title="Competitive Programming Assistant", theme=gr.themes.Soft()
|
|
169 |
inputs=[problem_input, language, api_key_input],
|
170 |
outputs=solution_output
|
171 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
# Launch the app
|
174 |
if __name__ == "__main__":
|
|
|
97 |
except Exception as e:
|
98 |
return f"Error: {str(e)}"
|
99 |
|
100 |
+
# Custom CSS for dark mode toggle and styling
|
101 |
+
custom_css = """
|
102 |
+
.dark-mode {
|
103 |
+
--color-background: #1a1a1a;
|
104 |
+
--color-text: #ffffff;
|
105 |
+
--color-border: #444444;
|
106 |
+
--color-accent: #3d85c6;
|
107 |
+
--color-input-background: #2d2d2d;
|
108 |
+
--color-button: #3d85c6;
|
109 |
+
--color-button-hover: #5699d8;
|
110 |
+
}
|
111 |
+
|
112 |
+
.light-mode {
|
113 |
+
--color-background: #ffffff;
|
114 |
+
--color-text: #333333;
|
115 |
+
--color-border: #dddddd;
|
116 |
+
--color-accent: #2e67a9;
|
117 |
+
--color-input-background: #f9f9f9;
|
118 |
+
--color-button: #2e67a9;
|
119 |
+
--color-button-hover: #4a7dbd;
|
120 |
+
}
|
121 |
+
|
122 |
+
body.dark-mode {
|
123 |
+
background-color: var(--color-background);
|
124 |
+
color: var(--color-text);
|
125 |
+
}
|
126 |
+
|
127 |
+
body.light-mode {
|
128 |
+
background-color: var(--color-background);
|
129 |
+
color: var(--color-text);
|
130 |
+
}
|
131 |
+
|
132 |
+
.theme-toggle {
|
133 |
+
display: flex;
|
134 |
+
align-items: center;
|
135 |
+
justify-content: flex-end;
|
136 |
+
padding: 8px 16px;
|
137 |
+
}
|
138 |
+
|
139 |
+
.theme-toggle button {
|
140 |
+
background-color: var(--color-button);
|
141 |
+
color: white;
|
142 |
+
border: none;
|
143 |
+
padding: 8px 16px;
|
144 |
+
border-radius: 4px;
|
145 |
+
cursor: pointer;
|
146 |
+
transition: background-color 0.3s;
|
147 |
+
}
|
148 |
+
|
149 |
+
.theme-toggle button:hover {
|
150 |
+
background-color: var(--color-button-hover);
|
151 |
+
}
|
152 |
+
|
153 |
+
.gradio-container {
|
154 |
+
background-color: var(--color-background) !important;
|
155 |
+
color: var(--color-text) !important;
|
156 |
+
}
|
157 |
+
|
158 |
+
.dark-mode .gradio-container textarea,
|
159 |
+
.dark-mode .gradio-container input {
|
160 |
+
background-color: var(--color-input-background) !important;
|
161 |
+
color: var(--color-text) !important;
|
162 |
+
border-color: var(--color-border) !important;
|
163 |
+
}
|
164 |
+
|
165 |
+
.dark-mode .gradio-markdown {
|
166 |
+
color: var(--color-text) !important;
|
167 |
+
}
|
168 |
+
|
169 |
+
.dark-mode .gradio-button {
|
170 |
+
background-color: var(--color-button) !important;
|
171 |
+
}
|
172 |
+
|
173 |
+
.dark-mode .gradio-button:hover {
|
174 |
+
background-color: var(--color-button-hover) !important;
|
175 |
+
}
|
176 |
+
"""
|
177 |
+
|
178 |
+
# JavaScript for theme toggle functionality
|
179 |
+
theme_toggle_js = """
|
180 |
+
function toggleTheme() {
|
181 |
+
const body = document.body;
|
182 |
+
if (body.classList.contains('light-mode')) {
|
183 |
+
body.classList.remove('light-mode');
|
184 |
+
body.classList.add('dark-mode');
|
185 |
+
localStorage.setItem('theme', 'dark');
|
186 |
+
document.getElementById('theme-toggle-btn').textContent = 'βοΈ Light Mode';
|
187 |
+
} else {
|
188 |
+
body.classList.remove('dark-mode');
|
189 |
+
body.classList.add('light-mode');
|
190 |
+
localStorage.setItem('theme', 'light');
|
191 |
+
document.getElementById('theme-toggle-btn').textContent = 'π Dark Mode';
|
192 |
+
}
|
193 |
+
}
|
194 |
+
|
195 |
+
document.addEventListener('DOMContentLoaded', function() {
|
196 |
+
const savedTheme = localStorage.getItem('theme') || 'light';
|
197 |
+
document.body.classList.add(savedTheme + '-mode');
|
198 |
+
|
199 |
+
const themeToggleBtn = document.getElementById('theme-toggle-btn');
|
200 |
+
if (themeToggleBtn) {
|
201 |
+
themeToggleBtn.textContent = savedTheme === 'dark' ? 'βοΈ Light Mode' : 'π Dark Mode';
|
202 |
+
themeToggleBtn.addEventListener('click', toggleTheme);
|
203 |
+
}
|
204 |
+
});
|
205 |
+
"""
|
206 |
+
|
207 |
+
# Create a Gradio interface with theme support
|
208 |
+
with gr.Blocks(title="Competitive Programming Assistant",
|
209 |
+
theme=gr.themes.Soft(),
|
210 |
+
css=custom_css) as app:
|
211 |
+
|
212 |
+
# Add JavaScript for theme toggle
|
213 |
+
gr.HTML(f"""
|
214 |
+
<script>
|
215 |
+
{theme_toggle_js}
|
216 |
+
</script>
|
217 |
+
<div class="theme-toggle">
|
218 |
+
<button id="theme-toggle-btn">π Dark Mode</button>
|
219 |
+
</div>
|
220 |
+
""")
|
221 |
+
|
222 |
gr.Markdown("""
|
223 |
# π Competitive Programming Assistant
|
224 |
|
|
|
289 |
inputs=[problem_input, language, api_key_input],
|
290 |
outputs=solution_output
|
291 |
)
|
292 |
+
|
293 |
+
# Initialize theme based on user preference or system default
|
294 |
+
gr.HTML("""
|
295 |
+
<script>
|
296 |
+
document.addEventListener('DOMContentLoaded', function() {
|
297 |
+
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
298 |
+
const savedTheme = localStorage.getItem('theme');
|
299 |
+
|
300 |
+
if (savedTheme) {
|
301 |
+
document.body.classList.add(savedTheme + '-mode');
|
302 |
+
if (savedTheme === 'dark') {
|
303 |
+
document.getElementById('theme-toggle-btn').textContent = 'βοΈ Light Mode';
|
304 |
+
}
|
305 |
+
} else if (prefersDarkMode) {
|
306 |
+
document.body.classList.add('dark-mode');
|
307 |
+
localStorage.setItem('theme', 'dark');
|
308 |
+
document.getElementById('theme-toggle-btn').textContent = 'βοΈ Light Mode';
|
309 |
+
} else {
|
310 |
+
document.body.classList.add('light-mode');
|
311 |
+
localStorage.setItem('theme', 'light');
|
312 |
+
}
|
313 |
+
});
|
314 |
+
</script>
|
315 |
+
""")
|
316 |
|
317 |
# Launch the app
|
318 |
if __name__ == "__main__":
|