da03 commited on
Commit
0473ddc
ยท
1 Parent(s): d83ec2c
Files changed (1) hide show
  1. debug_hf_spaces.py +119 -0
debug_hf_spaces.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Debug script to test HF Spaces environment
4
+ """
5
+ import os
6
+ import sys
7
+ import subprocess
8
+ import time
9
+ import requests
10
+ from pathlib import Path
11
+
12
+ def check_files():
13
+ """Check if required files exist"""
14
+ print("๐Ÿ” Checking required files...")
15
+ files_to_check = [
16
+ "dispatcher.py",
17
+ "worker.py",
18
+ "utils.py",
19
+ "latent_stats.json",
20
+ "static/index.html",
21
+ "requirements.txt"
22
+ ]
23
+
24
+ for file in files_to_check:
25
+ if os.path.exists(file):
26
+ print(f"โœ… {file} exists")
27
+ else:
28
+ print(f"โŒ {file} missing")
29
+
30
+ print(f"๐Ÿ“ Current directory: {os.getcwd()}")
31
+ print(f"๐Ÿ“‹ Directory contents:")
32
+ for item in os.listdir('.'):
33
+ print(f" {item}")
34
+
35
+ def test_imports():
36
+ """Test if imports work"""
37
+ print("\n๐Ÿ” Testing imports...")
38
+ try:
39
+ import torch
40
+ print(f"โœ… torch {torch.__version__}")
41
+ except Exception as e:
42
+ print(f"โŒ torch failed: {e}")
43
+
44
+ try:
45
+ from utils import initialize_model
46
+ print("โœ… utils imports work")
47
+ except Exception as e:
48
+ print(f"โŒ utils import failed: {e}")
49
+
50
+ try:
51
+ import fastapi
52
+ print(f"โœ… fastapi {fastapi.__version__}")
53
+ except Exception as e:
54
+ print(f"โŒ fastapi failed: {e}")
55
+
56
+ def test_dispatcher():
57
+ """Test dispatcher startup"""
58
+ print("\n๐Ÿ” Testing dispatcher...")
59
+ try:
60
+ # Try to start dispatcher
61
+ proc = subprocess.Popen([
62
+ sys.executable, "dispatcher.py", "--port", "7860"
63
+ ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
64
+
65
+ # Wait a bit
66
+ time.sleep(3)
67
+
68
+ # Check if it's running
69
+ if proc.poll() is None:
70
+ print("โœ… Dispatcher process is running")
71
+
72
+ # Test HTTP request
73
+ try:
74
+ response = requests.get("http://localhost:7860/", timeout=5)
75
+ if response.status_code == 200:
76
+ print("โœ… Dispatcher HTTP response OK")
77
+ else:
78
+ print(f"โš ๏ธ Dispatcher HTTP status: {response.status_code}")
79
+ except Exception as e:
80
+ print(f"โŒ Dispatcher HTTP test failed: {e}")
81
+
82
+ else:
83
+ print("โŒ Dispatcher process died")
84
+ stdout, stderr = proc.communicate()
85
+ print(f"๐Ÿ“‹ Stdout: {stdout.decode()}")
86
+ print(f"๐Ÿ“‹ Stderr: {stderr.decode()}")
87
+
88
+ # Clean up
89
+ proc.terminate()
90
+ proc.wait()
91
+
92
+ except Exception as e:
93
+ print(f"โŒ Failed to test dispatcher: {e}")
94
+
95
+ def main():
96
+ print("๐Ÿš€ HF Spaces Debug Script")
97
+ print("=" * 50)
98
+
99
+ check_files()
100
+ test_imports()
101
+ test_dispatcher()
102
+
103
+ print("\n๐Ÿ“Š Environment info:")
104
+ print(f"Python: {sys.version}")
105
+ print(f"Platform: {sys.platform}")
106
+ print(f"CWD: {os.getcwd()}")
107
+
108
+ # Check for GPU
109
+ try:
110
+ import torch
111
+ if torch.cuda.is_available():
112
+ print(f"๐ŸŽฎ CUDA available: {torch.cuda.device_count()} devices")
113
+ else:
114
+ print("๐Ÿ’ป Running on CPU")
115
+ except:
116
+ print("โ“ Cannot check GPU status")
117
+
118
+ if __name__ == "__main__":
119
+ main()