asataura commited on
Commit
c0bb1b2
1 Parent(s): a5f2527

Refactoring app.py

Browse files
Files changed (3) hide show
  1. app.py +43 -29
  2. tester.py +1 -3
  3. trainer.py +1 -1
app.py CHANGED
@@ -1,49 +1,63 @@
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
 
4
-
5
  import streamlit as st
6
- import trainer
7
- import tester
8
  import os
 
 
9
 
10
 
11
  def main():
12
  st.title("Beyond the Anti-Jam: Integration of DRL with LLM")
13
- st.header("Make Your Environment Configuration")
14
- mode = st.radio("Choose Mode", ["Auto", "Manual"])
 
15
 
16
  if mode == "Auto":
17
  jammer_type = "dynamic"
18
  channel_switching_cost = 0.1
19
  else:
20
- jammer_type = st.selectbox("Select Jammer Type", ["constant", "sweeping", "random", "dynamic"])
21
- channel_switching_cost = st.selectbox("Select Channel Switching Cost", [0, 0.05, 0.1, 0.15, 0.2])
22
 
23
- st.subheader("Configuration:")
24
- st.write(f"Jammer Type: {jammer_type}")
25
- st.write(f"Channel Switching Cost: {channel_switching_cost}")
26
 
27
- if st.button('Train'):
28
- agentName = f'DDQNAgent_{jammer_type}_csc_{channel_switching_cost}'
29
- if os.path.exists(agentName):
30
- st.write("Agent has been trained already!!!")
31
- else:
32
- st.write("==================================================")
33
- st.write('Training Starting')
34
- trainer.train(jammer_type, channel_switching_cost)
35
- st.write("Training completed")
36
- st.write("==================================================")
37
- if st.button('Test'):
38
- agentName = f'DDQNAgent_{jammer_type}_csc_{channel_switching_cost}'
39
- if os.path.exists(agentName):
40
- st.write("==================================================")
41
- st.write('Testing Starting')
42
- tester.test(jammer_type, channel_switching_cost)
43
- st.write("Testing completed")
44
- st.write("==================================================")
45
  else:
46
- st.write("Agent has not been trained yet. Click Train First!!!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
 
49
  if __name__ == "__main__":
 
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
 
 
4
  import streamlit as st
 
 
5
  import os
6
+ from trainer import train
7
+ from tester import test
8
 
9
 
10
  def main():
11
  st.title("Beyond the Anti-Jam: Integration of DRL with LLM")
12
+
13
+ st.sidebar.header("Make Your Environment Configuration")
14
+ mode = st.sidebar.radio("Choose Mode", ["Auto", "Manual"])
15
 
16
  if mode == "Auto":
17
  jammer_type = "dynamic"
18
  channel_switching_cost = 0.1
19
  else:
20
+ jammer_type = st.sidebar.selectbox("Select Jammer Type", ["constant", "sweeping", "random", "dynamic"])
21
+ channel_switching_cost = st.sidebar.selectbox("Select Channel Switching Cost", [0, 0.05, 0.1, 0.15, 0.2])
22
 
23
+ st.sidebar.subheader("Configuration:")
24
+ st.sidebar.write(f"Jammer Type: {jammer_type}")
25
+ st.sidebar.write(f"Channel Switching Cost: {channel_switching_cost}")
26
 
27
+ train_button = st.sidebar.button('Train')
28
+ test_button = st.sidebar.button('Test')
29
+
30
+ if train_button or test_button:
31
+ agent_name = f'DDQNAgent_{jammer_type}_csc_{channel_switching_cost}'
32
+ if os.path.exists(agent_name):
33
+ if train_button:
34
+ st.warning("Agent has been trained already! Do you want to retrain?")
35
+ retrain = st.sidebar.button('Yes')
36
+ if retrain:
37
+ perform_training(jammer_type, channel_switching_cost)
38
+ elif test_button:
39
+ perform_testing(jammer_type, channel_switching_cost)
 
 
 
 
 
40
  else:
41
+ if train_button:
42
+ perform_training(jammer_type, channel_switching_cost)
43
+ elif test_button:
44
+ st.warning("Agent has not been trained yet. Click Train First!!!")
45
+
46
+
47
+ def perform_training(jammer_type, channel_switching_cost):
48
+ st.sidebar.write("==================================================")
49
+ st.sidebar.write('Training Starting')
50
+ train(jammer_type, channel_switching_cost)
51
+ st.sidebar.write("Training completed")
52
+ st.sidebar.write("==================================================")
53
+
54
+
55
+ def perform_testing(jammer_type, channel_switching_cost):
56
+ st.sidebar.write("==================================================")
57
+ st.sidebar.write('Testing Starting')
58
+ test(jammer_type, channel_switching_cost)
59
+ st.sidebar.write("Testing completed")
60
+ st.sidebar.write("==================================================")
61
 
62
 
63
  if __name__ == "__main__":
tester.py CHANGED
@@ -13,13 +13,11 @@ def test(jammer_type, channel_switching_cost):
13
  env = AntiJamEnv(jammer_type, channel_switching_cost)
14
  ob_space = env.observation_space
15
  ac_space = env.action_space
16
- st.write(f"Observation space: , {ob_space}")
17
- st.write(f"Action space: {ac_space}")
18
 
19
  s_size = ob_space.shape[0]
20
  a_size = ac_space.n
21
  max_env_steps = 100
22
- TEST_Episodes = 100
23
  env._max_episode_steps = max_env_steps
24
 
25
  epsilon = 1.0 # exploration rate
 
13
  env = AntiJamEnv(jammer_type, channel_switching_cost)
14
  ob_space = env.observation_space
15
  ac_space = env.action_space
 
 
16
 
17
  s_size = ob_space.shape[0]
18
  a_size = ac_space.n
19
  max_env_steps = 100
20
+ TEST_Episodes = 10
21
  env._max_episode_steps = max_env_steps
22
 
23
  epsilon = 1.0 # exploration rate
trainer.py CHANGED
@@ -19,7 +19,7 @@ def train(jammer_type, channel_switching_cost):
19
  s_size = ob_space.shape[0]
20
  a_size = ac_space.n
21
  max_env_steps = 100
22
- TRAIN_Episodes = 100
23
  env._max_episode_steps = max_env_steps
24
 
25
  epsilon = 1.0 # exploration rate
 
19
  s_size = ob_space.shape[0]
20
  a_size = ac_space.n
21
  max_env_steps = 100
22
+ TRAIN_Episodes = 10
23
  env._max_episode_steps = max_env_steps
24
 
25
  epsilon = 1.0 # exploration rate