Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,73 @@
|
|
1 |
import gradio as gr
|
2 |
-
import subprocess
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
def
|
|
|
|
|
|
|
|
|
6 |
try:
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
14 |
-
|
15 |
-
stdout, stderr = process.communicate()
|
16 |
-
|
17 |
-
if process.returncode == 0:
|
18 |
-
subprocess.run(["python", "/app/qwen/collect_data.py"])
|
19 |
-
return "Training completed successfully!"
|
20 |
-
else:
|
21 |
-
return f"Error during training: {stderr.decode()}"
|
22 |
-
except Exception as e:
|
23 |
-
return f"Error: {str(e)}"
|
24 |
|
25 |
-
# Create
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
gr.
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
if __name__ == "__main__":
|
39 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
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."
|
10 |
+
|
11 |
+
iterations = len(list(results_dir.glob("iter_*")))
|
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)
|
18 |
+
|
19 |
try:
|
20 |
+
subprocess.run(["bash", "run.sh"],
|
21 |
+
check=True,
|
22 |
+
cwd="/app/qwen")
|
23 |
+
return "Training completed successfully!"
|
24 |
+
except subprocess.CalledProcessError as e:
|
25 |
+
return f"Error during training: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
# Create the interface
|
28 |
+
with gr.Blocks() as iface:
|
29 |
+
gr.Markdown("# Self-Lengthen Training Interface")
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
with gr.Column():
|
33 |
+
model_path = gr.Textbox(
|
34 |
+
label="Model Path",
|
35 |
+
value="/app/models/base_model",
|
36 |
+
info="Path to the base model"
|
37 |
+
)
|
38 |
+
instruct_count = gr.Number(
|
39 |
+
label="Instruction Count",
|
40 |
+
value=5000,
|
41 |
+
minimum=100,
|
42 |
+
info="Number of instructions to generate"
|
43 |
+
)
|
44 |
+
max_iter = gr.Number(
|
45 |
+
label="Max Iterations",
|
46 |
+
value=3,
|
47 |
+
minimum=1,
|
48 |
+
info="Number of training iterations"
|
49 |
+
)
|
50 |
+
train_btn = gr.Button("Start Training")
|
51 |
+
|
52 |
+
with gr.Column():
|
53 |
+
status_output = gr.Textbox(
|
54 |
+
label="Status",
|
55 |
+
value="Ready to start training...",
|
56 |
+
interactive=False
|
57 |
+
)
|
58 |
+
refresh_btn = gr.Button("Refresh Status")
|
59 |
+
|
60 |
+
train_btn.click(
|
61 |
+
fn=start_training,
|
62 |
+
inputs=[model_path, instruct_count, max_iter],
|
63 |
+
outputs=status_output
|
64 |
+
)
|
65 |
+
|
66 |
+
refresh_btn.click(
|
67 |
+
fn=check_training_status,
|
68 |
+
inputs=None,
|
69 |
+
outputs=status_output
|
70 |
+
)
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|