File size: 2,912 Bytes
0ef94af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
Setup script for Production RAG Agent
Run this script to install dependencies and set up the environment
"""

import subprocess
import sys
import os
from pathlib import Path

def run_command(command):
    """Run a shell command and return the result"""
    try:
        result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
        return True, result.stdout
    except subprocess.CalledProcessError as e:
        return False, e.stderr

def main():
    print("πŸš€ Setting up Production RAG Agent...")
    print("=" * 50)
    
    # Check Python version
    print(f"βœ“ Python version: {sys.version}")
    
    # Install dependencies
    print("\nπŸ“¦ Installing dependencies...")
    success, output = run_command("pip install -r requirements.txt")
    
    if success:
        print("βœ“ Dependencies installed successfully")
    else:
        print(f"❌ Error installing dependencies: {output}")
        return
    
    # Check environment variables
    print("\nπŸ”‘ Checking environment variables...")
    
    required_vars = ["HF_TOKEN"]
    optional_vars = ["OPENWEATHER_API_KEY", "SERPER_API_KEY"]
    
    for var in required_vars:
        if os.getenv(var):
            print(f"βœ“ {var} is set")
        else:
            print(f"⚠️ {var} is not set (required for full functionality)")
    
    for var in optional_vars:
        if os.getenv(var):
            print(f"βœ“ {var} is set")
        else:
            print(f"ℹ️ {var} is not set (optional)")
    
    # Check directories
    print("\nπŸ“ Checking directories...")
    base_dir = Path(__file__).parent
    
    directories = [
        base_dir / "knowledge_base",
        base_dir / "vector_store", 
        base_dir / "logs"
    ]
    
    for directory in directories:
        if directory.exists():
            print(f"βœ“ {directory.name} directory exists")
        else:
            directory.mkdir(parents=True, exist_ok=True)
            print(f"βœ“ Created {directory.name} directory")
    
    # Test imports
    print("\nπŸ§ͺ Testing imports...")
    
    test_imports = [
        "gradio",
        "transformers", 
        "torch",
        "sentence_transformers",
        "langchain"
    ]
    
    for module in test_imports:
        try:
            __import__(module)
            print(f"βœ“ {module}")
        except ImportError:
            print(f"❌ {module} (install failed)")
    
    print("\n" + "=" * 50)
    print("πŸŽ‰ Setup complete!")
    print("\nNext steps:")
    print("1. Set your HF_TOKEN environment variable")
    print("2. Add documents to the knowledge_base folder")
    print("3. Run: python app.py")
    print("\nFor Hugging Face Spaces:")
    print("1. Upload all files to your space")
    print("2. Set HF_TOKEN in space settings")
    print("3. Your space will automatically deploy!")

if __name__ == "__main__":
    main()