harismlnaslm's picture
Switch to API server: Replace Gradio with Flask API endpoints
4669d04
#!/usr/bin/env python3
"""
Test script for Textilindo AI Assistant
"""
import sys
import os
# Add current directory to path
sys.path.insert(0, os.path.dirname(__file__))
def test_imports():
"""Test if all required imports work"""
try:
import gradio as gr
import requests
from difflib import SequenceMatcher
import json
import logging
print("βœ… All imports successful")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
return False
def test_ai_class():
"""Test if the AI class can be instantiated"""
try:
from app_gradio import TextilindoAI
ai = TextilindoAI()
print(f"βœ… AI class instantiated successfully")
print(f"βœ… Dataset loaded: {len(ai.dataset)} examples")
return True
except Exception as e:
print(f"❌ AI class error: {e}")
return False
def test_chat_function():
"""Test if the chat function works"""
try:
from app_gradio import chat_function
response = chat_function("Hello, what is Textilindo?")
print(f"βœ… Chat function works: {response[:50]}...")
return True
except Exception as e:
print(f"❌ Chat function error: {e}")
return False
if __name__ == "__main__":
print("Testing Textilindo AI Assistant...")
print("=" * 50)
tests = [
test_imports,
test_ai_class,
test_chat_function
]
passed = 0
for test in tests:
if test():
passed += 1
print()
print("=" * 50)
print(f"Tests passed: {passed}/{len(tests)}")
if passed == len(tests):
print("βœ… All tests passed! Ready for deployment.")
else:
print("❌ Some tests failed. Check the errors above.")