Chris4K commited on
Commit
7384874
·
verified ·
1 Parent(s): 5713d5e

Update app.py

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