RobbiePasquale commited on
Commit
84998a2
1 Parent(s): d523868

Update train_agent.py

Browse files
Files changed (1) hide show
  1. train_agent.py +33 -6
train_agent.py CHANGED
@@ -1,16 +1,43 @@
1
  # train_agent.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
3
  from twisted.internet import reactor, defer, task
4
  import random
5
  import logging
6
- import sys
7
  import time
8
  import codecs
9
-
10
- IS_COLAB = 'google.colab' in sys.modules
11
- from agent import AutonomousWebAgent
12
-
13
-
14
  # Configure logging
15
  if IS_COLAB:
16
  logging.basicConfig(level=logging.INFO,
 
1
  # train_agent.py
2
+ import sys
3
+ import os
4
+ from pathlib import Path
5
+
6
+ IS_COLAB = 'google.colab' in sys.modules
7
+
8
+ # Get the current file's directory
9
+ current_dir = Path(__file__).parent.absolute()
10
+
11
+ # Search for agent.py in the current directory and its parent directories
12
+ agent_path = None
13
+ search_dir = current_dir
14
+ while search_dir != search_dir.parent: # Stop at root directory
15
+ possible_path = search_dir / 'agent.py'
16
+ if possible_path.exists():
17
+ agent_path = str(search_dir)
18
+ break
19
+ search_dir = search_dir.parent
20
+
21
+ if agent_path:
22
+ sys.path.insert(0, agent_path)
23
+ print(f"Added {agent_path} to Python path")
24
+ else:
25
+ print("Could not find agent.py")
26
+
27
+ # Now try to import AutonomousWebAgent
28
+ try:
29
+ from agent import AutonomousWebAgent
30
+ print("Successfully imported AutonomousWebAgent")
31
+ except ImportError as e:
32
+ print(f"Error importing AutonomousWebAgent: {e}")
33
+ sys.exit(1)
34
 
35
+ # Rest of your imports
36
  from twisted.internet import reactor, defer, task
37
  import random
38
  import logging
 
39
  import time
40
  import codecs
 
 
 
 
 
41
  # Configure logging
42
  if IS_COLAB:
43
  logging.basicConfig(level=logging.INFO,