File size: 5,720 Bytes
19b19f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/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()