Spaces:
tkionline
/
Runtime error

File size: 3,321 Bytes
59edf5a
 
 
 
 
 
 
 
 
 
 
6a188d0
59edf5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import sys
import importlib.util
import threading
import time
from datetime import datetime
from huggingface_hub import hf_hub_download

# ==========================================
# KONFIGURASI - GANTI SESUAI REPO ANDA
# ==========================================
DATASET_REPO = "malikrf22/abcx"  
CORE_ENGINE_FILE = "core_engine.py"
REFRESH_INTERVAL = 24 * 60 * 60  
# ==========================================
# AUTO-REFRESH FUNCTION
# ==========================================
def auto_refresh_scheduler():
    """Refresh otomatis setiap 24 jam"""
    while True:
        time.sleep(REFRESH_INTERVAL)
        print("\n" + "=" * 60)
        print(f"πŸ”„ AUTO-REFRESH TRIGGERED at {datetime.now()}")
        print("=" * 60)
        
        # Restart aplikasi
        os.execv(sys.executable, ['python'] + sys.argv)

def start_auto_refresh():
    """Jalankan auto-refresh di background thread"""
    refresh_thread = threading.Thread(target=auto_refresh_scheduler, daemon=True)
    refresh_thread.start()
    print(f"⏰ Auto-refresh dijadwalkan setiap 24 jam")
    print(f"   Next refresh: {datetime.now().replace(hour=(datetime.now().hour + 24) % 24)}")

# ==========================================
# CORE ENGINE LOADER
# ==========================================
def load_core_engine():
    """Download dan load core_engine.py dari dataset private"""
    
    print("=" * 60)
    print("πŸš€ SEEDANCE 2.0 - LOADER")
    print("=" * 60)
    
    # Ambil token dari environment
    hf_token = os.environ.get("HF_TOKEN")
    
    if not hf_token:
        print("❌ ERROR: HF_TOKEN tidak ditemukan!")
        print("   Pastikan Anda sudah menambahkan HF_TOKEN di Space Secrets")
        sys.exit(1)
    
    print(f"βœ… HF_TOKEN ditemukan")
    print(f"πŸ“¦ Dataset: {DATASET_REPO}")
    print(f"πŸ“„ Loading: {CORE_ENGINE_FILE}")
    
    # SET ENVIRONMENT VARIABLES SEBELUM LOAD MODULE
    os.environ["SEEDANCE_DATASET_REPO"] = DATASET_REPO
    os.environ["SEEDANCE_HF_TOKEN"] = hf_token
    
    try:
        # Download core_engine.py dari dataset
        local_path = hf_hub_download(
            repo_id=DATASET_REPO,
            filename=CORE_ENGINE_FILE,
            repo_type="dataset",
            token=hf_token
        )
        
        print(f"βœ… File downloaded: {local_path}")
        
        # Load module dari file
        spec = importlib.util.spec_from_file_location("core_engine", local_path)
        core_engine = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(core_engine)
        
        print("βœ… Core engine loaded successfully!")
        print("=" * 60)
        
        return core_engine
        
    except Exception as e:
        print(f"❌ ERROR loading core engine: {str(e)}")
        import traceback
        traceback.print_exc()
        sys.exit(1)

# ==========================================
# MAIN
# ==========================================
if __name__ == "__main__":
    # Mulai auto-refresh scheduler
    start_auto_refresh()
    
    # Load core engine dari dataset
    core_engine = load_core_engine()
    
    # Jalankan aplikasi
    demo = core_engine.create_app()
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        ssr_mode=False  # Disable SSR untuk menghindari warning
    )