File size: 28,937 Bytes
1770bc8
 
675fc70
 
 
 
 
 
 
 
 
 
 
1770bc8
 
 
28a389b
1770bc8
0a378f4
1770bc8
 
 
 
 
675fc70
1770bc8
 
 
 
 
675fc70
 
1770bc8
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
675fc70
1770bc8
 
 
 
 
 
 
 
 
675fc70
1770bc8
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
675fc70
 
f51b1f2
 
 
1770bc8
 
675fc70
1770bc8
 
675fc70
1770bc8
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
675fc70
1770bc8
 
 
 
 
 
f51b1f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
 
f51b1f2
 
 
 
 
 
 
 
1770bc8
 
 
dc5c13f
 
 
675fc70
dc5c13f
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc5c13f
675fc70
dc5c13f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
 
 
675fc70
1770bc8
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
675fc70
1770bc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc5c13f
1770bc8
dc5c13f
675fc70
dc5c13f
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc5c13f
675fc70
dc5c13f
 
 
 
 
 
 
 
 
 
 
 
1770bc8
 
 
 
 
675fc70
1770bc8
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
675fc70
1770bc8
 
814e035
1770bc8
 
 
 
 
f51b1f2
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f51b1f2
 
 
 
 
 
 
 
 
0a378f4
 
 
 
 
 
f51b1f2
0a378f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f51b1f2
 
 
 
 
 
 
 
 
1770bc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
814e035
1770bc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675fc70
 
1770bc8
 
 
 
 
 
675fc70
 
 
 
 
1770bc8
 
675fc70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1770bc8
 
 
 
 
 
 
 
 
 
 
 
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
"""
Support documentation module with accordion-style help sections

IMAGE PLACEHOLDERS TO REPLACE:
1. interface_overview.png - Three-tab interface overview (Getting Started)
2. configuration_tab.png - Configuration tab screenshot (Space Settings)
3. system_prompt_interface.png - System prompt and template interface (Assistant Configuration)
4. preview_tab.png - Preview tab with chat interface (Preview Tab Usage)
5. example_prompts.png - Example prompts input and display (Example Prompts)
6. tool_settings_diagram.png - Configuration structure diagram (Tool Settings)
7. advanced_settings.png - Temperature and token controls (Advanced Settings)
8. deployment_process.png - Deployment process flow diagram (Deployment Process)
9. secret.png - HuggingFace secret configuration (already exists)
"""

import gradio as gr
from datetime import datetime


def create_support_docs():
    """Create the support documentation interface with accordion menus"""
    
    with gr.Column():
        gr.Markdown("# Support Documentation")
        gr.Markdown("*Under construction - images coming soon!*")
        gr.Markdown("Complete step-by-step guidance for creating and deploying chat interfaces with HuggingFace Spaces.")
        
        with gr.Accordion("πŸš€ Getting Started", open=True):
            gr.Markdown("""
            ### Quick Start Guide
            This guide helps you set up your first chat interface on HuggingFace Spaces using Gradio. Follow these steps to create a functional assistant with URL grounding and example prompts.
            """)
            
            # TODO: Add interface overview screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="interface_overview.png",  # Placeholder for interface overview screenshot
                        label="Three-Tab Interface: Configuration, Preview, and Support",
                        show_label=True,
                        interactive=False,
                        width=600,
                        height=400,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Workflow Steps:**
                    1. **Configure** your space settings
                    2. **Set up** assistant with system prompt
                    3. **Enable** tools like URL grounding
                    4. **Preview** & test your configuration
                    5. **Generate** deployment package
                    6. **Deploy** to HuggingFace
                    """)
            
            gr.Markdown("""
            **Prerequisites:**
            - HuggingFace account (free at huggingface.co)
            - OpenRouter API key (get at openrouter.ai/keys)
            - Basic understanding of AI chatbots
            """)
        
        with gr.Accordion("βš™οΈ Space Settings", open=False):
            gr.Markdown("""
            ### Space Configuration Fields
            """)
            
            # TODO: Add configuration tab screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="configuration_tab.png",  # Placeholder for configuration tab screenshot
                        label="Configuration Tab Interface",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=400,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Key Configuration Fields:**
                    
                    **Space Title** - Display name for your assistant
                    
                    **Space Description** - Brief explanation of purpose
                    
                    **Model Selection** - Choose from optimized models:
                    - **Gemma 3 27B** - Open-source, sustainable
                    - **Gemini 2.0 Flash** - Fast, reliable
                    - **Claude 3.5 Haiku** - Complex reasoning
                    
                    **API Key Variable** - Default: `OPENROUTER_API_KEY`
                    
                    **Access Code** - Optional student protection
                    """)
            
            gr.Markdown("""
            **Model Comparison:**
            - **[google/gemma-3-27b-it](https://openrouter.ai/models/google/gemma-3-27b-it)**: Open-source, sustainable option with excellent performance
            - **[google/gemini-2.0-flash-001](https://openrouter.ai/models/google/gemini-2.0-flash-001)**: Fast, reliable, good for general tasks
            - **[anthropic/claude-3.5-haiku](https://openrouter.ai/models/anthropic/claude-3.5-haiku)**: Great for complex reasoning and analysis
            """)
        
        with gr.Accordion("πŸ€– Space Configuration", open=False):
            gr.Markdown("""
            ### System Prompt Design
            """)
            
            # TODO: Add system prompt interface screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="system_prompt_interface.png",  # Placeholder for system prompt interface
                        label="System Prompt Configuration Interface",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=300,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Template System:**
                    
                    **Research Template** - Pre-configured for academic use
                    - MLA citation formatting
                    - Fact-checking emphasis
                    - Auto-enables URL fetching
                    
                    **Socratic Template** - Pedagogical questioning
                    - Constructivist learning approach
                    - Critical thinking focus
                    
                    **Custom Prompt** - Build your own
                    """)
            
            gr.Markdown("""
            **Best Practices:**
            - Be specific about the assistant's role and purpose
            - Include behavioral guidelines and constraints
            - Mention the intended audience (students, researchers, etc.)
            - List key capabilities and tasks
            
            ### Copy-Pasteable System Prompts
            
            **Biology Course Assistant:**
            ```
            You are a biology teaching assistant for undergraduate students. Help with concepts, lab procedures, and study questions. Always explain complex topics in simple terms and encourage critical thinking. Focus on helping students understand fundamental biological processes and prepare for exams.
            ```
            
            **Research Writing Helper:**
            ```
            You are a research writing assistant. Help students with citation formatting, argument structure, and source analysis. Focus on academic writing standards and proper documentation. Guide students through the research process from topic selection to final paper submission.
            ```
            
            **Course Q&A Assistant (Template):**
            ```
            You are a knowledgeable academic assistant for [COURSE NAME] students. Provide clear, evidence-based answers about [SUBJECT AREA] while encouraging deeper engagement through follow-up questions. Use accessible language appropriate for [STUDENT LEVEL]. Keep responses concise (under 100 words) with bullet points when helpful. End each response with a thought-provoking question or real-world connection that encourages students to think critically about the topic and explore related concepts.
            ```
            
            **Psychology 101 Example:**
            ```
            You are a knowledgeable academic research assistant for a Psychology 101 class. Provide students with clear, evidence-based answers about psychology topics while encouraging deeper engagement through follow-up questions. Use accessible language appropriate for introductory students. Keep responses concise (under 100 words) with bullet points when helpful. End each response with a thought-provoking question or real-world example that encourages students to think critically about how psychology concepts apply to everyday life.
            ```
            
            **Technical Support Helper:**
            ```
            You are a technical support assistant specializing in software tools and programming concepts. Provide step-by-step guidance, troubleshoot common issues, and explain technical concepts in accessible language. Always include examples when possible.
            ```
            
            **Research Assistant (Pre-configured Template):**
            ```
            You are a research assistant that provides link-grounded information through web fetching. Use MLA documentation for parenthetical citations and bibliographic entries. This assistant is designed for students and researchers conducting academic inquiry. Your main responsibilities include: analyzing academic sources, fact-checking claims with evidence, providing properly cited research summaries, and helping users navigate scholarly information. Ground all responses in provided URL contexts and any additional URLs you're instructed to fetch. Never rely on memory for factual claims.
            ```
            """)
        
        with gr.Accordion("πŸ”¬ Preview Tab Usage", open=False):
            gr.Markdown("""
            ### Testing Your Assistant Before Deployment
            """)
            
            # TODO: Add preview tab screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="preview_tab.png",  # Placeholder for preview tab screenshot
                        label="Preview Tab with Active Chat Interface",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=400,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Preview Features:**
                    
                    **Real API Integration** - Uses actual OpenRouter API
                    
                    **Configuration Display** - Shows current setup
                    
                    **URL Testing** - Add up to 4 URLs for context
                    
                    **Chat Export** - Download conversation logs
                    
                    **Clear Function** - Reset chat history
                    """)
            
            gr.Markdown("""
            **How to Use the Preview:**
            1. **Configure First**: Complete your setup in the Configuration tab
            2. **Click Preview Button**: Use "Preview Deployment Package" to activate the preview
            3. **Test Chat Interface**: Interactive chat with your exact configuration
            4. **Test URL Context**: Add URLs to test grounding functionality
            5. **Export Conversations**: Save chat logs for analysis
            
            **Preview Requirements:**
            - Set `OPENROUTER_API_KEY` environment variable for real API testing
            - Without API key: Shows configuration but no actual chat responses
            
            **Testing Best Practices:**
            - Test different types of queries to validate assistant behavior
            - Try URL grounding with actual websites to test context integration
            - Verify that system prompt and model settings work as expected
            - Export successful conversations to use as examples for documentation
            """)
        
        with gr.Accordion("πŸ’¬ Example Prompts", open=False):
            gr.Markdown("""
            ### Creating Effective Example Prompts
            """)
            
            # TODO: Add example prompts interface screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="example_prompts.png",  # Placeholder for example prompts interface
                        label="Example Prompts Interface and Display",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=300,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Guidelines:**
                    
                    **Format** - One prompt per line
                    
                    **Length** - Under 100 characters each
                    
                    **Content** - Show assistant capabilities
                    
                    **Language** - Natural and conversational
                    
                    **URLs** - Include if assistant processes them
                    """)
            
            gr.Markdown("""
            **Examples by Use Case:**
            
            **Course Assistant:**
            ```
            Can you explain photosynthesis in simple terms?
            Help me understand the difference between mitosis and meiosis
            What should I focus on for the midterm exam?
            ```
            
            **Research Assistant:**
            ```
            Analyze this research paper: https://example.com/paper.pdf
            Help me fact-check claims about climate change
            What citation format should I use for this source?
            ```
            
            **Writing Helper:**
            ```
            Review my thesis statement for clarity
            Help me organize my argument structure
            Suggest improvements for this paragraph
            ```
            """)
        
        with gr.Accordion("πŸ”§ Tool Settings & Configuration", open=False):
            gr.Markdown("""
            ### Configuration Tab Structure
            """)
            
            # TODO: Add tool settings diagram
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="tool_settings_diagram.png",  # Placeholder for tool settings structure diagram
                        label="Configuration Tab Structure and Tool Integration",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=400,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Main Configuration Fields:**
                    - Space Title & Description
                    - Model Selection
                    - API Key Variable
                    - Access Code (optional)
                    
                    **Assistant Configuration:**
                    - System Prompt
                    - Template Selection
                    - URL Grounding (2-4 URLs)
                    - Example Prompts
                    
                    **Advanced Settings:**
                    - Temperature (0.0-2.0)
                    - Max Tokens (50-4096)
                    """)
            
            gr.Markdown("""
            ### Tool Integration Options
            
            **URL Grounding (Static Context)**
            - Add 2-4 URLs for consistent context across all responses
            - Content fetched once during generation and cached
            - Dynamic add/remove buttons for scalable input
            - Perfect for course syllabi, policies, reference materials
            
            **Dynamic URL Fetching (Runtime)**
            - Always enabled - processes URLs mentioned in conversations
            - Extracts content from user-provided links automatically
            - Limited to reasonable content size for performance
            """)
        
        with gr.Accordion("πŸŽ›οΈ Advanced Settings", open=False):
            gr.Markdown("""
            ### Model Parameters
            """)
            
            # TODO: Add advanced settings interface screenshot
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="advanced_settings.png",  # Placeholder for advanced settings interface
                        label="Advanced Settings: Temperature and Token Controls",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=300,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Temperature (0.0 - 2.0)**
                    - **0.0-0.3**: Very focused, deterministic
                    - **0.4-0.7**: Balanced (recommended)
                    - **0.8-1.2**: More creative and varied
                    - **1.3-2.0**: Highly creative, unpredictable
                    
                    **Max Response Tokens (50-4096)**
                    - **50-200**: Short, concise answers
                    - **200-500**: Medium responses (recommended)
                    - **500-1000**: Longer, detailed explanations
                    - **1000+**: Extended analysis
                    """)
            
            gr.Markdown("""
            **Token Usage Notes:**
            - Tokens include both input (your prompt + context) and output
            - Longer contexts (URLs) use more input tokens
            - Consider costs when setting high token limits
            """)
        
        with gr.Accordion("πŸš€ Deployment Process", open=False):
            gr.Markdown("""
            ### Quick Deployment Guide
            """)
            
            # TODO: Add deployment process diagram
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="deployment_process.png",  # Placeholder for deployment process diagram
                        label="Complete Deployment Process Flow",
                        show_label=True,
                        interactive=False,
                        width=500,
                        height=300,
                        container=False
                    )
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Deployment Steps:**
                    
                    **1. Generate Package** - Download zip file
                    
                    **2. Create Space** - New HuggingFace Space (Gradio SDK)
                    
                    **3. Upload Files** - app.py and requirements.txt
                    
                    **4. Add API Key** - Secret configuration
                    
                    **5. Deploy & Test** - Wait for build, then test
                    """)
            
            gr.Markdown("""
            **Detailed Steps:**
            
            **1. Generate & Upload**
            - Click "Generate Deployment Package" β†’ download zip
            - Create new Space at [huggingface.co/spaces](https://huggingface.co/spaces) (select **Gradio** SDK)
            - Upload `app.py` and `requirements.txt` from zip to Files tab
            
            **2. Add Your OpenRouter API Key**
            Since you already have an OpenRouter API key, add it as a secret:
            - Go to Settings β†’ Variables and secrets β†’ New secret
            - Name: `OPENROUTER_API_KEY` (or your chosen variable name)
            - Value: Your OpenRouter API key (starts with `sk-or-`)
            - Click "Add" to save the secret
            
            The secret configuration interface looks like this:
            """)
            
            # Add the secret configuration image (flush left)
            with gr.Row():
                with gr.Column(scale=1):
                    gr.Image(
                        value="https://drive.google.com/uc?export=view&id=1z67BZrYlJkpvHJ0Dp6vvIWAkN2iwUxCv",
                        label="HuggingFace Secret Configuration Interface",
                        show_label=False,
                        interactive=False,
                        width=400,
                        height=300,
                        container=False
                    )
                with gr.Column(scale=2):
                    pass  # Empty column to push image left
            
            gr.Markdown("""
            *If the image above doesn't load, the interface shows:*
            - **Name**: `OPENROUTER_API_KEY` (your API key variable name)
            - **Description**: Optional description
            - **Value**: Your OpenRouter API key (starts with `sk-or-`)
            - **Save** button to store the secret
            
            **3. Optional: Add Access Code**
            If you configured student access protection:
            - Add another secret: Name = `SPACE_ACCESS_CODE`, Value = your chosen code
            
            **4. Deploy & Share**
            - Wait for build completion β†’ test in App tab β†’ share URL with students
            
            **That's it!** Your Space will be live and ready for use.
            """)
        
        with gr.Accordion("πŸ”§ Troubleshooting", open=False):
            gr.Markdown("""
            ### Common Issues and Solutions
            
            **"Please set your API key" message**
            - Check that you added the API key secret in Space settings
            - Verify the secret name matches your configuration
            - Ensure your OpenRouter account has credits
            
            **Building Failed**
            - Check `requirements.txt` formatting (no extra spaces/characters)
            - Verify all required dependencies are listed
            - Try reuploading files if build gets stuck
            
            **Error 401 (Unauthorized)**
            - Invalid API key or incorrect secret name
            - Check OpenRouter account status and credits
            - Regenerate API key if needed
            
            **Error 429 (Too Many Requests)**
            - Rate limit exceeded
            - Wait a few minutes before trying again
            - Consider upgrading OpenRouter plan for higher limits
            
            **Assistant not responding**
            - Check browser console for JavaScript errors
            - Verify model name is correct and available
            - Test with simple prompts first
            
            **Access code not working**
            - Verify `SPACE_ACCESS_CODE` secret is set correctly
            - Check for typos in the access code
            - Case-sensitive matching
            
            **URLs not fetching content**
            - Check URLs are publicly accessible
            - Some sites block automated requests
            - Verify dynamic URL fetching is enabled if needed
            """)
        
        with gr.Accordion("πŸ’‘ Best Practices", open=False):
            gr.Markdown("""
            ### Optimization Tips
            
            **Performance**
            - Use appropriate model for your use case
            - Set reasonable token limits
            - Cache static content with URL grounding
            # Document RAG functionality removed
            
            **User Experience**
            - Write clear, helpful example prompts
            - Include usage instructions in Space description
            - Test thoroughly before sharing with students
            - Provide clear access instructions if using codes
            
            **Security**
            - Never include API keys in code or README
            - Use environment variables for all secrets
            - Set appropriate access controls
            - Monitor usage and costs regularly
            
            **Maintenance**
            - Regularly check for model updates
            - Monitor student feedback and usage patterns
            - Update grounding URLs if content changes
            - Keep documentation current
            
            **Cost Management**
            - Start with lower token limits and adjust as needed
            - Monitor usage through OpenRouter dashboard
            - Consider setting up usage alerts
            - Educate users on efficient prompting
            """)
        
        with gr.Accordion("πŸ“š Additional Resources", open=False):
            gr.Markdown("""
            ### Helpful Links
            
            **HuggingFace Documentation**
            - [Spaces Overview](https://huggingface.co/docs/hub/spaces-overview)
            - [Gradio on Spaces](https://huggingface.co/docs/hub/spaces-gradio)
            - [Environment Variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets)
            
            **OpenRouter Documentation**
            - [API Keys](https://openrouter.ai/keys)
            - [Model Comparison](https://openrouter.ai/models)
            - [Pricing](https://openrouter.ai/docs#models)
            
            **Gradio Documentation**
            - [Chat Interface](https://gradio.app/docs/chatinterface)
            - [Components](https://gradio.app/docs/)
            - [Sharing Apps](https://gradio.app/sharing-your-app/)
            
            **Community Support**
            - [HuggingFace Community Forums](https://discuss.huggingface.co/)
            - [Gradio Discord](https://discord.gg/feTf9x3ZSB)
            
            **Educational Use Cases**
            - Course assistants for Q&A
            - Research writing support
            - Study guide generation
            - Document analysis tools
            - Language practice partners
            """)

def export_conversation_to_markdown(conversation_history, config_metadata=None):
    """Export conversation history to markdown format with configuration metadata"""
    if not conversation_history:
        return "No conversation to export."
    
    markdown_content = f"""# Conversation Export
Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}

"""
    
    # Add configuration metadata if provided
    if config_metadata:
        markdown_content += """## Configuration Information

"""
        
        # Add basic configuration details
        if config_metadata.get('name'):
            markdown_content += f"**Assistant Name:** {config_metadata['name']}\n"
        if config_metadata.get('description'):
            markdown_content += f"**Description:** {config_metadata['description']}\n"
        if config_metadata.get('model'):
            markdown_content += f"**Model:** {config_metadata['model']}\n"
        if config_metadata.get('temperature'):
            markdown_content += f"**Temperature:** {config_metadata['temperature']}\n"
        if config_metadata.get('max_tokens'):
            markdown_content += f"**Max Tokens:** {config_metadata['max_tokens']}\n"
        
        # Add URL grounding information
        grounding_urls = []
        for i in range(1, 5):
            url = config_metadata.get(f'url{i}')
            if url and url.strip():
                grounding_urls.append(url.strip())
        
        if grounding_urls:
            markdown_content += f"\n**URL Grounding ({len(grounding_urls)} URLs):**\n"
            for i, url in enumerate(grounding_urls, 1):
                markdown_content += f"- URL {i}: {url}\n"
        
        # Add feature flags
        if config_metadata.get('enable_dynamic_urls'):
            markdown_content += f"\n**Dynamic URL Fetching:** Enabled\n"
        
        # Add system prompt
        if config_metadata.get('system_prompt'):
            system_prompt = config_metadata['system_prompt']
            markdown_content += f"\n**System Prompt:**\n```\n{system_prompt}\n```\n"
        
        markdown_content += "\n---\n\n"
    else:
        markdown_content += "---\n\n"
    
    for i, message in enumerate(conversation_history):
        if isinstance(message, dict):
            role = message.get('role', 'unknown')
            content = message.get('content', '')
            
            if role == 'user':
                markdown_content += f"## User Message {(i//2) + 1}\n\n{content}\n\n"
            elif role == 'assistant':
                markdown_content += f"## Assistant Response {(i//2) + 1}\n\n{content}\n\n---\n\n"
    
    return markdown_content