File size: 3,277 Bytes
0473ddc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
"""
Debug script to test HF Spaces environment
"""
import os
import sys
import subprocess
import time
import requests
from pathlib import Path

def check_files():
    """Check if required files exist"""
    print("๐Ÿ” Checking required files...")
    files_to_check = [
        "dispatcher.py",
        "worker.py", 
        "utils.py",
        "latent_stats.json",
        "static/index.html",
        "requirements.txt"
    ]
    
    for file in files_to_check:
        if os.path.exists(file):
            print(f"โœ… {file} exists")
        else:
            print(f"โŒ {file} missing")
    
    print(f"๐Ÿ“ Current directory: {os.getcwd()}")
    print(f"๐Ÿ“‹ Directory contents:")
    for item in os.listdir('.'):
        print(f"   {item}")

def test_imports():
    """Test if imports work"""
    print("\n๐Ÿ” Testing imports...")
    try:
        import torch
        print(f"โœ… torch {torch.__version__}")
    except Exception as e:
        print(f"โŒ torch failed: {e}")
    
    try:
        from utils import initialize_model
        print("โœ… utils imports work")
    except Exception as e:
        print(f"โŒ utils import failed: {e}")
    
    try:
        import fastapi
        print(f"โœ… fastapi {fastapi.__version__}")
    except Exception as e:
        print(f"โŒ fastapi failed: {e}")

def test_dispatcher():
    """Test dispatcher startup"""
    print("\n๐Ÿ” Testing dispatcher...")
    try:
        # Try to start dispatcher
        proc = subprocess.Popen([
            sys.executable, "dispatcher.py", "--port", "7860"
        ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        
        # Wait a bit
        time.sleep(3)
        
        # Check if it's running
        if proc.poll() is None:
            print("โœ… Dispatcher process is running")
            
            # Test HTTP request
            try:
                response = requests.get("http://localhost:7860/", timeout=5)
                if response.status_code == 200:
                    print("โœ… Dispatcher HTTP response OK")
                else:
                    print(f"โš ๏ธ Dispatcher HTTP status: {response.status_code}")
            except Exception as e:
                print(f"โŒ Dispatcher HTTP test failed: {e}")
                
        else:
            print("โŒ Dispatcher process died")
            stdout, stderr = proc.communicate()
            print(f"๐Ÿ“‹ Stdout: {stdout.decode()}")
            print(f"๐Ÿ“‹ Stderr: {stderr.decode()}")
        
        # Clean up
        proc.terminate()
        proc.wait()
        
    except Exception as e:
        print(f"โŒ Failed to test dispatcher: {e}")

def main():
    print("๐Ÿš€ HF Spaces Debug Script")
    print("=" * 50)
    
    check_files()
    test_imports()
    test_dispatcher()
    
    print("\n๐Ÿ“Š Environment info:")
    print(f"Python: {sys.version}")
    print(f"Platform: {sys.platform}")
    print(f"CWD: {os.getcwd()}")
    
    # Check for GPU
    try:
        import torch
        if torch.cuda.is_available():
            print(f"๐ŸŽฎ CUDA available: {torch.cuda.device_count()} devices")
        else:
            print("๐Ÿ’ป Running on CPU")
    except:
        print("โ“ Cannot check GPU status")

if __name__ == "__main__":
    main()