Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
|
4 |
-
logs = []
|
|
|
5 |
|
6 |
def run_training():
|
7 |
global logs
|
@@ -13,16 +14,47 @@ def run_training():
|
|
13 |
text=True,
|
14 |
bufsize=1
|
15 |
)
|
16 |
-
|
17 |
for line in process.stdout:
|
18 |
logs.append(line)
|
19 |
-
yield "\n".join(logs[:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
with gr.
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
|
4 |
+
logs = []
|
5 |
+
inference_logs = []
|
6 |
|
7 |
def run_training():
|
8 |
global logs
|
|
|
14 |
text=True,
|
15 |
bufsize=1
|
16 |
)
|
|
|
17 |
for line in process.stdout:
|
18 |
logs.append(line)
|
19 |
+
yield "\n".join(logs[-50:]) # عرض آخر 50 سطر
|
20 |
+
|
21 |
+
def run_inference():
|
22 |
+
global inference_logs
|
23 |
+
inference_logs = []
|
24 |
+
output_lines = []
|
25 |
+
|
26 |
+
process = subprocess.Popen(
|
27 |
+
["python", "inference.py"],
|
28 |
+
stdout=subprocess.PIPE,
|
29 |
+
stderr=subprocess.STDOUT,
|
30 |
+
text=True,
|
31 |
+
bufsize=1
|
32 |
+
)
|
33 |
+
for line in process.stdout:
|
34 |
+
inference_logs.append(line)
|
35 |
+
output_lines.append(line)
|
36 |
+
|
37 |
+
# حفظ النتائج في ملف
|
38 |
+
with open("inference_results.txt", "a") as f:
|
39 |
+
f.write("=== New Inference Run ===\n")
|
40 |
+
f.writelines(output_lines)
|
41 |
+
f.write("\n")
|
42 |
+
|
43 |
+
yield "\n".join(inference_logs[-50:]) # عرض آخر 50 سطر
|
44 |
+
|
45 |
+
with gr.Blocks(title="VRP Transformer Training & Inference") as demo:
|
46 |
+
gr.Markdown("# 🚛 Vehicle Routing Problem Solver with Transformer + Reinforcement Learning")
|
47 |
|
48 |
+
with gr.Tab("🚀 Start Training"):
|
49 |
+
with gr.Row():
|
50 |
+
start_btn = gr.Button("Start Training")
|
51 |
+
output = gr.Textbox(label="Training Logs", lines=25)
|
52 |
+
start_btn.click(fn=run_training, outputs=output)
|
53 |
|
54 |
+
with gr.Tab("🔍 Run Inference"):
|
55 |
+
with gr.Row():
|
56 |
+
infer_btn = gr.Button("Run Inference on New Batch")
|
57 |
+
infer_output = gr.Textbox(label="Inference Results", lines=15)
|
58 |
+
infer_btn.click(fn=run_inference, outputs=infer_output)
|
59 |
|
60 |
+
demo.launch()
|