import sys import os import logging sys.path.insert(0, os.path.dirname(__file__)) from dotenv import load_dotenv load_dotenv(os.path.join(os.path.dirname(__file__), ".env")) # Suppress OTel "Failed to detach context" warning caused by generator/context interaction. # Tracing is unaffected. # Known bug: https://github.com/open-telemetry/opentelemetry-python/issues/2606 class _SuppressOtelDetachWarning(logging.Filter): def filter(self, record): return "Failed to detach context" not in record.getMessage() logging.getLogger("opentelemetry.context").addFilter(_SuppressOtelDetachWarning()) from ui.css import custom_css from ui.gradio_app import create_gradio_ui if __name__ == "__main__": auth_username = os.environ.get("GRADIO_AUTH_USERNAME", "") auth_password = os.environ.get("GRADIO_AUTH_PASSWORD", "") if bool(auth_username) != bool(auth_password): raise ValueError("Set both GRADIO_AUTH_USERNAME and GRADIO_AUTH_PASSWORD, or neither.") print("\n🔨 Creating RAG Assistant...") demo = create_gradio_ui() print("\n🚀 Launching RAG Assistant...") demo.launch( css=custom_css, server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0" if os.environ.get("SPACE_ID") else "127.0.0.1"), server_port=int(os.environ.get("PORT", os.environ.get("GRADIO_SERVER_PORT", "7860"))), auth=(auth_username, auth_password) if auth_username else None, )