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