File size: 4,275 Bytes
c69ba8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
Free AI Setup Helper
===================

This script helps you set up completely free AI models for data analysis.
"""

import os
import subprocess
import sys

def setup_free_huggingface():
    """Setup free Hugging Face models"""
    print("πŸ†“ SETTING UP FREE HUGGING FACE AI")
    print("=" * 40)
    
    print("πŸ“ Steps to get free Hugging Face access:")
    print("1. Go to: https://huggingface.co/join")
    print("2. Create a free account")
    print("3. Go to: https://huggingface.co/settings/tokens")
    print("4. Create a new token (read access is enough)")
    print("5. Copy the token")
    
    token = input("\nπŸ”‘ Paste your Hugging Face token here (or press Enter to skip): ").strip()
    
    if token:
        # Set environment variable for current session
        os.environ['HF_TOKEN'] = token
        print("βœ… Token set for current session!")
        
        # Try to test the token
        try:
            import requests
            headers = {"Authorization": f"Bearer {token}"}
            response = requests.get("https://huggingface.co/api/whoami", headers=headers)
            if response.status_code == 200:
                user_info = response.json()
                print(f"βœ… Token verified! Hello, {user_info.get('name', 'User')}!")
                return True
            else:
                print("⚠️  Token verification failed. Please check your token.")
                return False
        except Exception as e:
            print(f"⚠️  Could not verify token: {e}")
            return False
    else:
        print("⚠️  No token provided. Some models may not work without authentication.")
        return False

def setup_ollama_quick():
    """Quick Ollama setup guide"""
    print("\nπŸ†“ SETTING UP FREE LOCAL OLLAMA AI")
    print("=" * 40)
    
    print("πŸ“ Quick Ollama setup:")
    print("1. Download from: https://ollama.ai/")
    print("2. Install the application")
    print("3. Open terminal and run: ollama pull llama2")
    print("4. Start server: ollama serve")
    print("5. Your script will automatically detect it!")
    
    choice = input("\n❓ Open Ollama website now? (y/n): ").strip().lower()
    if choice == 'y':
        try:
            if sys.platform == 'win32':
                os.startfile("https://ollama.ai/")
            elif sys.platform == 'darwin':
                subprocess.run(['open', "https://ollama.ai/"])
            else:
                subprocess.run(['xdg-open', "https://ollama.ai/"])
            print("βœ… Ollama website opened!")
        except Exception as e:
            print(f"⚠️  Could not open website: {e}")
            print("Please manually go to: https://ollama.ai/")

def test_current_setup():
    """Test what AI models are currently available"""
    print("\nπŸ§ͺ TESTING CURRENT AI SETUP")
    print("=" * 30)
    
    try:
        from upload import EnhancedDataExplorer
        explorer = EnhancedDataExplorer()
        
        if explorer.agent is not None:
            print("βœ… AI model is configured and ready!")
            print("πŸš€ You can now use AI analysis in your data explorer!")
            return True
        else:
            print("❌ No AI model configured yet.")
            return False
    except Exception as e:
        print(f"❌ Error testing setup: {e}")
        return False

def main():
    print("πŸ€– FREE AI MODELS SETUP")
    print("=" * 25)
    print("Choose your free AI option:")
    print("1. πŸ†“ Hugging Face (cloud-based, free account needed)")
    print("2. πŸ†“ Ollama (local, completely free, more private)")
    print("3. πŸ§ͺ Test current setup")
    print("4. ❌ Skip AI setup")
    
    choice = input("\nEnter your choice (1-4): ").strip()
    
    if choice == "1":
        setup_free_huggingface()
    elif choice == "2":
        setup_ollama_quick()
    elif choice == "3":
        test_current_setup()
    elif choice == "4":
        print("βœ… You can still use all non-AI features!")
    else:
        print("❌ Invalid choice. Please run the script again.")
    
    print("\nπŸš€ Next steps:")
    print("1. Run: python upload.py")
    print("2. Choose option 2 (Enhanced mode)")
    print("3. Try AI analysis with menu option 4")

if __name__ == "__main__":
    main()