neural-os / debug_hf_spaces.py
da03
.
0473ddc
#!/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()