# ============================================================ # LEXOSYNTH - HF SPACES ENTRY POINT # File : app.py # ============================================================ import threading import time import sys import os import requests def start_flask(): """Start Flask backend on port 5000 (internal only).""" from backend import app app.run( host = "0.0.0.0", port = 5000, debug = False, use_reloader= False ) def wait_for_flask(max_wait=60): """Poll Flask /health until ready.""" print("[Startup] Waiting for Flask backend...", flush=True) for _ in range(max_wait): try: r = requests.get("http://localhost:5000/health", timeout=1) if r.status_code == 200: print("[Startup] Flask is ready!", flush=True) return True except Exception: pass time.sleep(1) return False if __name__ == "__main__": # Start Flask in background thread flask_thread = threading.Thread(target=start_flask, daemon=True) flask_thread.start() # Wait for Flask to be ready if not wait_for_flask(max_wait=60): print("[ERROR] Flask did not start. Exiting.") sys.exit(1) # Launch Gradio on port 7860 (HF Spaces public port) from frontend import demo print("[Startup] Launching Gradio interface...", flush=True) demo.launch( server_name = "0.0.0.0", server_port = 7860, share=False, # HF Spaces handles public access — no share needed show_api=False, debug=False, show_error=True )