Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,31 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def check_training_status():
|
|
|
|
|
|
|
|
|
|
|
7 |
results_dir = Path("/app/results")
|
8 |
if not results_dir.exists():
|
9 |
return "Training hasn't started yet."
|
@@ -12,6 +35,11 @@ def check_training_status():
|
|
12 |
return f"Completed {iterations} training iterations."
|
13 |
|
14 |
def start_training(model_path, instruct_count, max_iter):
|
|
|
|
|
|
|
|
|
|
|
15 |
os.environ["MODEL_PATH"] = model_path
|
16 |
os.environ["INSTRUCT_COUNT"] = str(instruct_count)
|
17 |
os.environ["MAX_ITER"] = str(max_iter)
|
@@ -70,4 +98,14 @@ with gr.Blocks() as iface:
|
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
5 |
+
import time
|
6 |
+
import requests
|
7 |
+
|
8 |
+
def check_services():
|
9 |
+
"""Check if all required services are running"""
|
10 |
+
services = [
|
11 |
+
("Controller", "http://localhost:21001"),
|
12 |
+
("API Server", "http://localhost:8000"),
|
13 |
+
("Model Worker", "http://localhost:8080")
|
14 |
+
]
|
15 |
+
|
16 |
+
for service_name, url in services:
|
17 |
+
try:
|
18 |
+
requests.get(url)
|
19 |
+
print(f"{service_name} is running")
|
20 |
+
except requests.exceptions.ConnectionError:
|
21 |
+
return False, f"{service_name} is not running"
|
22 |
+
return True, "All services are running"
|
23 |
|
24 |
def check_training_status():
|
25 |
+
# First check if services are running
|
26 |
+
services_ok, message = check_services()
|
27 |
+
if not services_ok:
|
28 |
+
return message
|
29 |
+
|
30 |
results_dir = Path("/app/results")
|
31 |
if not results_dir.exists():
|
32 |
return "Training hasn't started yet."
|
|
|
35 |
return f"Completed {iterations} training iterations."
|
36 |
|
37 |
def start_training(model_path, instruct_count, max_iter):
|
38 |
+
# Check if services are running
|
39 |
+
services_ok, message = check_services()
|
40 |
+
if not services_ok:
|
41 |
+
return message
|
42 |
+
|
43 |
os.environ["MODEL_PATH"] = model_path
|
44 |
os.environ["INSTRUCT_COUNT"] = str(instruct_count)
|
45 |
os.environ["MAX_ITER"] = str(max_iter)
|
|
|
98 |
)
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
+
# Wait for services to be ready
|
102 |
+
print("Waiting for services to start...")
|
103 |
+
while True:
|
104 |
+
services_ok, message = check_services()
|
105 |
+
if services_ok:
|
106 |
+
break
|
107 |
+
print(message)
|
108 |
+
time.sleep(5)
|
109 |
+
|
110 |
+
print("All services are running, starting web interface...")
|
111 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|