milwright commited on
Commit
9ba05be
·
verified ·
1 Parent(s): 6a9fa15

Delete test_preview_function.py

Browse files
Files changed (1) hide show
  1. test_preview_function.py +0 -176
test_preview_function.py DELETED
@@ -1,176 +0,0 @@
1
- """
2
- Test script for the preview function in app.py
3
- Tests the preview tab rendering and functionality
4
- """
5
-
6
- import gradio as gr
7
- import sys
8
- import os
9
- import json
10
- from pathlib import Path
11
-
12
- # Add current directory to path
13
- sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
14
-
15
- from app import SpaceGenerator
16
- from utils import ConfigurationManager
17
-
18
- def test_preview_function():
19
- """Test the preview function with various configurations"""
20
-
21
- print("Starting preview function tests...")
22
-
23
- # Initialize the generator
24
- generator = SpaceGenerator()
25
-
26
- # Test configuration
27
- test_config = {
28
- "name": "Test Assistant",
29
- "tagline": "A test AI assistant for preview testing",
30
- "system_prompt": "You are a helpful AI assistant for testing.",
31
- "model": "meta-llama/llama-2-7b-chat",
32
- "api_base": "https://openrouter.ai/api/v1",
33
- "api_key_var": "OPENROUTER_API_KEY",
34
- "enable_examples": True,
35
- "examples_list": [
36
- "What is machine learning?",
37
- "Explain quantum computing",
38
- "How does blockchain work?"
39
- ],
40
- "enable_file_upload": True,
41
- "enable_export": True,
42
- "theme": "Default",
43
- "preview_ready": True
44
- }
45
-
46
- # Create a test app with the preview tab
47
- with gr.Blocks() as demo:
48
- config_state = gr.State(test_config)
49
-
50
- with gr.Tab("Test Preview"):
51
- # Use the preview rendering logic
52
- @gr.render(inputs=[config_state])
53
- def render_preview(config):
54
- if not config or not config.get('preview_ready'):
55
- gr.Markdown("## ⚠️ Preview Not Ready\n\nPlease configure your space first.")
56
- return
57
-
58
- # Preview chatbot with correct format
59
- preview_chatbot = gr.Chatbot(
60
- label=config.get('name', 'AI Assistant'),
61
- height=400,
62
- show_copy_button=True,
63
- type='messages' # Using the correct format
64
- )
65
-
66
- # Example buttons
67
- examples = config.get('examples_list', [])
68
- if examples:
69
- with gr.Row():
70
- for i, example in enumerate(examples[:3]):
71
- gr.Button(
72
- f"💡 {example[:30]}...",
73
- variant="secondary",
74
- size="sm"
75
- )
76
-
77
- # Input area
78
- with gr.Row():
79
- if config.get('enable_file_upload'):
80
- with gr.Column(scale=1):
81
- gr.File(
82
- label="📎 Upload Files",
83
- file_count="multiple",
84
- file_types=["text", "image", "audio", "video", ".pdf", ".csv", ".xlsx", ".json"],
85
- height=100
86
- )
87
-
88
- with gr.Column(scale=4):
89
- gr.Textbox(
90
- placeholder="Type your message here...",
91
- label="Message",
92
- lines=2,
93
- max_lines=10,
94
- autofocus=True
95
- )
96
-
97
- # Control buttons
98
- with gr.Row():
99
- gr.Button("🚀 Send", variant="primary", size="lg")
100
- gr.Button("🗑️ Clear", variant="secondary")
101
- if config.get('enable_export'):
102
- gr.DownloadButton("📥 Export", variant="secondary")
103
-
104
- # Footer
105
- footer_text = f"### {config.get('name', 'AI Assistant')}"
106
- if config.get('tagline'):
107
- footer_text += f"\n*{config.get('tagline')}*"
108
- gr.Markdown(footer_text)
109
-
110
- # Test 1: Basic rendering
111
- print("\n✓ Test 1: Preview components render without errors")
112
-
113
- # Test 2: Check message format
114
- print("✓ Test 2: Chatbot uses correct 'messages' type format")
115
-
116
- # Test 3: Verify conditional rendering
117
- test_config_minimal = {
118
- "name": "Minimal Assistant",
119
- "preview_ready": True,
120
- "enable_examples": False,
121
- "enable_file_upload": False,
122
- "enable_export": False
123
- }
124
-
125
- with gr.Blocks() as demo_minimal:
126
- config_state = gr.State(test_config_minimal)
127
-
128
- with gr.Tab("Minimal Preview"):
129
- @gr.render(inputs=[config_state])
130
- def render_minimal_preview(config):
131
- if not config or not config.get('preview_ready'):
132
- return
133
-
134
- gr.Chatbot(
135
- label=config.get('name', 'AI Assistant'),
136
- height=400,
137
- type='messages'
138
- )
139
- gr.Textbox(placeholder="Type your message...")
140
- gr.Button("Send")
141
-
142
- print("✓ Test 3: Conditional rendering works correctly")
143
-
144
- # Test 4: Empty config handling
145
- with gr.Blocks() as demo_empty:
146
- config_state = gr.State({})
147
-
148
- with gr.Tab("Empty Preview"):
149
- @gr.render(inputs=[config_state])
150
- def render_empty_preview(config):
151
- if not config or not config.get('preview_ready'):
152
- gr.Markdown("## ⚠️ Preview Not Ready")
153
- return
154
-
155
- print("✓ Test 4: Empty config handled gracefully")
156
-
157
- # Test 5: Message format compatibility
158
- test_messages = [
159
- {"role": "user", "content": "Hello"},
160
- {"role": "assistant", "content": "Hi! How can I help you?"},
161
- {"role": "user", "content": "What's the weather?"},
162
- {"role": "assistant", "content": "I don't have access to weather data."}
163
- ]
164
-
165
- print("✓ Test 5: Message format is compatible with Gradio 5.x")
166
-
167
- print("\n🎉 All preview function tests passed!")
168
- print("\nSummary:")
169
- print("- Preview tab renders without deprecation warnings")
170
- print("- Chatbot uses correct 'messages' type format")
171
- print("- Conditional rendering based on configuration works")
172
- print("- Empty/missing configuration handled gracefully")
173
- print("- All UI components render correctly")
174
-
175
- if __name__ == "__main__":
176
- test_preview_function()