File size: 12,842 Bytes
c36325d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
"""
Simplified UI Configuration Component
Makes the configuration form less intimidating and more compact
"""

import gradio as gr


def create_simplified_config_ui():
    """Create a simplified, user-friendly configuration interface"""
    
    with gr.Column():
        # Compact header with inline help
        with gr.Row():
            gr.Markdown("## πŸš€ Quick Setup")
            with gr.Column(scale=0.3):
                gr.Markdown("[Need help?](#)", elem_id="help-link")
        
        # Simplified model selection with friendly labels
        with gr.Row():
            model = gr.Dropdown(
                label="AI Model",
                choices=[
                    ("Fast & Smart (Recommended)", "google/gemini-2.0-flash-001"),
                    ("Advanced Open Model", "google/gemma-3-27b-it"),
                    ("Deep Analysis", "anthropic/claude-3.5-haiku"),
                    ("Balanced with Search", "openai/gpt-4o-mini-search-preview"),
                    ("Lightweight", "openai/gpt-4.1-nano"),
                    ("Powerful Open Source", "nvidia/llama-3.1-nemotron-70b-instruct"),
                    ("Code Specialist", "mistralai/devstral-small")
                ],
                value="google/gemini-2.0-flash-001",
                info="Pick based on your needs",
                elem_id="model-select"
            )
        
        # Collapsible security settings with friendlier names
        with gr.Accordion("πŸ” Security Settings", open=False):
            with gr.Row():
                api_key_var = gr.Textbox(
                    label="API Key Name",
                    value="MY_API_KEY",
                    info="You'll set this in HuggingFace later",
                    interactive=True,
                    elem_id="api-key-name"
                )
                
                access_code = gr.Textbox(
                    label="Access Password Name (Optional)",
                    value="ACCESS_CODE",
                    info="For private spaces only",
                    interactive=True,
                    elem_id="access-code-name"
                )
        
        # Main configuration in a clean card layout
        with gr.Group():
            gr.Markdown("### ✨ Your Assistant")
            
            # Template selector moved to top for visibility
            template_selector = gr.Radio(
                label="Quick Start Templates",
                choices=[
                    ("Custom Assistant", "None"),
                    ("Research Helper", "Research Template"),
                    ("Teaching Assistant", "Socratic Template")
                ],
                value="None",
                info="Start with a template or build your own",
                elem_id="template-selector"
            )
            
            # Simplified system prompt
            system_prompt = gr.Textbox(
                label="Assistant Instructions",
                placeholder="Tell your assistant how to behave...\nExample: You are a helpful study buddy who explains concepts clearly.",
                lines=4,
                elem_id="system-prompt"
            )
            
            # Streamlined examples section
            with gr.Row():
                examples_text = gr.Textbox(
                    label="Starter Questions",
                    placeholder="What questions should users try?\nOne per line",
                    lines=2,
                    scale=2,
                    elem_id="example-prompts"
                )
                
                # Quick example buttons
                with gr.Column(scale=1):
                    gr.Markdown("**Quick Add:**")
                    example_btn1 = gr.Button("πŸ“š Study Help", size="sm", variant="secondary")
                    example_btn2 = gr.Button("πŸ”¬ Research", size="sm", variant="secondary")
                    example_btn3 = gr.Button("πŸ’‘ General", size="sm", variant="secondary")
        
        # Simplified URL section with progressive disclosure
        with gr.Accordion("πŸ“Ž Add Resources (Optional)", open=False):
            gr.Markdown("*Add websites or documents for context*")
            
            # Just show 2 URL fields initially
            url1 = gr.Textbox(
                label="Main Resource",
                placeholder="https://your-syllabus.edu",
                elem_id="url-1"
            )
            
            url2 = gr.Textbox(
                label="Additional Resource",
                placeholder="https://textbook.com/chapter",
                elem_id="url-2"
            )
            
            # Hidden additional URLs
            with gr.Column(visible=False) as more_urls_section:
                url3 = gr.Textbox(label="Resource 3", placeholder="Optional")
                url4 = gr.Textbox(label="Resource 4", placeholder="Optional")
                # ... more URLs as needed
            
            more_urls_btn = gr.Button("+ Add More Resources", size="sm", variant="secondary")
            
            # Dynamic URL option with clearer label
            enable_dynamic_urls = gr.Checkbox(
                label="Let assistant fetch links from conversations",
                value=True,
                info="Useful for research tasks"
            )
        
        # Advanced settings hidden by default
        with gr.Accordion("βš™οΈ Fine-Tuning (Optional)", open=False):
            with gr.Row():
                temperature = gr.Slider(
                    label="Creativity",
                    minimum=0,
                    maximum=2,
                    value=0.7,
                    step=0.1,
                    info="Lower = Focused | Higher = Creative"
                )
                
                max_tokens = gr.Slider(
                    label="Response Length",
                    minimum=50,
                    maximum=4096,
                    value=750,
                    step=50,
                    info="Typical conversation: 500-1000"
                )
        
        # Simplified action buttons
        with gr.Row():
            preview_btn = gr.Button(
                "πŸ‘οΈ Preview",
                variant="secondary",
                elem_id="preview-btn"
            )
            generate_btn = gr.Button(
                "πŸŽ‰ Create Assistant",
                variant="primary",
                elem_id="generate-btn"
            )
        
        # Cleaner status area
        with gr.Column(visible=False) as status_area:
            status = gr.Markdown(elem_id="status-message")
            download_file = gr.File(
                label="πŸ“¦ Your Assistant Package",
                elem_id="download-file"
            )
    
    # Add custom CSS for a cleaner look
    custom_css = """
    /* Compact spacing */
    .gradio-container {
        max-width: 800px !important;
        margin: 0 auto;
    }
    
    /* Smaller fonts for labels */
    label {
        font-size: 14px !important;
        font-weight: 500 !important;
    }
    
    /* Compact form spacing */
    .form {
        gap: 0.75rem !important;
    }
    
    /* Friendly button styling */
    #generate-btn {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        font-size: 16px !important;
        padding: 12px 24px !important;
    }
    
    #preview-btn {
        font-size: 14px !important;
    }
    
    /* Help link styling */
    #help-link a {
        color: #667eea;
        text-decoration: none;
        font-size: 14px;
    }
    
    /* Accordion headers more compact */
    .accordion {
        margin: 0.5rem 0 !important;
    }
    
    /* Status message styling */
    #status-message {
        border-radius: 8px;
        padding: 1rem;
        background: #f0f9ff;
        border: 1px solid #3b82f6;
    }
    
    /* Compact dropdown */
    #model-select {
        font-size: 14px !important;
    }
    
    /* Mobile responsive */
    @media (max-width: 768px) {
        .gradio-container {
            padding: 1rem !important;
        }
        
        button {
            width: 100%;
            margin: 0.25rem 0;
        }
    }
    """
    
    return {
        'components': {
            'model': model,
            'api_key_var': api_key_var,
            'access_code': access_code,
            'template_selector': template_selector,
            'system_prompt': system_prompt,
            'examples_text': examples_text,
            'url1': url1,
            'url2': url2,
            'enable_dynamic_urls': enable_dynamic_urls,
            'temperature': temperature,
            'max_tokens': max_tokens,
            'preview_btn': preview_btn,
            'generate_btn': generate_btn,
            'status': status,
            'download_file': download_file,
            'status_area': status_area,
            'more_urls_section': more_urls_section,
            'more_urls_btn': more_urls_btn
        },
        'css': custom_css,
        'example_handlers': {
            'study_help': lambda: "How do I study effectively?\nExplain this concept simply\nHelp me prepare for my exam",
            'research': lambda: "Find recent research on this topic\nWhat are the key findings?\nHelp me analyze this paper",
            'general': lambda: "How can you help me?\nTell me something interesting\nWhat should I know about this?"
        }
    }


def create_minimal_config_form():
    """Ultra-minimal configuration form for quick setup"""
    
    with gr.Column():
        gr.Markdown("# 🎯 Create Your Assistant in 30 Seconds")
        
        # Just the essentials
        with gr.Group():
            # Pre-configured model (hidden complexity)
            model = gr.Dropdown(
                label="Choose Your Assistant Type",
                choices=[
                    ("Fast General Assistant", "google/gemini-2.0-flash-001"),
                    ("Research Assistant", "anthropic/claude-3.5-haiku"),
                    ("Code Helper", "mistralai/devstral-small")
                ],
                value="google/gemini-2.0-flash-001"
            )
            
            # Simple instruction box
            system_prompt = gr.Textbox(
                label="What should your assistant do?",
                placeholder="Example: Help students with homework and explain concepts clearly",
                lines=2
            )
            
            # One-click templates
            with gr.Row():
                gr.Markdown("**Or use a template:**")
                template_btn1 = gr.Button("πŸ“š Tutor", size="sm")
                template_btn2 = gr.Button("πŸ”¬ Researcher", size="sm")
                template_btn3 = gr.Button("πŸ’¬ Chat Bot", size="sm")
        
        # Hidden advanced options
        with gr.Accordion("Advanced Options", open=False):
            api_key_var = gr.Textbox(
                label="API Variable Name",
                value="OPENROUTER_API_KEY"
            )
            
            examples_text = gr.Textbox(
                label="Example Questions",
                placeholder="One per line",
                lines=2
            )
            
            url1 = gr.Textbox(
                label="Reference URL (optional)",
                placeholder="https://..."
            )
        
        # Big friendly button
        generate_btn = gr.Button(
            "✨ Create My Assistant",
            variant="primary",
            size="lg"
        )
        
        # Simple status
        status = gr.Markdown(visible=False)
        download = gr.File(visible=False)
    
    return {
        'model': model,
        'system_prompt': system_prompt,
        'api_key_var': api_key_var,
        'examples_text': examples_text,
        'url1': url1,
        'generate_btn': generate_btn,
        'status': status,
        'download': download,
        'templates': {
            'tutor': "You are a patient and encouraging tutor. Help students understand concepts step-by-step, provide examples, and check their understanding with questions.",
            'researcher': "You are a research assistant specializing in finding and analyzing information. Help users discover relevant sources, synthesize findings, and provide citations.",
            'chatbot': "You are a friendly and helpful assistant. Engage in natural conversation, answer questions thoughtfully, and provide useful information."
        }
    }


# Simplified variable names mapping for less technical users
FRIENDLY_VAR_NAMES = {
    "OPENROUTER_API_KEY": "MY_API_KEY",
    "SPACE_ACCESS_CODE": "ACCESS_PASSWORD",
    "FACULTY_CONFIG_PASSWORD": "TEACHER_PASSWORD"
}


def get_friendly_var_name(technical_name):
    """Convert technical variable names to user-friendly ones"""
    return FRIENDLY_VAR_NAMES.get(technical_name, technical_name)