Spaces:
Runtime error
Runtime error
da03
commited on
Commit
ยท
0473ddc
1
Parent(s):
d83ec2c
- 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()
|