Spaces:
Running
on
Zero
Running
on
Zero
| #!/usr/bin/env python3 | |
| """ | |
| Test script for the Petite Elle L'Aime 3 Gradio application | |
| """ | |
| import sys | |
| import os | |
| import importlib.util | |
| def test_imports(): | |
| """Test if all required packages can be imported""" | |
| required_packages = [ | |
| 'gradio', | |
| 'torch', | |
| 'transformers', | |
| 'accelerate', | |
| 'safetensors', | |
| 'tokenizers' | |
| ] | |
| print("Testing imports...") | |
| for package in required_packages: | |
| try: | |
| __import__(package) | |
| print(f"β {package} imported successfully") | |
| except ImportError as e: | |
| print(f"β Failed to import {package}: {e}") | |
| return False | |
| return True | |
| def test_app_structure(): | |
| """Test if the app.py file has the correct structure""" | |
| print("\nTesting app.py structure...") | |
| if not os.path.exists('app.py'): | |
| print("β app.py not found") | |
| return False | |
| try: | |
| # Import the app module | |
| spec = importlib.util.spec_from_file_location("app", "app.py") | |
| app_module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(app_module) | |
| # Check for required functions | |
| required_functions = [ | |
| 'load_model', | |
| 'create_prompt', | |
| 'generate_response', | |
| 'user', | |
| 'bot' | |
| ] | |
| for func_name in required_functions: | |
| if hasattr(app_module, func_name): | |
| print(f"β {func_name} function found") | |
| else: | |
| print(f"β {func_name} function not found") | |
| return False | |
| # Check for required variables | |
| required_variables = [ | |
| 'DEFAULT_SYSTEM_PROMPT', | |
| 'title', | |
| 'description', | |
| 'presentation1', | |
| 'presentation2', | |
| 'joinus' | |
| ] | |
| for var_name in required_variables: | |
| if hasattr(app_module, var_name): | |
| print(f"β {var_name} variable found") | |
| else: | |
| print(f"β {var_name} variable not found") | |
| return False | |
| print("β All required functions and variables found") | |
| return True | |
| except Exception as e: | |
| print(f"β Error testing app.py: {e}") | |
| return False | |
| def test_requirements(): | |
| """Test if requirements.txt exists and has required packages""" | |
| print("\nTesting requirements.txt...") | |
| if not os.path.exists('requirements.txt'): | |
| print("β requirements.txt not found") | |
| return False | |
| required_packages = [ | |
| 'gradio', | |
| 'torch', | |
| 'transformers', | |
| 'accelerate' | |
| ] | |
| with open('requirements.txt', 'r') as f: | |
| content = f.read() | |
| for package in required_packages: | |
| if package in content: | |
| print(f"β {package} found in requirements.txt") | |
| else: | |
| print(f"β {package} not found in requirements.txt") | |
| return False | |
| return True | |
| def test_config(): | |
| """Test if config.yaml exists and has required sections""" | |
| print("\nTesting config.yaml...") | |
| if not os.path.exists('config.yaml'): | |
| print("β config.yaml not found") | |
| return False | |
| try: | |
| import yaml | |
| with open('config.yaml', 'r') as f: | |
| config = yaml.safe_load(f) | |
| required_sections = [ | |
| 'model', | |
| 'system_prompt', | |
| 'generation', | |
| 'chat', | |
| 'ui' | |
| ] | |
| for section in required_sections: | |
| if section in config: | |
| print(f"β {section} section found in config.yaml") | |
| else: | |
| print(f"β {section} section not found in config.yaml") | |
| return False | |
| # Check system prompt default | |
| if 'system_prompt' in config and 'default' in config['system_prompt']: | |
| print(f"β System prompt default found: {config['system_prompt']['default']}") | |
| else: | |
| print("β System prompt default not found") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"β Error testing config.yaml: {e}") | |
| return False | |
| def test_readme(): | |
| """Test if README.md has the correct structure""" | |
| print("\nTesting README.md...") | |
| if not os.path.exists('README.md'): | |
| print("β README.md not found") | |
| return False | |
| with open('README.md', 'r') as f: | |
| content = f.read() | |
| required_sections = [ | |
| 'Petite Elle L\'Aime 3', | |
| 'Features', | |
| 'Installation', | |
| 'Usage' | |
| ] | |
| for section in required_sections: | |
| if section in content: | |
| print(f"β {section} section found") | |
| else: | |
| print(f"β {section} section not found") | |
| return False | |
| return True | |
| def main(): | |
| """Run all tests""" | |
| print("π§ͺ Testing Petite Elle L'Aime 3 Gradio Application\n") | |
| tests = [ | |
| test_imports, | |
| test_app_structure, | |
| test_requirements, | |
| test_config, | |
| test_readme | |
| ] | |
| passed = 0 | |
| total = len(tests) | |
| for test in tests: | |
| if test(): | |
| passed += 1 | |
| print() | |
| print(f"π Test Results: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("π All tests passed! The application is ready to run.") | |
| print("\nTo run the application:") | |
| print("python app.py") | |
| else: | |
| print("β Some tests failed. Please fix the issues before running the application.") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() |