100XZX001 commited on
Commit
ffa64df
·
verified ·
1 Parent(s): 2dde460

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
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
- thread = threading.Thread(target=run_training)
11
- thread.start()
12
 
13
- import gradio as gr
14
- def status():
15
- return "Training running…"
16
- gr.Interface(fn=status, inputs=[], outputs="text").launch()
 
 
 
 
 
 
 
 
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()