Spaces:
Running on Zero
Running on Zero
fix: move bridge JS to demo.load() script in gr.HTML never executed
Browse files
app.py
CHANGED
|
@@ -301,14 +301,7 @@ def submit_answer(question, chunk, student_answer, correct, total, language):
|
|
| 301 |
# UI
|
| 302 |
# ---------------------------------------------------------------------------
|
| 303 |
|
| 304 |
-
|
| 305 |
-
with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
| 306 |
-
|
| 307 |
-
gr.HTML(CUSTOM_HTML)
|
| 308 |
-
|
| 309 |
-
gr.HTML("""
|
| 310 |
-
<script>
|
| 311 |
-
(function() {
|
| 312 |
let lastStatus = '';
|
| 313 |
let quizRevealed = false;
|
| 314 |
|
|
@@ -328,13 +321,10 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
|
| 328 |
ensureStatusBar();
|
| 329 |
const bar = document.getElementById('gradio-status-bar');
|
| 330 |
if (!bar) return;
|
| 331 |
-
|
| 332 |
bar.textContent = text;
|
| 333 |
bar.style.display = 'block';
|
| 334 |
-
|
| 335 |
-
const
|
| 336 |
-
const isSuccess = text.includes('π') || text.includes('sections') || text.includes('extraites') || text.includes('extracted');
|
| 337 |
-
|
| 338 |
if (isError) {
|
| 339 |
bar.style.background = 'rgba(239,68,68,0.12)';
|
| 340 |
bar.style.border = '1px solid rgba(239,68,68,0.3)';
|
|
@@ -343,7 +333,6 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
|
| 343 |
bar.style.background = 'rgba(16,185,129,0.12)';
|
| 344 |
bar.style.border = '1px solid rgba(16,185,129,0.3)';
|
| 345 |
bar.style.color = '#6EE7B7';
|
| 346 |
-
|
| 347 |
if (!quizRevealed) {
|
| 348 |
quizRevealed = true;
|
| 349 |
const quizCard = document.getElementById('quiz-card');
|
|
@@ -351,7 +340,6 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
|
| 351 |
quizCard.classList.remove('hidden');
|
| 352 |
setTimeout(() => quizCard.scrollIntoView({ behavior: 'smooth', block: 'start' }), 400);
|
| 353 |
}
|
| 354 |
-
// Recede upload row
|
| 355 |
const uploadRow = document.getElementById('upload-row');
|
| 356 |
if (uploadRow) {
|
| 357 |
uploadRow.style.opacity = '0.5';
|
|
@@ -367,15 +355,19 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
|
| 367 |
}
|
| 368 |
}
|
| 369 |
|
| 370 |
-
// Poll every
|
| 371 |
-
// which
|
| 372 |
setInterval(function() {
|
| 373 |
const el = document.querySelector('#hidden-status-output textarea');
|
| 374 |
if (el && el.value) applyStatus(el.value);
|
| 375 |
}, 300);
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
chunks_state = gr.State([])
|
| 381 |
chunk_state = gr.State("")
|
|
|
|
| 301 |
# UI
|
| 302 |
# ---------------------------------------------------------------------------
|
| 303 |
|
| 304 |
+
BRIDGE_JS = """() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
let lastStatus = '';
|
| 306 |
let quizRevealed = false;
|
| 307 |
|
|
|
|
| 321 |
ensureStatusBar();
|
| 322 |
const bar = document.getElementById('gradio-status-bar');
|
| 323 |
if (!bar) return;
|
|
|
|
| 324 |
bar.textContent = text;
|
| 325 |
bar.style.display = 'block';
|
| 326 |
+
const isError = text.includes('\\u26a0') || text.toLowerCase().includes('erreur');
|
| 327 |
+
const isSuccess = text.includes('sections') || text.includes('extraites') || text.includes('extracted') || text.includes('\\ud83d\\udcda');
|
|
|
|
|
|
|
| 328 |
if (isError) {
|
| 329 |
bar.style.background = 'rgba(239,68,68,0.12)';
|
| 330 |
bar.style.border = '1px solid rgba(239,68,68,0.3)';
|
|
|
|
| 333 |
bar.style.background = 'rgba(16,185,129,0.12)';
|
| 334 |
bar.style.border = '1px solid rgba(16,185,129,0.3)';
|
| 335 |
bar.style.color = '#6EE7B7';
|
|
|
|
| 336 |
if (!quizRevealed) {
|
| 337 |
quizRevealed = true;
|
| 338 |
const quizCard = document.getElementById('quiz-card');
|
|
|
|
| 340 |
quizCard.classList.remove('hidden');
|
| 341 |
setTimeout(() => quizCard.scrollIntoView({ behavior: 'smooth', block: 'start' }), 400);
|
| 342 |
}
|
|
|
|
| 343 |
const uploadRow = document.getElementById('upload-row');
|
| 344 |
if (uploadRow) {
|
| 345 |
uploadRow.style.opacity = '0.5';
|
|
|
|
| 355 |
}
|
| 356 |
}
|
| 357 |
|
| 358 |
+
// Poll every 300 ms β Svelte sets textarea.value as a JS property
|
| 359 |
+
// which characterData MutationObserver does not catch.
|
| 360 |
setInterval(function() {
|
| 361 |
const el = document.querySelector('#hidden-status-output textarea');
|
| 362 |
if (el && el.value) applyStatus(el.value);
|
| 363 |
}, 300);
|
| 364 |
+
}"""
|
| 365 |
+
|
| 366 |
+
print("β
Starting Gradio app...")
|
| 367 |
+
with gr.Blocks(title="PaperProf", css=CSS) as demo:
|
| 368 |
+
|
| 369 |
+
gr.HTML(CUSTOM_HTML)
|
| 370 |
+
demo.load(None, js=BRIDGE_JS)
|
| 371 |
|
| 372 |
chunks_state = gr.State([])
|
| 373 |
chunk_state = gr.State("")
|