Spaces:
Sleeping
Sleeping
File size: 2,041 Bytes
b27eb78 837d0b8 b27eb78 837d0b8 b27eb78 837d0b8 b27eb78 8099e26 b27eb78 8a1135c 8099e26 b27eb78 837d0b8 b27eb78 |
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 |
#!/usr/bin/env python3
"""
Hugging Face Space app for Second Brain AI Assistant.
Direct implementation for HF Space deployment.
"""
import os
import sys
from pathlib import Path
# Add the current directory and src directory to Python path
sys.path.append('.')
sys.path.append('src')
from second_brain_online.application.agents import get_agent
from second_brain_online.application.ui import CustomGradioUI
from second_brain_online import opik_utils
def main():
"""Main function for Hugging Face Space deployment."""
# Set default values for HF Spaces
retriever_config_path = os.getenv("RETRIEVER_CONFIG_PATH", "configs/compute_rag_vector_index_openai_contextual_simple.yaml")
print("π Starting Second Brain AI Assistant...")
print(f"π Using retriever config: {retriever_config_path}")
# Debug: Check environment variables
print("π Environment variables check:")
print(f" COMET_API_KEY: {'SET' if os.getenv('COMET_API_KEY') else 'NOT SET'}")
print(f" COMET_PROJECT: {os.getenv('COMET_PROJECT', 'NOT SET')}")
print(f" OPENAI_API_KEY: {'SET' if os.getenv('OPENAI_API_KEY') else 'NOT SET'}")
print(f" MONGODB_URI: {'SET' if os.getenv('MONGODB_URI') else 'NOT SET'}")
# Configure OPIK (optional - will use default project if COMET_PROJECT not set)
try:
opik_utils.configure()
print("β
OPIK configured successfully")
except Exception as e:
print(f"β οΈ OPIK configuration failed: {e}")
try:
# Initialize agent
agent = get_agent(retriever_config_path=Path(retriever_config_path))
# Get the actual agent from the wrapper
actual_agent = agent._AgentWrapper__agent
# Launch custom UI
CustomGradioUI(actual_agent).launch(
server_name="0.0.0.0",
server_port=7860,
share=False
)
except Exception as e:
print(f"β Error starting the application: {e}")
raise
if __name__ == "__main__":
main()
|