Spaces:
Paused
Paused
File size: 1,874 Bytes
7384874 afc5295 7384874 afc5295 7384874 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import os
import subprocess
import secrets
import string
def generate_secure_string(length=32):
"""Generate a secure random string."""
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for _ in range(length))
def run_langfuse():
# Hardcoded configuration with dynamically generated secrets
env_vars = {
# Postgres database - using SQLite as a simple alternative
'DATABASE_URL': 'file:///data/langfuse.db',
# Dynamically generated secrets
'NEXTAUTH_URL': 'https://chris4k-langfuse.hf.space',
'NEXTAUTH_SECRET': generate_secure_string(64),
'SALT': generate_secure_string(32),
'ENCRYPTION_KEY': secrets.token_hex(32), # 64-character hex string
# Additional configuration
'HOSTNAME': '0.0.0.0',
'PORT': '3000',
# Disable signup if needed
'AUTH_DISABLE_SIGNUP': 'false',
# Optional: Initial user creation
'LANGFUSE_INIT_USER_EMAIL': 'admin@example.com',
'LANGFUSE_INIT_USER_PASSWORD': generate_secure_string(12),
}
# Pull Langfuse Docker image
subprocess.run(['docker', 'pull', 'langfuse/langfuse:2'], check=True)
# Prepare Docker run command
docker_cmd = [
'docker', 'run', '-d',
'-p', '3000:3000',
'-v', '/data:/data' # Persist data
]
# Add environment variables
for key, value in env_vars.items():
docker_cmd.extend(['-e', f'{key}={value}'])
docker_cmd.append('langfuse/langfuse:2')
# Run the container
subprocess.run(docker_cmd, check=True)
print("Langfuse is running!")
print(f"Initial admin email: {env_vars['LANGFUSE_INIT_USER_EMAIL']}")
print(f"Initial admin password: {env_vars['LANGFUSE_INIT_USER_PASSWORD']}")
if __name__ == "__main__":
run_langfuse() |