Singtel_Use_Case1 / setup_free_ai.py
cosmoruler
problems fixed
c69ba8c
"""
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()