File size: 3,180 Bytes
44413d3 67e580b 44413d3 2598a5c 44413d3 890bcc8 44413d3 67e580b 7bb3314 67e580b 2598a5c 67e580b 2598a5c 7bb3314 67e580b 7bb3314 bff9789 44413d3 94c33ea 2598a5c 44413d3 2598a5c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
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 |