Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,9 @@ import os
|
|
5 |
logs = []
|
6 |
inference_logs = []
|
7 |
|
8 |
-
# تأكد من أن مجلد /data موجود وآمن للكتابة
|
9 |
-
DATA_DIR = os.path.join(os.getcwd(), "data")
|
10 |
-
os.makedirs(DATA_DIR, exist_ok=True)
|
11 |
-
|
12 |
def run_training():
|
13 |
global logs
|
14 |
logs = []
|
15 |
-
|
16 |
-
# تنفيذ سكربت التدريب
|
17 |
process = subprocess.Popen(
|
18 |
["python", "run.py"],
|
19 |
stdout=subprocess.PIPE,
|
@@ -21,18 +15,15 @@ def run_training():
|
|
21 |
text=True,
|
22 |
bufsize=1
|
23 |
)
|
24 |
-
|
25 |
-
# عرض اللوجات بشكل مباشر
|
26 |
for line in process.stdout:
|
27 |
logs.append(line)
|
28 |
-
yield "\n".join(logs[:]) # عرض آخر 50 سطر
|
29 |
|
30 |
def run_inference():
|
31 |
global inference_logs
|
32 |
inference_logs = []
|
33 |
output_lines = []
|
34 |
|
35 |
-
# تنفيذ سكربت التنبؤ
|
36 |
process = subprocess.Popen(
|
37 |
["python", "inference.py"],
|
38 |
stdout=subprocess.PIPE,
|
@@ -40,34 +31,45 @@ def run_inference():
|
|
40 |
text=True,
|
41 |
bufsize=1
|
42 |
)
|
43 |
-
|
44 |
for line in process.stdout:
|
45 |
inference_logs.append(line)
|
46 |
output_lines.append(line)
|
47 |
|
48 |
-
# حفظ
|
49 |
-
|
50 |
-
with open(inference_output_path, "a") as f:
|
51 |
f.write("=== New Inference Run ===\n")
|
52 |
f.writelines(output_lines)
|
53 |
f.write("\n")
|
54 |
|
55 |
-
yield "\n".join(inference_logs[:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
gr.Markdown("# 🚛 Vehicle Routing Problem Solver with Transformer + Reinforcement Learning")
|
60 |
|
61 |
with gr.Tab("🚀 Start Training"):
|
62 |
-
|
63 |
-
start_btn = gr.Button("Start Training")
|
64 |
output = gr.Textbox(label="Training Logs", lines=25)
|
65 |
start_btn.click(fn=run_training, outputs=output)
|
66 |
|
67 |
-
with gr.Tab("🔍
|
68 |
-
|
69 |
-
|
70 |
-
infer_output = gr.Textbox(label="Inference Results", lines=15)
|
71 |
infer_btn.click(fn=run_inference, outputs=infer_output)
|
72 |
|
|
|
|
|
|
|
|
|
|
|
73 |
demo.launch()
|
|
|
5 |
logs = []
|
6 |
inference_logs = []
|
7 |
|
|
|
|
|
|
|
|
|
8 |
def run_training():
|
9 |
global logs
|
10 |
logs = []
|
|
|
|
|
11 |
process = subprocess.Popen(
|
12 |
["python", "run.py"],
|
13 |
stdout=subprocess.PIPE,
|
|
|
15 |
text=True,
|
16 |
bufsize=1
|
17 |
)
|
|
|
|
|
18 |
for line in process.stdout:
|
19 |
logs.append(line)
|
20 |
+
yield "\n".join(logs[-50:]) # عرض آخر 50 سطر
|
21 |
|
22 |
def run_inference():
|
23 |
global inference_logs
|
24 |
inference_logs = []
|
25 |
output_lines = []
|
26 |
|
|
|
27 |
process = subprocess.Popen(
|
28 |
["python", "inference.py"],
|
29 |
stdout=subprocess.PIPE,
|
|
|
31 |
text=True,
|
32 |
bufsize=1
|
33 |
)
|
|
|
34 |
for line in process.stdout:
|
35 |
inference_logs.append(line)
|
36 |
output_lines.append(line)
|
37 |
|
38 |
+
# حفظ النتائج
|
39 |
+
with open("/home/user/data/inference_results.txt", "a") as f:
|
|
|
40 |
f.write("=== New Inference Run ===\n")
|
41 |
f.writelines(output_lines)
|
42 |
f.write("\n")
|
43 |
|
44 |
+
yield "\n".join(inference_logs[-50:])
|
45 |
+
|
46 |
+
def list_saved_files():
|
47 |
+
data_dir = "/home/user/data"
|
48 |
+
if not os.path.exists(data_dir):
|
49 |
+
return "📁 No saved files found."
|
50 |
+
|
51 |
+
files = os.listdir(data_dir)
|
52 |
+
if not files:
|
53 |
+
return "📂 No files found in /data."
|
54 |
+
|
55 |
+
return "\n".join(f"📄 {f}" for f in files)
|
56 |
|
57 |
+
with gr.Blocks(title="VRP Solver Interface") as demo:
|
58 |
+
gr.Markdown("# 🚛 VRP Solver: Transformer + RL + OR-Tools")
|
|
|
59 |
|
60 |
with gr.Tab("🚀 Start Training"):
|
61 |
+
start_btn = gr.Button("Start Training")
|
|
|
62 |
output = gr.Textbox(label="Training Logs", lines=25)
|
63 |
start_btn.click(fn=run_training, outputs=output)
|
64 |
|
65 |
+
with gr.Tab("🔍 Inference"):
|
66 |
+
infer_btn = gr.Button("Run Inference")
|
67 |
+
infer_output = gr.Textbox(label="Inference Output", lines=15)
|
|
|
68 |
infer_btn.click(fn=run_inference, outputs=infer_output)
|
69 |
|
70 |
+
with gr.Tab("📁 Show Saved Files"):
|
71 |
+
list_btn = gr.Button("List /data Files")
|
72 |
+
file_output = gr.Textbox(label="Saved Files", lines=10)
|
73 |
+
list_btn.click(fn=list_saved_files, outputs=file_output)
|
74 |
+
|
75 |
demo.launch()
|