Update app.py to stream training logs live
Browse files
app.py
CHANGED
|
@@ -3,25 +3,27 @@ import subprocess
|
|
| 3 |
|
| 4 |
def run_training():
|
| 5 |
try:
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 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="
|
| 23 |
title="Run Model Training",
|
| 24 |
-
description="Click the button to
|
| 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()
|