forked from samsartor/stable-diffusion-webui-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve-progress.py
29 lines (24 loc) · 826 Bytes
/
serve-progress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
import http.server
import socketserver
from pathlib import Path
status_path = Path('download-model-status.json')
# Define a handler to serve the progress page
class ProgressHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
try:
message = status_path.read_text()
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(message.encode())
except FileNotFoundError:
self.send_response(400)
def log_message(self, format, *args):
pass
# Start the HTTP server in the background
with socketserver.TCPServer(("0.0.0.0", 7850), ProgressHandler) as httpd:
try:
httpd.serve_forever()
finally:
httpd.shutdown()