Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,24 @@
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
import threading
|
|
|
|
| 4 |
|
| 5 |
def run_training():
|
| 6 |
print("Starting training job...")
|
| 7 |
subprocess.run([sys.executable, "training.py"], check=True)
|
| 8 |
print("Training finished.")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
import threading
|
| 4 |
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
| 5 |
|
| 6 |
def run_training():
|
| 7 |
print("Starting training job...")
|
| 8 |
subprocess.run([sys.executable, "training.py"], check=True)
|
| 9 |
print("Training finished.")
|
| 10 |
|
| 11 |
+
# Start training in background
|
| 12 |
+
threading.Thread(target=run_training).start()
|
| 13 |
|
| 14 |
+
# Minimal HTTP server to keep the container alive (port 7860)
|
| 15 |
+
class Handler(BaseHTTPRequestHandler):
|
| 16 |
+
def do_GET(self):
|
| 17 |
+
self.send_response(200)
|
| 18 |
+
self.end_headers()
|
| 19 |
+
self.wfile.write(b"Training in progress...")
|
| 20 |
+
def do_POST(self):
|
| 21 |
+
self.do_GET()
|
| 22 |
+
|
| 23 |
+
print("Keeping container alive on port 7860")
|
| 24 |
+
HTTPServer(("0.0.0.0", 7860), Handler).serve_forever()
|