Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -227,10 +227,10 @@ HTML_UI = """
|
|
| 227 |
const data = await res.json();
|
| 228 |
const ms = Math.round(performance.now() - t0);
|
| 229 |
if (res.ok) {
|
| 230 |
-
appendOutput(`[${ms}ms]\n${data.generated_text || JSON.stringify(data, null, 2)}\n\n`, true);
|
| 231 |
setStatus(`OK — ${ms}ms`);
|
| 232 |
} else {
|
| 233 |
-
appendOutput(`Error ${res.status}:\n${JSON.stringify(data, null, 2)}\n\n`, true);
|
| 234 |
setStatus(`HTTP ${res.status}`, true);
|
| 235 |
}
|
| 236 |
}
|
|
@@ -246,17 +246,17 @@ HTML_UI = """
|
|
| 246 |
const data = await res.json();
|
| 247 |
const ms = Math.round(performance.now() - t0);
|
| 248 |
if (res.ok) {
|
| 249 |
-
let text = `[${ms}ms]\nGenerated text:\n${data.generated_text}\n\n`;
|
| 250 |
if (data.intermediate_states && data.intermediate_states.length) {
|
| 251 |
-
text += `Intermediate states (${data.intermediate_states.length}):\n`;
|
| 252 |
data.intermediate_states.forEach((s, i) => {
|
| 253 |
text += " Step " + s.step + ": " + s.text.substring(0,120).replace(/\\n/g, ' ') + "...\\n";
|
| 254 |
});
|
| 255 |
}
|
| 256 |
-
appendOutput(text + '\n', true);
|
| 257 |
setStatus(`OK — ${ms}ms, ${data.intermediate_states?.length || 0} intermediates`);
|
| 258 |
} else {
|
| 259 |
-
appendOutput(`Error ${res.status}:\n${JSON.stringify(data, null, 2)}\n\n`, true);
|
| 260 |
setStatus(`HTTP ${res.status}`, true);
|
| 261 |
}
|
| 262 |
}
|
|
@@ -275,7 +275,7 @@ HTML_UI = """
|
|
| 275 |
|
| 276 |
if (!res.ok) {
|
| 277 |
const data = await res.json().catch(() => ({}));
|
| 278 |
-
appendOutput(`Error ${res.status}:\n${JSON.stringify(data, null, 2)}`, true);
|
| 279 |
setStatus(`HTTP ${res.status}`, true);
|
| 280 |
return;
|
| 281 |
}
|
|
@@ -290,7 +290,7 @@ HTML_UI = """
|
|
| 290 |
const { done, value } = await reader.read();
|
| 291 |
if (done) break;
|
| 292 |
buffer += decoder.decode(value, { stream: true });
|
| 293 |
-
const lines = buffer.split('\n');
|
| 294 |
buffer = lines.pop(); // keep incomplete line in buffer
|
| 295 |
|
| 296 |
for (const line of lines) {
|
|
@@ -303,7 +303,7 @@ HTML_UI = """
|
|
| 303 |
if (event.type === 'final') {
|
| 304 |
finalText = event.text;
|
| 305 |
const ms = Math.round(performance.now() - t0);
|
| 306 |
-
appendOutput(`[${ms}ms | ${eventCount} events]\n${finalText}\n`, true);
|
| 307 |
setStatus(`Done — ${ms}ms, ${eventCount} events, ${event.total_steps || '?'} steps`);
|
| 308 |
} else if (event.type === 'intermediate' || event.type === 'token') {
|
| 309 |
// Live update: overwrite with latest accumulated text
|
|
@@ -330,7 +330,7 @@ HTML_UI = """
|
|
| 330 |
else if (route === '/generate_stream') await handleGenerateStream();
|
| 331 |
else if (route === '/generate_sse') await handleGenerateSSE();
|
| 332 |
} catch (err) {
|
| 333 |
-
appendOutput(`Network/JS Error:\n${err.message}\n\n`, true);
|
| 334 |
setStatus(err.message, true);
|
| 335 |
} finally {
|
| 336 |
sendBtn.disabled = false;
|
|
|
|
| 227 |
const data = await res.json();
|
| 228 |
const ms = Math.round(performance.now() - t0);
|
| 229 |
if (res.ok) {
|
| 230 |
+
appendOutput(`[${ms}ms]\\n${data.generated_text || JSON.stringify(data, null, 2)}\\n\\n`, true);
|
| 231 |
setStatus(`OK — ${ms}ms`);
|
| 232 |
} else {
|
| 233 |
+
appendOutput(`Error ${res.status}:\\n${JSON.stringify(data, null, 2)}\\n\\n`, true);
|
| 234 |
setStatus(`HTTP ${res.status}`, true);
|
| 235 |
}
|
| 236 |
}
|
|
|
|
| 246 |
const data = await res.json();
|
| 247 |
const ms = Math.round(performance.now() - t0);
|
| 248 |
if (res.ok) {
|
| 249 |
+
let text = `[${ms}ms]\\nGenerated text:\n${data.generated_text}\\n\\n`;
|
| 250 |
if (data.intermediate_states && data.intermediate_states.length) {
|
| 251 |
+
text += `Intermediate states (${data.intermediate_states.length}):\\n`;
|
| 252 |
data.intermediate_states.forEach((s, i) => {
|
| 253 |
text += " Step " + s.step + ": " + s.text.substring(0,120).replace(/\\n/g, ' ') + "...\\n";
|
| 254 |
});
|
| 255 |
}
|
| 256 |
+
appendOutput(text + '\\n', true);
|
| 257 |
setStatus(`OK — ${ms}ms, ${data.intermediate_states?.length || 0} intermediates`);
|
| 258 |
} else {
|
| 259 |
+
appendOutput(`Error ${res.status}:\\n${JSON.stringify(data, null, 2)}\\n\\n`, true);
|
| 260 |
setStatus(`HTTP ${res.status}`, true);
|
| 261 |
}
|
| 262 |
}
|
|
|
|
| 275 |
|
| 276 |
if (!res.ok) {
|
| 277 |
const data = await res.json().catch(() => ({}));
|
| 278 |
+
appendOutput(`Error ${res.status}:\\n${JSON.stringify(data, null, 2)}`, true);
|
| 279 |
setStatus(`HTTP ${res.status}`, true);
|
| 280 |
return;
|
| 281 |
}
|
|
|
|
| 290 |
const { done, value } = await reader.read();
|
| 291 |
if (done) break;
|
| 292 |
buffer += decoder.decode(value, { stream: true });
|
| 293 |
+
const lines = buffer.split('\\n');
|
| 294 |
buffer = lines.pop(); // keep incomplete line in buffer
|
| 295 |
|
| 296 |
for (const line of lines) {
|
|
|
|
| 303 |
if (event.type === 'final') {
|
| 304 |
finalText = event.text;
|
| 305 |
const ms = Math.round(performance.now() - t0);
|
| 306 |
+
appendOutput(`[${ms}ms | ${eventCount} events]\\n${finalText}\\n`, true);
|
| 307 |
setStatus(`Done — ${ms}ms, ${eventCount} events, ${event.total_steps || '?'} steps`);
|
| 308 |
} else if (event.type === 'intermediate' || event.type === 'token') {
|
| 309 |
// Live update: overwrite with latest accumulated text
|
|
|
|
| 330 |
else if (route === '/generate_stream') await handleGenerateStream();
|
| 331 |
else if (route === '/generate_sse') await handleGenerateSSE();
|
| 332 |
} catch (err) {
|
| 333 |
+
appendOutput(`Network/JS Error:\\n${err.message}\\n\\n`, true);
|
| 334 |
setStatus(err.message, true);
|
| 335 |
} finally {
|
| 336 |
sendBtn.disabled = false;
|