Spaces:
Sleeping
Sleeping
Commit Β·
00a3cc2
1
Parent(s): 8af35ac
Updates run.py to use direct file paths
Browse files6 unmodified lines789101011121314161516172 unmodified lines202122252627232425293031262728293031323333343536343536373938394243444041424344451 unmodified line4748495250515455565758525354555657585960616 unmodified lines
bg_process = None
def cleanup(): """Ensure background process is terminated on script exit.""" global bg_process if 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 reliable try: os.kill(bg_process.pid, signal.SIGTERM) bg_process.wait(timeout=5)2 unmodified lines bg_process.kill() print("β
Pipeline terminated.")
def run_command(command, description): """Runs a setup command and exits if it fails."""def run_command(command_args, description): """Runs a setup command using its file path and exits if it fails.""" print(f"π {description}...") # Use sys.executable to ensure we use the python from the correct venv result = subprocess.run([sys.executable, "-m", command], capture_output=True, text=True) if result.returncode != 0: 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(result.stderr) sys.exit(result.returncode) print(f"β
{description} complete.")
print(e.stderr) # Print the actual error from the script sys.exit(1)
def main(): # Register the cleanup function to be called on any script exit atexit.register(cleanup)
# Initialize and Seed run_command("database/database_setup.py", "Initializing database") run_command("scripts/seed_db.py", "Seeding initial data") # --- 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 pipeline print("π‘ Starting background data pipeline...")1 unmodified line bg_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) # Start the Streamlit app print("π Starting Streamlit dashboard...")
subprocess.run( ["streamlit", "run", "app.py", "--server.port", "8501", "--server.headless", "true"] )
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