yt-flow / status_server.py
Arshit Malik
fix cache quantization, full kernel logs, copy button
ef2dcf8
Raw
History Blame Contribute Delete
2.29 kB
import http.server
import os
LOG_PATH = '/app/pipeline.log'
HTML = """<!DOCTYPE html>
<html><head><meta charset=utf-8><title>YT Pipeline</title>
<style>
body{font-family:monospace;background:#111;color:#0f0;margin:0;padding:20px}
h2{color:#0f0}
#log{background:#000;padding:10px;white-space:pre-wrap;height:80vh;overflow-y:auto;font-size:12px}
</style></head><body>
<h2>YouTube Shorts Pipeline</h2>
<button onclick="copyLog()" style="background:#333;color:#0f0;border:1px solid #0f0;padding:5px 15px;cursor:pointer;margin-bottom:10px">Copy Log</button>
<p>Full pipeline log (live, updates every 2 seconds):</p>
<pre id="log">Loading...</pre>
<script>
async function refresh(){
try{
const r=await fetch('/log');
const t=await r.text();
const el=document.getElementById('log');
if(t!==el.textContent){
el.textContent=t;
el.scrollTop=el.scrollHeight;
}
}catch(e){}
}
refresh();
setInterval(refresh,2000);
function copyLog(){const t=document.getElementById("log").textContent;navigator.clipboard.writeText(t).then(()=>{const b=document.querySelector("button");b.textContent="Copied!";setTimeout(()=>b.textContent="Copy Log",2000)})}
</script></body></html>"""
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/log':
try:
log_content = open(LOG_PATH).read()
except:
log_content = 'No log yet.'
data = log_content.encode()
self.send_response(200)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.send_header('Content-Length', str(len(data)))
self.end_headers()
try:
self.wfile.write(data)
except (BrokenPipeError, ConnectionResetError):
pass
else:
data = HTML.encode()
self.send_response(200)
self.send_header('Content-Type', 'text/html; charset=utf-8')
self.send_header('Content-Length', str(len(data)))
self.end_headers()
try:
self.wfile.write(data)
except (BrokenPipeError, ConnectionResetError):
pass
def log_message(self, *a): pass
http.server.HTTPServer(('0.0.0.0', 8080), H).serve_forever()