AI-Lead-Qualification-Bot / quick_test.py
vinayabc1824's picture
Upload 35 files
61fe5a5 verified
Raw History Blame Contribute Delete
4.22 kB
#!/usr/bin/env python3
"""
Quick test script to verify the fixes work.
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def test_csv_parsing():
"""Test the CSV parsing fix."""
print("Testing CSV parsing fix...")
try:
import pandas as pd
import ast
import json
# Read the CSV file
df = pd.read_csv("data/training_data/crm_data.csv")
# Test parsing the first row
row = df.iloc[0]
# Test messages parsing
messages_str = row.get('messages', '[]')
if messages_str and messages_str != '[]':
# Clean up the string - replace escaped quotes and fix formatting
messages_str = messages_str.replace("\\'", "'").replace('\\"', '"')
# Remove outer quotes if present
if messages_str.startswith('"') and messages_str.endswith('"'):
messages_str = messages_str[1:-1]
try:
messages = ast.literal_eval(messages_str)
print(f"βœ… Messages parsed successfully: {len(messages)} messages")
except:
# Fallback to json.loads if ast.literal_eval fails
messages = json.loads(messages_str)
print(f"βœ… Messages parsed with JSON fallback: {len(messages)} messages")
else:
messages = []
print("βœ… Empty messages handled correctly")
# Test lead_info parsing
lead_info_str = row.get('lead_info', '{}')
if lead_info_str and lead_info_str != '{}':
# Clean up the string
lead_info_str = lead_info_str.replace("\\'", "'").replace('\\"', '"')
if lead_info_str.startswith('"') and lead_info_str.endswith('"'):
lead_info_str = lead_info_str[1:-1]
try:
lead_info = ast.literal_eval(lead_info_str)
print(f"βœ… Lead info parsed successfully: {len(lead_info)} fields")
except:
import json
lead_info = json.loads(lead_info_str)
print(f"βœ… Lead info parsed with JSON fallback: {len(lead_info)} fields")
else:
lead_info = {}
print("βœ… Empty lead_info handled correctly")
return True
except Exception as e:
print(f"❌ CSV parsing test failed: {e}")
return False
def test_requirements():
"""Test if required packages are available."""
print("Testing required packages...")
required_packages = [
'torch',
'transformers',
'sentence_transformers',
'langchain',
'langchain_community',
'faiss',
'scikit_learn',
'lightgbm',
'pandas',
'gradio'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
print(f"βœ… {package}")
except ImportError:
print(f"❌ {package} - MISSING")
missing_packages.append(package)
if missing_packages:
print(f"\n⚠️ Missing packages: {', '.join(missing_packages)}")
print("Run: pip install -r requirements.txt")
return False
else:
print("\nβœ… All required packages are available")
return True
def main():
"""Run all tests."""
print("Running quick verification tests...\n")
# Test requirements
req_success = test_requirements()
print()
# Test CSV parsing
csv_success = test_csv_parsing()
print()
# Summary
if req_success and csv_success:
print("πŸŽ‰ All tests passed!")
print("The application should now work properly.")
print("\nTo run the full application:")
print("1. Install accelerate: pip install accelerate")
print("2. Run the app: python app.py")
else:
print("⚠️ Some issues remain. Check the output above.")
return req_success and csv_success
if __name__ == "__main__":
main()