File size: 839 Bytes
e8b11ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import subprocess
import time
import threading

# 1. Auto-detect the Hugging Face Space URL
repo = os.getenv('HF_SPACE_ID', 'user/space')
parts = repo.split('/')
url = f'https://{parts[0].lower()}-{parts[1].lower()}.hf.space/'

# 2. Build the configuration environment
env = os.environ.copy()
env.update({
    'N8N_PORT': '7860',
    'N8N_DATABASE_TYPE': 'sqlite',
    'N8N_USER_FOLDER': '/data/.n8n',
    'N8N_ENCRYPTION_KEY': 'auto-generated-hf-n8n-key-998877',
    'WEBHOOK_URL': url,
    'N8N_EDITOR_BASE_URL': url
})

# 3. Print a clean, clear box in the logs with your exact link
def print_link():
    time.sleep(5)
    print("\n" + "="*60)
    print(f"👉 CLICK YOUR DIRECT LINK HERE: {url}")
    print("="*60 + "\n")

threading.Thread(target=print_link).start()

# 4. Launch n8n
subprocess.run(['n8n', 'start'], env=env)