Spaces:
Sleeping
Sleeping
File size: 5,263 Bytes
1273036 |
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
#!/usr/bin/env python3
"""
Test script to verify the Neural Data Analyst application works correctly
Run this to check if all dependencies are available and create sample files
"""
import sys
import os
from pathlib import Path
def check_dependencies():
"""Check if all required dependencies are installed"""
print("π Checking dependencies...")
required_packages = [
'streamlit',
'pandas',
'numpy',
'plotly',
'requests'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
print(f"β
{package}")
except ImportError:
print(f"β {package} - MISSING")
missing_packages.append(package)
# Optional packages
optional_packages = [
'scipy',
'python-dotenv'
]
print("\nπ Checking optional dependencies...")
for package in optional_packages:
try:
__import__(package.replace('-', '_'))
print(f"β
{package} (optional)")
except ImportError:
print(f"β οΈ {package} (optional) - not installed")
if missing_packages:
print(f"\nβ Missing required packages: {', '.join(missing_packages)}")
print("Install them with: pip install " + " ".join(missing_packages))
return False
else:
print("\nβ
All required dependencies are installed!")
return True
def create_sample_files():
"""Create sample configuration files"""
print("\nπ Creating sample files...")
# Create .env file template
env_content = """# Groq API Configuration
# Get your API key from: https://console.groq.com/keys
GROQ_API_KEY=your_groq_api_key_here
# Optional: Set other environment variables
# DEBUG=True
"""
env_file = Path('.env.template')
if not env_file.exists():
with open(env_file, 'w') as f:
f.write(env_content)
print(f"β
Created {env_file}")
else:
print(f"βΉοΈ {env_file} already exists")
# Create sample CSV data
sample_csv = Path('sample_data.csv')
if not sample_csv.exists():
csv_content = """customer_id,customer_name,product,sales_amount,order_date,region,sales_rep
1,Customer_1,Widget A,2147.23,2023-01-01,North,John Smith
2,Customer_2,Widget B,1823.45,2023-01-02,South,Jane Doe
3,Customer_3,Widget C,2456.78,2023-01-03,East,Bob Johnson
4,Customer_4,Gadget X,1934.56,2023-01-04,West,Alice Brown
5,Customer_5,Widget A,2234.67,2023-01-05,North,John Smith
"""
with open(sample_csv, 'w') as f:
f.write(csv_content)
print(f"β
Created {sample_csv}")
else:
print(f"βΉοΈ {sample_csv} already exists")
def create_required_modules():
"""Create the required module files if they don't exist"""
print("\nπ Checking required modules...")
# Check if eda_analyzer.py exists
if not Path('eda_analyzer.py').exists():
print("β eda_analyzer.py not found!")
print(" Please save the EDA Analyzer code as 'eda_analyzer.py'")
return False
else:
print("β
eda_analyzer.py found")
# Check if database_manager.py exists
if not Path('database_manager.py').exists():
print("β database_manager.py not found!")
print(" Please save the Database Manager code as 'database_manager.py'")
return False
else:
print("β
database_manager.py found")
return True
def test_imports():
"""Test if the modules can be imported"""
print("\nπ§ͺ Testing module imports...")
try:
from eda_analyzer import EDAAnalyzer
print("β
EDAAnalyzer imported successfully")
except Exception as e:
print(f"β Failed to import EDAAnalyzer: {e}")
return False
try:
from database_manager import DatabaseManager
print("β
DatabaseManager imported successfully")
except Exception as e:
print(f"β Failed to import DatabaseManager: {e}")
return False
return True
def main():
"""Main test function"""
print("π Neural Data Analyst - Setup Test")
print("=" * 50)
# Check Python version
python_version = sys.version_info
print(f"π Python version: {python_version.major}.{python_version.minor}.{python_version.micro}")
if python_version < (3, 7):
print("β Python 3.7+ required!")
return False
else:
print("β
Python version OK")
# Run all checks
deps_ok = check_dependencies()
if not deps_ok:
return False
create_sample_files()
modules_ok = create_required_modules()
if not modules_ok:
return False
imports_ok = test_imports()
if not imports_ok:
return False
print("\nπ Setup test completed successfully!")
print("\nπ Next steps:")
print("1. Copy .env.template to .env and add your Groq API key (optional)")
print("2. Run: streamlit run app.py")
print("3. Upload sample_data.csv or your own data file")
print("4. Explore the analysis features!")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |