File size: 1,642 Bytes
6f2c7f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
MIMO - HuggingFace Spaces Entry Point
Clean version with all dependencies pre-installed during build
"""

# CRITICAL: Import spaces FIRST before any CUDA initialization
# This must be the very first import to avoid CUDA initialization conflicts
try:
    import spaces
    HAS_SPACES = True
    print("βœ… HF Spaces GPU support available")
except ImportError:
    HAS_SPACES = False
    print("⚠️ spaces package not available")

import os
import sys
import gradio as gr

print("πŸš€ MIMO HuggingFace Spaces starting...")
print(f"πŸ“ Python: {sys.version}")
print(f"πŸ“‚ Working dir: {os.getcwd()}")

# Import the complete MIMO implementation
try:
    from app_hf_spaces import CompleteMIMO, gradio_interface
    print("βœ… Successfully imported MIMO modules")
except ImportError as e:
    print(f"❌ Import error: {e}")
    import traceback
    traceback.print_exc()
    raise

# HuggingFace Spaces GPU decorator
if HAS_SPACES:

    @spaces.GPU(duration=120)
    def warmup():
        """GPU warmup for HF Spaces detection"""
        import torch
        if torch.cuda.is_available():
            x = torch.randn(1, device='cuda')
            return f"GPU: {torch.cuda.get_device_name()}"
        return "CPU mode"
else:
    warmup = lambda: "CPU mode"

# Launch the Gradio interface
if __name__ == "__main__":
    print("🎬 Creating MIMO interface...")

    # Create the interface
    demo = gradio_interface()

    print("🌐 Launching web server...")
    demo.queue(max_size=20)
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        show_error=True
    )