Spaces:
Runtime error
Runtime error
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() |