Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	| #!/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!") |