Spaces:
Sleeping
Sleeping
Commit Β·
00a3cc2
1
Parent(s): 8af35ac
Updates run.py to use direct file paths
Browse files6 unmodified lines789101112131415161718192 unmodified lines22232425262728293031323334353637383940414243444546471 unmodified line495051525354555657585960616 unmodified linesbg_process = Nonedef cleanup():"""Ensure background process is terminated on script exit."""global bg_processif bg_process and bg_process.poll() is None:print("\nπ Terminating background data pipeline...")# On Unix-like systems (like Hugging Face), os.kill is more reliabletry:os.kill(bg_process.pid, signal.SIGTERM)bg_process.wait(timeout=5)2 unmodified linesbg_process.kill()print("β Pipeline terminated.")def run_command(command, description):"""Runs a setup command and exits if it fails."""print(f"π {description}...")# Use sys.executable to ensure we use the python from the correct venvresult = subprocess.run([sys.executable, "-m", command], capture_output=True, text=True)if result.returncode != 0:print(f"β ERROR: {description} failed.")print(result.stderr)sys.exit(result.returncode)print(f"β {description} complete.")def main():# Register the cleanup function to be called on any script exitatexit.register(cleanup)# Initialize and Seedrun_command("database/database_setup.py", "Initializing database")run_command("scripts/seed_db.py", "Seeding initial data")# Start the background data pipelineprint("π‘ Starting background data pipeline...")1 unmodified linebg_process = subprocess.Popen([sys.executable, "main.py"])print(f"β Data pipeline started with PID: {bg_process.pid}")# Start the Streamlit app (this is the main blocking process)print("π Starting Streamlit dashboard...")subprocess.run(["streamlit", "run", "app.py", "--server.port", "8501", "--server.headless", "true"])if __name__ == "__main__":main()6 unmodified lines78910111213141516172 unmodified lines20212223242526272829303132333435363738394041424344451 unmodified line4748495051525354555657585960616 unmodified linesbg_process = Nonedef cleanup():"""Ensure background process is terminated on script exit."""global bg_processif bg_process and bg_process.poll() is None:print("\nπ Terminating background data pipeline...")try:os.kill(bg_process.pid, signal.SIGTERM)bg_process.wait(timeout=5)2 unmodified linesbg_process.kill()print("β Pipeline terminated.")def run_command(command_args, description):"""Runs a setup command using its file path and exits if it fails."""print(f"π {description}...")try:# --- FIX IS HERE: We now run the script by its file path directly ---result = subprocess.run([sys.executable] + command_args, check=True, capture_output=True, text=True)print(f"β {description} complete.")except subprocess.CalledProcessError as e:print(f"β ERROR: {description} failed.")print(e.stderr) # Print the actual error from the scriptsys.exit(1)def main():atexit.register(cleanup)# --- FIX IS HERE: We pass the file paths as a list ---run_command(["database/database_setup.py"], "Initializing database")run_command(["scripts/seed_db.py"], "Seeding initial data")# Start the background data pipelineprint("π‘ Starting background data pipeline...")1 unmodified linebg_process = subprocess.Popen([sys.executable, "main.py"])print(f"β Data pipeline started with PID: {bg_process.pid}")# Start the Streamlit appprint("π Starting Streamlit dashboard...")try:subprocess.run(["streamlit", "run", "app.py", "--server.port", "8501", "--server.headless", "true"],check=True)finally:cleanup()if __name__ == "__main__":main()
run.py+22-22