File size: 4,140 Bytes
467cc9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test Vish AI locally before deploying to Hugging Face
Run: python test_local.py
"""

import os
import importlib
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

print("πŸ§ͺ Testing Vish AI Setup...")
print("-" * 50)

# Test 1: Environment Variables
print("\n1️⃣ Testing Environment Variables...")
supabase_url = os.getenv("NEXT_PUBLIC_SUPABASE_URL")
supabase_key = os.getenv("NEXT_PUBLIC_SUPABASE_ANON_KEY")

if supabase_url and supabase_key:
    print(f"βœ… Supabase URL: {supabase_url[:30]}...")
    print(f"βœ… Supabase Key: {supabase_key[:30]}...")
else:
    print("❌ Missing environment variables!")
    print("   Make sure .env file exists with Supabase credentials")

# Test 2: Supabase Connection
print("\n2️⃣ Testing Supabase Connection...")
try:
    from supabase import create_client
    supabase = create_client(supabase_url, supabase_key)
    print("βœ… Supabase client created successfully")
    
    # Test database query (if table exists)
    try:
        result = supabase.table("vish_ai_logs").select("*").limit(1).execute()
        print(f"βœ… Database query successful (found {len(result.data)} records)")
    except Exception as e:
        print(f"⚠️  Table might not exist yet: {e}")
        print("   Run the SQL in supabase_setup.sql to create the table")
        
except ImportError:
    print("❌ Supabase library not installed")
    print("   Run: pip install supabase")
except Exception as e:
    print(f"❌ Supabase connection failed: {e}")

# Test 3: Transformers Library
print("\n3️⃣ Testing Transformers Library...")
try:
    transformers_module = importlib.import_module("transformers")
    print(f"βœ… Transformers version: {transformers_module.__version__}")
except ImportError:
    print("❌ Transformers not installed")
    print("   Run: pip install transformers")

# Test 4: PyTorch
print("\n4️⃣ Testing PyTorch...")
try:
    torch_module = importlib.import_module("torch")
    print(f"βœ… PyTorch version: {torch_module.__version__}")
    cuda_available = torch_module.cuda.is_available()
    print(f"   CUDA available: {cuda_available}")
    device = "GPU" if cuda_available else "CPU"
    print(f"   Device: {device}")
except ImportError:
    print("❌ PyTorch not installed")
    print("   Run: pip install torch")

# Test 5: Gradio
print("\n5️⃣ Testing Gradio...")
try:
    import gradio as gr
    print(f"βœ… Gradio version: {gr.__version__}")
except ImportError:
    print("❌ Gradio not installed")
    print("   Run: pip install gradio")

# Test 6: Model Loading (Quick Test)
print("\n6️⃣ Testing Model Loading (this may take a moment)...")
try:
    transformers_module = importlib.import_module("transformers")
    pipeline = getattr(transformers_module, "pipeline")
    print("   Loading DistilGPT2...")
    text_gen = pipeline("text-generation", model="distilgpt2", device=-1, max_length=50)
    print("βœ… Model loaded successfully")
    
    # Quick inference test
    print("\n   Testing inference...")
    result = text_gen("Hello, Vish AI is", max_length=20, num_return_sequences=1)
    print(f"βœ… Sample output: {result[0]['generated_text']}")
    
except Exception as e:
    print(f"❌ Model loading failed: {e}")
    print("   This might be due to network issues or missing dependencies")

# Test 7: File Structure
print("\n7️⃣ Checking File Structure...")
required_files = [
    "app.py",
    "requirements.txt",
    "README.md",
    ".env",
    "supabase_setup.sql",
    "DEPLOYMENT.md"
]

for file in required_files:
    if os.path.exists(file):
        print(f"βœ… {file}")
    else:
        print(f"❌ {file} - Missing!")

# Summary
print("\n" + "=" * 50)
print("🎯 Test Summary")
print("=" * 50)
print("""
Next steps:
1. If all tests pass, run: python app.py
2. Open browser to: http://localhost:7860
3. Test the chat, summarization, and sentiment features
4. When ready, deploy to Hugging Face using DEPLOYMENT.md

To deploy:
- Follow steps in DEPLOYMENT.md
- Push code to HF Space
- Add environment secrets
- Wait for build to complete
""")

print("\n✨ Testing complete! Check results above.\n")