File size: 2,953 Bytes
ea81a05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45c7380
ea81a05
 
16fde56
e9655e8
 
 
 
 
 
 
 
 
 
 
 
45c7380
e9655e8
16fde56
 
ea81a05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45c7380
 
 
ea81a05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Entry point for Heavy 2.0."""

import os
import sys

# Detect if running on Hugging Face Spaces
IS_SPACE = os.getenv("SPACE_ID") is not None

if not IS_SPACE:
    # Local configuration only
    os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
    os.environ["GRADIO_SERVER_NAME"] = "127.0.0.1"
    
    # Remove proxy settings that might interfere
    for proxy_var in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy', 'ALL_PROXY', 'all_proxy']:
        if proxy_var in os.environ:
            del os.environ[proxy_var]
    
    # Set no proxy to bypass any remaining proxy configs
    os.environ["NO_PROXY"] = "*"
    os.environ["no_proxy"] = "*"

# Monkey-patch Gradio to avoid schema generation crashes on Spaces
import gradio
gradio.version_check = lambda: None  # Disable version check
try:
    # Make schema-to-python conversion tolerant of booleans or other unexpected shapes
    import gradio_client.utils as grc_utils

    _orig_json_schema_to_python_type = grc_utils.json_schema_to_python_type

    def _safe_json_schema_to_python_type(schema, defs=None):
        if isinstance(schema, bool):
            return "any"
        try:
            return _orig_json_schema_to_python_type(schema, defs)
        except Exception:
            return "any"

    grc_utils.json_schema_to_python_type = _safe_json_schema_to_python_type
except Exception:
    pass

# Import the demo from multi_web_combined (with chat support!)
from src.multi_web_combined import demo

if __name__ == "__main__":
    print("πŸ€– Heavy 2.0 - Starting...")

    # Enable queue for better performance
    demo.queue()

    if IS_SPACE:
        # Hugging Face Spaces configuration
        print("🌐 Running on Hugging Face Spaces")
        demo.launch(
            show_error=True,
            show_api=False,
            share=True,  # Required when localhost not accessible in Spaces
            server_name="0.0.0.0",
            server_port=7860,
        )
    else:
        # Local development configuration
        print("🌐 Server will be available at: http://127.0.0.1:7860")
        print()

        try:
            demo.launch(
                server_name="127.0.0.1",  # Local only to avoid network issues
                server_port=7860,
                share=False,
                show_error=True,
                favicon_path=None,
                inbrowser=True,  # Auto-open browser
                show_api=False,  # Disable API documentation
                prevent_thread_lock=False
            )
        except Exception as e:
            print(f"❌ Error launching: {e}")
            print("\nπŸ’‘ Try opening http://127.0.0.1:7860 in your browser manually")
            # Keep server running even if browser launch fails
            import time
            try:
                while True:
                    time.sleep(1)
            except KeyboardInterrupt:
                print("\nπŸ‘‹ Shutting down...")