Spaces:
Sleeping
Sleeping
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")
|