#!/usr/bin/env python3 """Local web UI for transcribe_vod.sh — run with: python3 server.py""" import http.server import subprocess import json import os import threading import signal SCRIPT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "transcribe_vod.sh") PORT = 8765 HTML = r""" VOD Transcriber

VOD Transcriber

whisper.cpp · local · no upload

Running transcription…


  
Transcript ready
""" class Handler(http.server.BaseHTTPRequestHandler): def log_message(self, *args): pass # suppress request logs def do_GET(self): if self.path == "/": self._send(200, "text/html; charset=utf-8", HTML.encode()) elif self.path.startswith("/file?path="): from urllib.parse import unquote, urlparse, parse_qs qs = parse_qs(urlparse(self.path).query) path = unquote(qs.get("path", [""])[0]) if not path or not os.path.isfile(path): self._send(404, "text/plain", b"Not found") return with open(path, "rb") as f: content = f.read() self._send(200, "text/plain; charset=utf-8", content) else: self._send(404, "text/plain", b"Not found") def do_POST(self): if self.path == "/stop": self._send(200, "text/plain", b"Stopping.") threading.Timer(0.3, lambda: os.kill(os.getpid(), signal.SIGTERM)).start() return n = int(self.headers.get("Content-Length", 0)) body = json.loads(self.rfile.read(n)) video = body.get("path", "").strip() if not video: self._json({"ok": False, "log": "No path provided.", "transcript": None}) return result = subprocess.run( ["bash", SCRIPT, video], capture_output=True, text=True, ) base = os.path.splitext(video)[0] transcript = base + "_transcript.txt" self._json({ "ok": result.returncode == 0, "log": (result.stdout + result.stderr).strip(), "transcript": transcript if os.path.isfile(transcript) else None, }) def _send(self, code, ctype, body): self.send_response(code) self.send_header("Content-Type", ctype) self.send_header("Content-Length", len(body)) self.end_headers() self.wfile.write(body) def _json(self, data): body = json.dumps(data).encode() self._send(200, "application/json", body) if __name__ == "__main__": server = http.server.HTTPServer(("localhost", PORT), Handler) print(f"Open → http://localhost:{PORT}") try: server.serve_forever() except KeyboardInterrupt: print("\nStopped.")