rshakked commited on
Commit
d04cf51
Β·
1 Parent(s): 5d99999

Update app.py to stream training logs live

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -3,25 +3,27 @@ import subprocess
3
 
4
  def run_training():
5
  try:
6
- print("βœ… Training started.")
7
- result = subprocess.run(["python", "train_abuse_model.py"], capture_output=True, text=True)
8
- print("βœ… Training finished.")
9
- print("STDOUT:", result.stdout)
10
- print("STDERR:", result.stderr)
11
- return result.stdout if result.returncode == 0 else f"Error:\n{result.stderr}"
12
- except Exception as e:
13
- print("❌ Exception occurred:", e)
14
- return f"Exception occurred:\n{str(e)}"
15
 
 
 
 
 
16
 
 
 
17
 
18
- # Define a simple Gradio interface with one button
19
  demo = gr.Interface(
20
  fn=run_training,
21
  inputs=[],
22
- outputs="text",
23
  title="Run Model Training",
24
- description="Click the button to execute train.py. This will use GPU if available."
25
  )
26
 
27
  demo.launch()
 
3
 
4
  def run_training():
5
  try:
6
+ process = subprocess.Popen(
7
+ ["python", "train_abuse_model.py"],
8
+ stdout=subprocess.PIPE,
9
+ stderr=subprocess.STDOUT,
10
+ text=True
11
+ )
 
 
 
12
 
13
+ output_lines = []
14
+ for line in process.stdout:
15
+ output_lines.append(line)
16
+ yield "".join(output_lines)
17
 
18
+ except Exception as e:
19
+ yield f"Exception occurred:\n{str(e)}"
20
 
 
21
  demo = gr.Interface(
22
  fn=run_training,
23
  inputs=[],
24
+ outputs=gr.Textbox(lines=25, label="Training Logs"),
25
  title="Run Model Training",
26
+ description="Click the button to start training and see live logs below."
27
  )
28
 
29
  demo.launch()