|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
logs = [] |
|
inference_logs = [] |
|
|
|
|
|
DATA_DIR = os.path.join(os.getcwd(), "data") |
|
os.makedirs(DATA_DIR, exist_ok=True) |
|
|
|
def run_training(): |
|
global logs |
|
logs = [] |
|
|
|
|
|
process = subprocess.Popen( |
|
["python", "run.py"], |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.STDOUT, |
|
text=True, |
|
bufsize=1 |
|
) |
|
|
|
|
|
for line in process.stdout: |
|
logs.append(line) |
|
yield "\n".join(logs[:]) |
|
|
|
def run_inference(): |
|
global inference_logs |
|
inference_logs = [] |
|
output_lines = [] |
|
|
|
|
|
process = subprocess.Popen( |
|
["python", "inference.py"], |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.STDOUT, |
|
text=True, |
|
bufsize=1 |
|
) |
|
|
|
for line in process.stdout: |
|
inference_logs.append(line) |
|
output_lines.append(line) |
|
|
|
|
|
inference_output_path = os.path.join(DATA_DIR, "inference_results.txt") |
|
with open(inference_output_path, "a") as f: |
|
f.write("=== New Inference Run ===\n") |
|
f.writelines(output_lines) |
|
f.write("\n") |
|
|
|
yield "\n".join(inference_logs[:]) |
|
|
|
|
|
with gr.Blocks(title="VRP Transformer Training & Inference") as demo: |
|
gr.Markdown("# 🚛 Vehicle Routing Problem Solver with Transformer + Reinforcement Learning") |
|
|
|
with gr.Tab("🚀 Start Training"): |
|
with gr.Row(): |
|
start_btn = gr.Button("Start Training") |
|
output = gr.Textbox(label="Training Logs", lines=25) |
|
start_btn.click(fn=run_training, outputs=output) |
|
|
|
with gr.Tab("🔍 Run Inference"): |
|
with gr.Row(): |
|
infer_btn = gr.Button("Run Inference on New Batch") |
|
infer_output = gr.Textbox(label="Inference Results", lines=15) |
|
infer_btn.click(fn=run_inference, outputs=infer_output) |
|
|
|
demo.launch() |
|
|