hvoss-techfak commited on
Commit
313e62a
·
verified ·
1 Parent(s): 7f776d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -334,28 +334,24 @@ if os.path.exists(DEFAULT_MATERIALS_CSV):
334
  else:
335
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
336
 
337
- @spaces.GPU(duration=90) # GPU reserved only for this call
338
  def run_autoforge_process(cmd, log_path):
339
- """
340
- Launch the external `autoforge` CLI.
341
- All stdout/stderr lines are appended (line-buffered) to *log_path*.
342
- Returns the CLI's exit-code.
343
- """
344
  _check_quota(90)
345
-
346
- with open(log_path, "w", buffering=1, encoding="utf-8") as log_f: # line-buffered
347
- proc = subprocess.Popen(
348
- cmd,
349
- stdout=subprocess.PIPE,
350
- stderr=subprocess.STDOUT,
351
- text=True,
352
- bufsize=1,
353
- universal_newlines=True,
354
- )
355
- for line in proc.stdout: # live streaming to the file
356
- log_f.write(line)
357
- proc.wait()
358
- return proc.returncode
359
 
360
 
361
  # Helper for creating an empty 10-tuple for error returns
 
334
  else:
335
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
336
 
337
+ @spaces.GPU(duration=90)
338
  def run_autoforge_process(cmd, log_path):
339
+ """Run AutoForge in-process and stream its console output to *log_path*."""
 
 
 
 
340
  _check_quota(90)
341
+
342
+ cli_args = cmd[1:] # skip the literal "autoforge"
343
+ autoforge_main = importlib.import_module("autoforge.__main__")
344
+
345
+ exit_code = 0
346
+ with open(log_path, "w", buffering=1, encoding="utf-8") as log_f, \
347
+ redirect_stdout(log_f), redirect_stderr(log_f):
348
+ try:
349
+ sys.argv = ["autoforge"] + cli_args
350
+ autoforge_main.main() # runs until completion
351
+ except SystemExit as e: # AutoForge calls sys.exit()
352
+ exit_code = e.code
353
+
354
+ return exit_code
355
 
356
 
357
  # Helper for creating an empty 10-tuple for error returns