File size: 3,203 Bytes
e2bca25 |
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 |
#!/usr/bin/env python3
"""
Test script to verify the setup for HF Space
"""
def test_imports():
"""Test if all required modules can be imported"""
print("π§ͺ Testing imports...")
try:
import gradio as gr
print("β
Gradio imported successfully")
except ImportError as e:
print(f"β Gradio import failed: {e}")
return False
try:
import torch
print(f"β
PyTorch imported successfully (version: {torch.__version__})")
except ImportError as e:
print(f"β PyTorch import failed: {e}")
return False
try:
import torchaudio
print(f"β
TorchAudio imported successfully")
except ImportError as e:
print(f"β TorchAudio import failed: {e}")
return False
return True
def test_hf_ac_imports():
"""Test hf_AC specific imports"""
print("\nπ Testing hf_AC imports...")
import sys
from pathlib import Path
# Add hf_AC to path
current_dir = Path(__file__).parent
hf_ac_path = current_dir / "hf_AC"
if not hf_ac_path.exists():
print("β hf_AC directory not found")
return False
sys.path.insert(0, str(hf_ac_path))
try:
from hf_AC.mmaudio.eval_utils import ModelConfig, all_model_cfg
print("β
hf_AC eval_utils imported successfully")
if all_model_cfg:
print(f"β
Available model variants: {list(all_model_cfg.keys())}")
else:
print("β οΈ No model configurations found")
except ImportError as e:
print(f"β hf_AC import failed: {e}")
return False
return True
def test_gradio_interface():
"""Test basic Gradio interface creation"""
print("\nπ¨ Testing Gradio interface...")
try:
import gradio as gr
def dummy_function(text):
return f"Echo: {text}"
# Create a simple interface
iface = gr.Interface(
fn=dummy_function,
inputs=gr.Textbox(label="Test Input"),
outputs=gr.Textbox(label="Test Output"),
title="Test Interface"
)
print("β
Gradio interface created successfully")
return True
except Exception as e:
print(f"β Gradio interface creation failed: {e}")
return False
def main():
"""Main test function"""
print("π Starting HF Space setup verification")
print("=" * 50)
# Test basic imports
if not test_imports():
print("\nβ Basic import test failed")
return False
# Test hf_AC imports
if not test_hf_ac_imports():
print("\nβ οΈ hf_AC import test failed (this is expected if model files are not downloaded)")
# Test Gradio interface
if not test_gradio_interface():
print("\nβ Gradio interface test failed")
return False
print("\n" + "=" * 50)
print("β
Setup verification completed successfully!")
print("π΅ Your HF Space should be ready to deploy")
return True
if __name__ == "__main__":
success = main()
exit(0 if success else 1)
|