import os import sys import argparse import gradio as gr import logging # Set up logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) # Add the current directory to the path current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) def main(): parser = argparse.ArgumentParser(description="Freudian Dream Analyzer Interface") parser.add_argument("--share", action="store_true", help="Create a shareable link") parser.add_argument("--debug", action="store_true", help="Run in debug mode") parser.add_argument("--hf_space", action="store_true", help="Running in Hugging Face Space") args = parser.parse_args() # Auto-detect if we're in Hugging Face Space in_hf_space = args.hf_space or os.path.exists("/home/user") if in_hf_space and not args.hf_space: logger.info("Detected Hugging Face Space environment") args.hf_space = True # Import the dream interface function try: from ui.dream_interface import create_dream_interface logger.info("Successfully imported create_dream_interface") except ImportError as e: logger.error(f"Error importing create_dream_interface: {e}") # Try to add the ui directory to the path ui_dir = os.path.join(current_dir, "ui") if os.path.exists(ui_dir): sys.path.append(ui_dir) try: from dream_interface import create_dream_interface logger.info("Successfully imported create_dream_interface from ui directory") except ImportError as e2: logger.error(f"Error importing create_dream_interface from ui directory: {e2}") raise else: raise # Use a dummy path - our new interface ignores it and uses a CPU-compatible model model_path = "dummy_path" logger.info(f"Using dummy model path for CPU-compatible model") # Create the interface try: logger.info("Creating interface...") interface = create_dream_interface(model_path) logger.info("Interface created successfully") # Launch with appropriate settings if args.debug: logger.info("Launching in debug mode...") interface.launch( server_name="0.0.0.0", server_port=7860, share=args.share, debug=True, show_error=True ) else: logger.info("Launching in normal mode...") interface.launch( server_name="0.0.0.0", server_port=7860, share=args.share, show_error=True ) except Exception as e: logger.error(f"Error creating or launching interface: {e}") raise if __name__ == "__main__": try: logger.info("Starting Freudian Dream Analyzer application") main() except Exception as e: logger.error(f"Application crashed: {e}") raise