import sys import nest_asyncio from pathlib import Path from initialize import ( initialize_components, initialize_s3_client, download_s3_folder, LOCAL_DIR, BUCKET_NAME, PREFIX_RETRIEVER ) from interface import create_gradio_interface # Apply nest_asyncio to handle nested async calls nest_asyncio.apply() if __name__ == "__main__": try: # # Створюємо локальну директорію # LOCAL_DIR.mkdir(parents=True, exist_ok=True) # # # Ініціалізуємо S3 клієнт та завантажуємо файли якщо потрібно # if not LOCAL_DIR.exists() or not any(LOCAL_DIR.iterdir()): # print(f"Локальна директорія {LOCAL_DIR} відсутня або пуста. Починаємо завантаження...") # s3_client = initialize_s3_client() # download_s3_folder(s3_client, BUCKET_NAME, PREFIX_RETRIEVER, LOCAL_DIR) # else: # print(f"Локальна директорія {LOCAL_DIR} вже існує і містить файли. Завантаження пропущено.") # # # Ініціалізуємо компоненти # if initialize_components(): # print("Components initialized successfully!") # app = create_gradio_interface() # app.launch(share=True) # else: # print("Failed to initialize components. Please check the paths and try again.", file=sys.stderr) # sys.exit(1) app = create_gradio_interface() app.launch(share=True) except Exception as e: print(f"Critical error during startup: {str(e)}", file=sys.stderr) sys.exit(1)