File size: 5,163 Bytes
26a93c4
 
 
 
 
 
 
 
402e17d
df9e43a
26a93c4
 
 
 
df9e43a
 
402e17d
 
 
df9e43a
402e17d
 
 
 
 
 
 
 
 
df9e43a
402e17d
df9e43a
402e17d
df9e43a
 
402e17d
df9e43a
 
 
26a93c4
402e17d
 
df9e43a
 
 
 
 
 
 
 
402e17d
df9e43a
 
402e17d
df9e43a
402e17d
df9e43a
 
 
 
 
 
 
 
 
 
 
 
 
 
402e17d
df9e43a
 
 
402e17d
df9e43a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402e17d
df9e43a
402e17d
df9e43a
 
 
 
 
 
 
 
 
 
 
 
 
 
26a93c4
df9e43a
402e17d
26a93c4
 
df9e43a
26a93c4
df9e43a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26a93c4
 
402e17d
df9e43a
 
 
 
 
 
 
 
26a93c4
df9e43a
 
 
 
 
 
 
 
 
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
"""
Hugging Face Spaces entry point for WanGP
This file imports and runs the main WanGP application
"""

import sys
import os
import traceback
import time

# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

print("===== Application Startup at", time.strftime("%Y-%m-%d %H:%M:%S"), "=====")
print()
print("Starting WanGP for Hugging Face Spaces...")
print(f"Python version: {sys.version}")

# Check torch availability with detailed logging
try:
    import torch
    print(f"PyTorch version: {torch.__version__}")
    print(f"CUDA available: {torch.cuda.is_available()}")
    if torch.cuda.is_available():
        print(f"CUDA version: {torch.version.cuda}")
        print(f"GPU count: {torch.cuda.device_count()}")
except Exception as e:
    print(f"Error checking PyTorch: {e}")
    traceback.print_exc()

# Set environment variable to force CPU mode for debugging
print("Forcing CPU mode for HF Spaces compatibility")
os.environ['CUDA_VISIBLE_DEVICES'] = ''
os.environ['HF_HUB_DISABLE_PROGRESS_BARS'] = '1'

print("Attempting to import WanGP...")

# Import Gradio first
try:
    import gradio as gr
    print("Gradio imported successfully")
except Exception as e:
    print(f"Error importing Gradio: {e}")
    traceback.print_exc()
    sys.exit(1)

# Try to import WanGP step by step
try:
    print("Importing WanGP modules...")
    
    # Import main wgp module with detailed error reporting
    print("Importing wgp module...")
    import wgp
    print("WanGP module imported successfully!")
    
    # Check if there's a demo variable or function
    if hasattr(wgp, 'demo'):
        print("Found demo variable in wgp module")
        demo = wgp.demo
    elif hasattr(wgp, 'create_ui'):
        print("Found create_ui function in wgp module")
        demo = wgp.create_ui()
    elif hasattr(wgp, 'launch'):
        print("Found launch function in wgp module")
        demo = wgp.launch()
    else:
        print("No standard demo interface found, searching for available attributes...")
        attributes = [attr for attr in dir(wgp) if not attr.startswith('_')]
        print(f"Available attributes in wgp: {attributes[:10]}...")  # Show first 10
        
        # Try to find gradio-related attributes
        gradio_attrs = [attr for attr in attributes if 'demo' in attr.lower() or 'ui' in attr.lower() or 'interface' in attr.lower()]
        print(f"Gradio-related attributes: {gradio_attrs}")
        
        if gradio_attrs:
            demo = getattr(wgp, gradio_attrs[0])
            print(f"Using {gradio_attrs[0]} as demo")
        else:
            # Create a simple fallback interface
            print("Creating fallback interface...")
            def placeholder():
                return "WanGP is loading... Please check the logs for more details."
            
            demo = gr.Interface(
                fn=placeholder,
                inputs=gr.Textbox(label="Status"),
                outputs=gr.Textbox(label="Response"),
                title="WanGP - Loading...",
                description="The application is starting up. Please wait or check the logs for more information."
            )
    
    print("Demo interface prepared successfully!")
    
    # Launch the demo
    print("Launching demo...")
    if hasattr(demo, 'launch'):
        demo.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=False,
            show_error=True,
            quiet=False
        )
    else:
        print(f"Demo object type: {type(demo)}")
        print("Demo object does not have launch method")
        
except Exception as e:
    print(f"Error importing or launching WanGP: {e}")
    print("Full traceback:")
    traceback.print_exc()
    
    # Create error page
    def show_error():
        error_msg = f"""
        # WanGP - Initialization Error
        
        **Error:** {str(e)}
        
        **Python Version:** {sys.version}
        
        **Working Directory:** {os.getcwd()}
        
        **Python Path:** {sys.path[:3]}...
        
        **Environment Variables:**
        - CUDA_VISIBLE_DEVICES: {os.environ.get('CUDA_VISIBLE_DEVICES', 'Not set')}
        - HF_HUB_DISABLE_PROGRESS_BARS: {os.environ.get('HF_HUB_DISABLE_PROGRESS_BARS', 'Not set')}
        
        **Full Error Traceback:**
        ```
        {traceback.format_exc()}
        ```
        
        Please check the logs for more detailed information.
        """
        return error_msg
    
    with gr.Blocks(title="WanGP - Error") as demo:
        gr.Markdown(show_error())
        
        with gr.Row():
            restart_btn = gr.Button("Restart Application", variant="primary")
            
            def restart():
                return "Restarting... Please refresh the page in a few moments."
            
            restart_btn.click(restart, outputs=gr.Textbox(label="Status"))
    
    print("Error page created, launching...")
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False,
        show_error=True,
        quiet=False
    )

print("Application startup completed!")