Sergidev commited on
Commit
8db0b4f
·
verified ·
1 Parent(s): bdb0ed5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -31
app.py CHANGED
@@ -1,39 +1,73 @@
1
  import gradio as gr
2
- import subprocess
3
  import os
 
 
 
 
 
 
 
 
 
 
4
 
5
- def run_self_lengthen(model_path, instruct_count, max_iter):
 
 
 
 
6
  try:
7
- process = subprocess.Popen([
8
- "bash",
9
- "/app/qwen/run.sh",
10
- f"--base_model={model_path}",
11
- f"--instruct_count={instruct_count}",
12
- f"--max_iter={max_iter}"
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 Gradio interface
26
- iface = gr.Interface(
27
- fn=run_self_lengthen,
28
- inputs=[
29
- gr.Textbox(label="Model Path", value="/app/models/base_model"),
30
- gr.Number(label="Instruction Count", value=5000, minimum=100),
31
- gr.Number(label="Max Iterations", value=3, minimum=1)
32
- ],
33
- outputs=gr.Textbox(label="Status"),
34
- title="Self-Lengthen Training Interface",
35
- description="Train language models to generate longer texts using the Self-Lengthen approach."
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)