hvoss-techfak commited on
Commit
d932bbf
·
1 Parent(s): d677a26
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -7,7 +7,6 @@ import zipfile
7
  import importlib
8
  import wandb
9
  from contextlib import redirect_stdout, redirect_stderr
10
- import spaces
11
 
12
  USE_WANDB = "WANDB_API_KEY" in os.environ
13
  if USE_WANDB:
@@ -795,28 +794,29 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
795
  to the run log to preserve the live console stream.
796
  """
797
  try:
798
- # Import or reload the package module so decorators execute on import.
799
- with open(self.log_path, "a", encoding="utf-8") as lf, \
800
- redirect_stdout(lf), redirect_stderr(lf):
 
 
 
 
801
  try:
802
- if "autoforge.auto_forge" in sys.modules:
803
- module = importlib.reload(sys.modules["autoforge.auto_forge"])
804
- else:
805
- module = importlib.import_module("autoforge.auto_forge")
806
 
807
- # Provide CLI-like argv for the parser inside the module
808
  sys.argv = ["autoforge"] + (self.cmd[1:] if len(self.cmd) > 1 else [])
809
-
810
- if hasattr(module, "main"):
811
  try:
812
- module.main()
813
  self.returncode = 0
814
  except SystemExit as se:
815
  self.returncode = se.code if isinstance(se.code, int) or se.code is None else 0
816
  else:
817
- raise AttributeError("autoforge.auto_forge does not expose a main() function")
818
  except Exception as e:
819
- lf.write(f"\nERROR while importing/running autoforge.auto_forge: {exc_text(e)}\n")
820
  self.exc = e
821
  if isinstance(e, SystemExit):
822
  self.returncode = e.code if isinstance(e.code, int) or e.code is None else 1
 
7
  import importlib
8
  import wandb
9
  from contextlib import redirect_stdout, redirect_stderr
 
10
 
11
  USE_WANDB = "WANDB_API_KEY" in os.environ
12
  if USE_WANDB:
 
794
  to the run log to preserve the live console stream.
795
  """
796
  try:
797
+ # Ensure the project directory is on sys.path so a plain `import auto_forge` finds the local file
798
+ script_dir = os.path.dirname(os.path.abspath(__file__))
799
+ if script_dir not in sys.path:
800
+ sys.path.insert(0, script_dir)
801
+
802
+ # Import the local auto_forge module using a plain import (no importlib utilities)
803
+ with open(self.log_path, "a", encoding="utf-8") as lf, redirect_stdout(lf), redirect_stderr(lf):
804
  try:
805
+ # Use plain import; if already imported, the module's top-level code won't re-run.
806
+ import auto_forge
 
 
807
 
808
+ # Provide argv for the module's CLI parsing and call main()
809
  sys.argv = ["autoforge"] + (self.cmd[1:] if len(self.cmd) > 1 else [])
810
+ if hasattr(auto_forge, "main"):
 
811
  try:
812
+ auto_forge.main()
813
  self.returncode = 0
814
  except SystemExit as se:
815
  self.returncode = se.code if isinstance(se.code, int) or se.code is None else 0
816
  else:
817
+ raise AttributeError("auto_forge module does not expose a main() function")
818
  except Exception as e:
819
+ lf.write(f"\nERROR while importing/running auto_forge: {exc_text(e)}\n")
820
  self.exc = e
821
  if isinstance(e, SystemExit):
822
  self.returncode = e.code if isinstance(e.code, int) or e.code is None else 1