| | |
| | """ |
| | Hugging Face Spaces entry point for Legal Position AI Analyzer |
| | """ |
| | import os |
| | import sys |
| | import warnings |
| | import logging |
| | from pathlib import Path |
| |
|
| | |
| | warnings.filterwarnings("ignore", message=".*Invalid file descriptor.*") |
| | logging.getLogger("asyncio").setLevel(logging.CRITICAL) |
| |
|
| | |
| | |
| | _original_unraisablehook = sys.unraisablehook |
| |
|
| | def _suppress_asyncio_fd_errors(unraisable): |
| | if (unraisable.exc_type is ValueError and |
| | "Invalid file descriptor" in str(unraisable.exc_value)): |
| | return |
| | _original_unraisablehook(unraisable) |
| |
|
| | sys.unraisablehook = _suppress_asyncio_fd_errors |
| |
|
| | |
| | os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0' |
| | os.environ['GRADIO_SERVER_PORT'] = '7860' |
| | |
| | os.environ.setdefault('UVICORN_LOOP', 'asyncio') |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | project_root = Path(__file__).parent |
| | sys.path.insert(0, str(project_root)) |
| |
|
| | |
| | def run_network_diagnostics(): |
| | """Check outbound network connectivity from HF Spaces container.""" |
| | import urllib.request |
| | import socket |
| | |
| | print("=" * 50) |
| | print("🔍 NETWORK DIAGNOSTICS") |
| | print("=" * 50) |
| | |
| | |
| | proxy_vars = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy', 'NO_PROXY', 'no_proxy', 'ALL_PROXY'] |
| | print("\n📡 Proxy environment variables:") |
| | for var in proxy_vars: |
| | val = os.environ.get(var) |
| | if val: |
| | print(f" {var} = {val}") |
| | if not any(os.environ.get(v) for v in proxy_vars): |
| | print(" (none set)") |
| | |
| | |
| | hosts = ['api.anthropic.com', 'api.openai.com', 'generativelanguage.googleapis.com'] |
| | print("\n🌐 DNS resolution:") |
| | for host in hosts: |
| | try: |
| | ip = socket.gethostbyname(host) |
| | print(f" ✅ {host} -> {ip}") |
| | except socket.gaierror as e: |
| | print(f" ❌ {host} -> DNS FAILED: {e}") |
| | |
| | |
| | print("\n🔌 HTTPS connectivity:") |
| | test_urls = [ |
| | ('https://api.anthropic.com', 'Anthropic API'), |
| | ('https://api.openai.com', 'OpenAI API'), |
| | ('https://httpbin.org/get', 'httpbin (general internet)'), |
| | ] |
| | for url, name in test_urls: |
| | try: |
| | req = urllib.request.Request(url, method='HEAD') |
| | req.add_header('User-Agent', 'connectivity-test/1.0') |
| | resp = urllib.request.urlopen(req, timeout=10) |
| | print(f" ✅ {name} ({url}) -> HTTP {resp.status}") |
| | except urllib.error.HTTPError as e: |
| | |
| | print(f" ✅ {name} ({url}) -> HTTP {e.code} (connection OK, auth expected)") |
| | except Exception as e: |
| | print(f" ❌ {name} ({url}) -> {type(e).__name__}: {e}") |
| | |
| | |
| | print("\n🔧 httpx connectivity test:") |
| | try: |
| | import httpx |
| | print(f" httpx version: {httpx.__version__}") |
| | |
| | with httpx.Client(timeout=10) as client: |
| | resp = client.get("https://api.anthropic.com") |
| | print(f" ✅ httpx (default) -> Anthropic HTTP {resp.status_code}") |
| | |
| | with httpx.Client(timeout=10, http2=False) as client: |
| | resp = client.get("https://api.openai.com") |
| | print(f" ✅ httpx (http1.1) -> OpenAI HTTP {resp.status_code}") |
| | |
| | try: |
| | with httpx.Client(timeout=10) as client: |
| | resp = client.get("https://api.openai.com") |
| | print(f" ✅ httpx (default) -> OpenAI HTTP {resp.status_code}") |
| | except Exception as e2: |
| | print(f" ⚠️ httpx (default/http2) -> OpenAI FAILED: {type(e2).__name__}: {e2}") |
| | except Exception as e: |
| | print(f" ❌ httpx -> {type(e).__name__}: {e}") |
| | |
| | print("=" * 50) |
| |
|
| | |
| |
|
| | |
| | from interface import create_gradio_interface |
| | from main import initialize_components |
| |
|
| | |
| | |
| | print("Initializing search components...") |
| | _init_ok = initialize_components() |
| | if _init_ok: |
| | print("Search components initialized successfully!") |
| | else: |
| | print("[WARNING] Search components initialization failed. Search functionality will be limited.") |
| |
|
| | |
| | demo = create_gradio_interface() |
| |
|
| | if __name__ == "__main__": |
| | |
| | run_network_diagnostics() |
| | |
| | print("🚀 Starting Legal Position AI Analyzer...") |
| | |
| | |
| | is_hf_space = os.environ.get('SPACE_ID') is not None |
| | |
| | |
| | |
| | if is_hf_space: |
| | |
| | demo.launch( |
| | server_name="0.0.0.0", |
| | server_port=7860, |
| | share=False, |
| | show_error=True, |
| | ssr_mode=False, |
| | ) |
| | else: |
| | |
| | demo.launch( |
| | share=False, |
| | show_error=True, |
| | ) |
| |
|