a-ragab-h-m commited on
Commit
25c9425
·
verified ·
1 Parent(s): fcc575f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -9
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.Blocks() as demo:
22
- with gr.Row():
23
- btn = gr.Button("🚀 Start Training")
24
- output = gr.Textbox(label="Logs", lines=25, interactive=False)
 
25
 
26
- btn.click(fn=run_training, outputs=output)
 
 
 
 
27
 
28
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
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()