Spaces:
Runtime error
Runtime error
""" | |
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() | |