testing out OCR viewer of OCR'd text
This commit is contained in:
45
launch_viewer.py
Normal file
45
launch_viewer.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
P44 OCR Viewer — launcher
|
||||
Starts a local HTTP server at port 5044 and opens the viewer in the default browser.
|
||||
Run from any directory; the server root is always the project folder (this file's location).
|
||||
"""
|
||||
import http.server
|
||||
import webbrowser
|
||||
import threading
|
||||
import os
|
||||
import sys
|
||||
|
||||
PORT = 5044
|
||||
ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
class QuietHandler(http.server.SimpleHTTPRequestHandler):
|
||||
"""Serve files from ROOT, suppress request logs."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, directory=ROOT, **kwargs)
|
||||
def log_message(self, fmt, *args):
|
||||
pass # silence per-request noise
|
||||
|
||||
def start_server():
|
||||
server = http.server.HTTPServer(('localhost', PORT), QuietHandler)
|
||||
server.serve_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Start the server in a background daemon thread
|
||||
t = threading.Thread(target=start_server, daemon=True)
|
||||
t.start()
|
||||
|
||||
url = f'http://localhost:{PORT}/p44-ocr-viewer.html'
|
||||
print(f"\n ⚜ P44 OCR Viewer")
|
||||
print(f" Serving: {ROOT}")
|
||||
print(f" URL: {url}\n")
|
||||
webbrowser.open(url)
|
||||
|
||||
print("Press Enter (or Ctrl-C) to stop the server and exit.\n")
|
||||
try:
|
||||
input()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
print("Server stopped.")
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user