Spaces:
Runtime error
Runtime error
Download quick_test.py from vinayabc1824/AI-Lead-Qualification-Bot: direct link, hf CLI and curl.
- Browser
- Download file 4.22 kB
-
https://huggingface.co/spaces/vinayabc1824/AI-Lead-Qualification-Bot/resolve/main/quick_test.py
- Command line
-
hf download hf://spaces/vinayabc1824/AI-Lead-Qualification-Bot/quick_test.py
-
curl -L -o quick_test.py https://huggingface.co/spaces/vinayabc1824/AI-Lead-Qualification-Bot/resolve/main/quick_test.py
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() | |