Spaces:
Sleeping
Sleeping
MINIMAL TEST: 3 pages with simple transitions
Browse filesFiles changed (2)
- app.py+14-44
- minimal_test.pyAdded+40
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465663 unmodified lines7071727374757677"""app.py โ Simplified entry point for hosting platforms (Render, Hugging Face, etc.)This file launches the full interface with login page support.No API key required โ users provide their own via the login page.For Hugging Face Spaces: demo object is created at module levelFor Render/local: can run with python app.py"""import osimport sysimport loggingfrom dotenv import load_dotenv# Configure logging BEFORE everything elselogging.basicConfig(level=logging.INFO,format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',handlers=[logging.FileHandler('app.log', encoding='utf-8'),logging.StreamHandler(sys.stdout)])logger = logging.getLogger(__name__)# Load .env if it exists (for local development)load_dotenv()# Apply proxy settings from .env if definedif os.getenv("http_proxy"):logger.info(f"Setting http_proxy: {os.getenv('http_proxy')}")os.environ["http_proxy"] = os.getenv("http_proxy")if os.getenv("https_proxy"):logger.info(f"Setting https_proxy: {os.getenv('https_proxy')}")os.environ["https_proxy"] = os.getenv("https_proxy")if os.getenv("no_proxy"):os.environ["no_proxy"] = os.getenv("no_proxy")import gradio as grimport student_interface# Create demo at module level for Hugging Face Spaceslogger.info("๐ Initializing Legacy Code Challenge...")has_key = bool(os.getenv("OPENAI_API_KEY"))if has_key:logger.info("โ API key detected in environment โ skipping login page")else:logger.info("๐ No API key found โ login page will be shown")try:demo = student_interface.create_full_interface()logger.info("โ Interface created successfully!")except Exception as e:logger.error(f"โ Failed to create interface: {e}", exc_info=True)raise# For local/Render deploymentif __name__ == "__main__":port = int(os.getenv("PORT", "7860"))logger.info(f"๐ Server will listen on 0.0.0.0:{port}")logger.info(f"๐ Launching Gradio on 0.0.0.0:{port}...")try:demo.launch(3 unmodified linesinbrowser=False,show_error=True,)logger.info("โ Gradio server started successfully!")except Exception as e:logger.error(f"โ Launch failed: {e}", exc_info=True)raise12345678910111213141516171819202122232425262728293031323334353 unmodified lines394041424344454647"""app.py โ MINIMAL TEST VERSIONTesting basic Gradio page transitions on HF Spaces.This version uses minimal_test.py instead of the full student_interface."""import osimport sysimport logging# Configure logginglogging.basicConfig(level=logging.INFO,format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',handlers=[logging.StreamHandler(sys.stdout)])logger = logging.getLogger(__name__)logger.info("=" * 80)logger.info("MINIMAL TEST - Testing Page Transitions")logger.info("=" * 80)import gradio as grfrom minimal_test import demologger.info("โ Minimal demo imported successfully!")# For local/Render/HF deploymentif __name__ == "__main__":port = int(os.getenv("PORT", "7860"))logger.info(f"๐ Launching on 0.0.0.0:{port}...")try:demo.launch(3 unmodified linesinbrowser=False,show_error=True,)logger.info("โ Demo started!")except Exception as e:logger.error(f"โ Launch failed: {e}", exc_info=True)raise
12345678910111213141516171819202122232425262728293031323334353637383940"""Minimal test - 3 pages with buttons to switch between them"""import gradio as gr
# Page 1with gr.Blocks() as demo: with gr.Column(visible=True) as page1: gr.Markdown("# ืขืืื 1 - ืืชืืื") gr.Markdown("ืืื ืืขืืื ืืจืืฉืื") btn1 = gr.Button("๐น ืืืฅ ืืื ืืืขืืจ ืืขืืื 2", size="lg") with gr.Column(visible=False) as page2: gr.Markdown("# ืขืืื 2 - ืืืฆืข") gr.HTML("<h2 style='color:blue;'>โ
ืืืขืืจ ืืจืืฉืื ืขืื!</h2>") btn2 = gr.Button("๐น ืืืฅ ืืื ืืืขืืจ ืืขืืื 3", size="lg") with gr.Column(visible=False) as page3: gr.Markdown("# ืขืืื 3 - ืกืืฃ") gr.HTML("<h2 style='color:green;'>โ
โ
ืฉื ื ืืืขืืจืื ืขืืื ืืืฆืืื!</h2>") gr.Markdown("**ืื ืืืขืืจืื ืขืืืืื ืืฆืืื** ๐") def switch_to_page2(): return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False) def switch_to_page3(): return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True) btn1.click( fn=switch_to_page2, inputs=[], outputs=[page1, page2, page3] ) btn2.click( fn=switch_to_page3, inputs=[], outputs=[page1, page2, page3] )
if __name__ == "__main__": demo.launch(share=False, inbrowser=True)app.py+14-44
minimal_test.pyAdded+40