Update app.py
Browse files
app.py
CHANGED
|
@@ -2916,4 +2916,157 @@ def create_demo_interface():
|
|
| 2916 |
|
| 2917 |
logger.info("β
Demo interface created successfully with modern UI integration")
|
| 2918 |
|
| 2919 |
-
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2916 |
|
| 2917 |
logger.info("β
Demo interface created successfully with modern UI integration")
|
| 2918 |
|
| 2919 |
+
return demo
|
| 2920 |
+
|
| 2921 |
+
# ===========================================
|
| 2922 |
+
# DARK MODE TOGGLE FUNCTION
|
| 2923 |
+
# ===========================================
|
| 2924 |
+
|
| 2925 |
+
def create_dark_mode_toggle():
|
| 2926 |
+
"""Create a dark mode toggle button with JavaScript"""
|
| 2927 |
+
return f"""
|
| 2928 |
+
<div id="darkModeToggle" class="dark-mode-toggle" onclick="toggleDarkMode()"
|
| 2929 |
+
title="Toggle Dark Mode">
|
| 2930 |
+
<span id="darkModeIcon" style="font-size: 24px;">π</span>
|
| 2931 |
+
</div>
|
| 2932 |
+
|
| 2933 |
+
<script>
|
| 2934 |
+
// Check for saved theme or prefer-color-scheme
|
| 2935 |
+
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 2936 |
+
const savedTheme = localStorage.getItem('theme');
|
| 2937 |
+
const theme = savedTheme || (prefersDark ? 'dark' : 'light');
|
| 2938 |
+
|
| 2939 |
+
// Apply theme
|
| 2940 |
+
document.documentElement.setAttribute('data-theme', theme);
|
| 2941 |
+
updateDarkModeIcon(theme);
|
| 2942 |
+
|
| 2943 |
+
function toggleDarkMode() {{
|
| 2944 |
+
const currentTheme = document.documentElement.getAttribute('data-theme');
|
| 2945 |
+
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
| 2946 |
+
|
| 2947 |
+
// Update theme
|
| 2948 |
+
document.documentElement.setAttribute('data-theme', newTheme);
|
| 2949 |
+
localStorage.setItem('theme', newTheme);
|
| 2950 |
+
|
| 2951 |
+
// Update icon
|
| 2952 |
+
updateDarkModeIcon(newTheme);
|
| 2953 |
+
|
| 2954 |
+
// Dispatch event for components that need to know
|
| 2955 |
+
document.dispatchEvent(new CustomEvent('themechange', {{ detail: {{ theme: newTheme }} }}));
|
| 2956 |
+
}}
|
| 2957 |
+
|
| 2958 |
+
function updateDarkModeIcon(theme) {{
|
| 2959 |
+
const icon = document.getElementById('darkModeIcon');
|
| 2960 |
+
if (theme === 'dark') {{
|
| 2961 |
+
icon.textContent = 'βοΈ';
|
| 2962 |
+
icon.title = 'Switch to Light Mode';
|
| 2963 |
+
}} else {{
|
| 2964 |
+
icon.textContent = 'π';
|
| 2965 |
+
icon.title = 'Switch to Dark Mode';
|
| 2966 |
+
}}
|
| 2967 |
+
}}
|
| 2968 |
+
|
| 2969 |
+
// Listen for system theme changes
|
| 2970 |
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {{
|
| 2971 |
+
if (!localStorage.getItem('theme')) {{
|
| 2972 |
+
const newTheme = e.matches ? 'dark' : 'light';
|
| 2973 |
+
document.documentElement.setAttribute('data-theme', newTheme);
|
| 2974 |
+
updateDarkModeIcon(newTheme);
|
| 2975 |
+
}}
|
| 2976 |
+
}});
|
| 2977 |
+
</script>
|
| 2978 |
+
"""
|
| 2979 |
+
|
| 2980 |
+
# ===========================================
|
| 2981 |
+
# MAIN EXECUTION - CRITICAL: THIS LAUNCHES THE APP
|
| 2982 |
+
# ===========================================
|
| 2983 |
+
|
| 2984 |
+
def main():
|
| 2985 |
+
"""Main entry point that actually launches the Gradio app"""
|
| 2986 |
+
try:
|
| 2987 |
+
logger.info("π ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION")
|
| 2988 |
+
logger.info("=" * 60)
|
| 2989 |
+
logger.info("Enhanced with clear OSS vs Enterprise boundaries")
|
| 2990 |
+
logger.info("DOCTRINAL COMPLIANCE: Historical Evidence, Observation Gate, Sequencing")
|
| 2991 |
+
logger.info("PHASE 2: Dynamic Performance Metrics by Scenario")
|
| 2992 |
+
logger.info(f"Modern UI: {'Enabled' if get_feature_flags().get('modern_ui', True) else 'Disabled'}")
|
| 2993 |
+
logger.info(f"True ARF OSS v3.3.9 integration with simulated Enterprise execution")
|
| 2994 |
+
logger.info("=" * 60)
|
| 2995 |
+
|
| 2996 |
+
# Create the demo interface
|
| 2997 |
+
demo = create_demo_interface()
|
| 2998 |
+
|
| 2999 |
+
print("\n" + "="*60)
|
| 3000 |
+
print("π ARF Ultimate Investor Demo v3.3.9 - ENTERPRISE EDITION")
|
| 3001 |
+
print("π Architecture: OSS advises β Enterprise executes")
|
| 3002 |
+
print("π DOCTRINAL: Historical Evidence + Observation Gate + Sequencing")
|
| 3003 |
+
print("π¨ MODERN UI: Design system with responsive components")
|
| 3004 |
+
print("π Starting on http://localhost:7860")
|
| 3005 |
+
print("="*60 + "\n")
|
| 3006 |
+
|
| 3007 |
+
# Launch with configuration for Hugging Face Spaces
|
| 3008 |
+
launch_config = {
|
| 3009 |
+
"server_name": "0.0.0.0",
|
| 3010 |
+
"server_port": 7860,
|
| 3011 |
+
"share": False,
|
| 3012 |
+
"favicon_path": None,
|
| 3013 |
+
"quiet": False,
|
| 3014 |
+
"show_error": True,
|
| 3015 |
+
"debug": False,
|
| 3016 |
+
"max_threads": 40,
|
| 3017 |
+
}
|
| 3018 |
+
|
| 3019 |
+
# Add CSS if available
|
| 3020 |
+
css_styles = load_css_files()
|
| 3021 |
+
if css_styles:
|
| 3022 |
+
launch_config["css"] = css_styles
|
| 3023 |
+
|
| 3024 |
+
logger.info(f"β
Launching demo with config: {launch_config}")
|
| 3025 |
+
|
| 3026 |
+
# LAUNCH THE DEMO - THIS IS THE CRITICAL PART
|
| 3027 |
+
demo.launch(**launch_config)
|
| 3028 |
+
|
| 3029 |
+
except KeyboardInterrupt:
|
| 3030 |
+
logger.info("π Demo stopped by user")
|
| 3031 |
+
except Exception as e:
|
| 3032 |
+
logger.error(f"β Fatal error: {e}", exc_info=True)
|
| 3033 |
+
print(f"\nβ ERROR: {e}")
|
| 3034 |
+
print("Please check the logs for more details.")
|
| 3035 |
+
sys.exit(1)
|
| 3036 |
+
|
| 3037 |
+
|
| 3038 |
+
# ===========================================
|
| 3039 |
+
# HUGGING FACE SPACES COMPATIBILITY
|
| 3040 |
+
# ===========================================
|
| 3041 |
+
|
| 3042 |
+
# This is the entry point that Hugging Face Spaces will use
|
| 3043 |
+
if __name__ == "__main__":
|
| 3044 |
+
# For Hugging Face Spaces, we need to ensure the app stays alive
|
| 3045 |
+
import os
|
| 3046 |
+
|
| 3047 |
+
# Set environment variables for better compatibility
|
| 3048 |
+
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
| 3049 |
+
os.environ["GRADIO_SERVER_PORT"] = "7860"
|
| 3050 |
+
os.environ["GRADIO_SERVER_NAME"] = "0.0.0.0"
|
| 3051 |
+
|
| 3052 |
+
print("\n" + "="*60)
|
| 3053 |
+
print("π ARF Demo Starting on Hugging Face Spaces")
|
| 3054 |
+
print(f"π Working directory: {os.getcwd()}")
|
| 3055 |
+
print(f"π Python version: {sys.version}")
|
| 3056 |
+
print("="*60 + "\n")
|
| 3057 |
+
|
| 3058 |
+
# Check for required files
|
| 3059 |
+
required_files = ["styles/modern.css", "styles/responsive.css", "ui/components.py"]
|
| 3060 |
+
missing_files = []
|
| 3061 |
+
|
| 3062 |
+
for file in required_files:
|
| 3063 |
+
if not os.path.exists(file):
|
| 3064 |
+
missing_files.append(file)
|
| 3065 |
+
print(f"β οΈ Warning: {file} not found")
|
| 3066 |
+
|
| 3067 |
+
if missing_files:
|
| 3068 |
+
print(f"β οΈ Missing {len(missing_files)} required files")
|
| 3069 |
+
print("β οΈ Some features may not work correctly")
|
| 3070 |
+
|
| 3071 |
+
# Start the main application
|
| 3072 |
+
main()
|