milwright Claude commited on
Commit
1770bc8
Β·
1 Parent(s): 12839ce

Add comprehensive support documentation module

Browse files

- Create support_docs.py with accordion-style help sections
- Include step-by-step guides for all major processes
- Add troubleshooting and best practices documentation
- Implement conversation export functionality

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. support_docs.py +364 -0
support_docs.py ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Support documentation module with accordion-style help sections
3
+ """
4
+
5
+ import gradio as gr
6
+
7
+ def create_support_docs():
8
+ """Create the support documentation interface with accordion menus"""
9
+
10
+ with gr.Column():
11
+ gr.Markdown("# Support Documentation")
12
+ gr.Markdown("Complete step-by-step guidance for creating and deploying chat interfaces with HuggingFace Spaces.")
13
+
14
+ with gr.Accordion("πŸš€ Getting Started", open=True):
15
+ gr.Markdown("""
16
+ ### Quick Start Guide
17
+
18
+ 1. **Configure your Space** in the main Configuration tab
19
+ 2. **Preview your assistant** using the Preview button
20
+ 3. **Generate deployment package** with the Generate button
21
+ 4. **Deploy to HuggingFace Spaces** following the README instructions
22
+
23
+ **Prerequisites:**
24
+ - HuggingFace account (free at huggingface.co)
25
+ - OpenRouter API key (get at openrouter.ai/keys)
26
+ - Basic understanding of AI chatbots
27
+ """)
28
+
29
+ with gr.Accordion("βš™οΈ Space Settings", open=False):
30
+ gr.Markdown("""
31
+ ### Space Configuration Fields
32
+
33
+ **Space Title**
34
+ - The name that will appear on HuggingFace and in your chat interface
35
+ - Keep it descriptive but concise (e.g., "Biology Course Assistant")
36
+
37
+ **Space Description**
38
+ - Brief explanation of what your assistant does
39
+ - Will appear in the HuggingFace Space listing and at the top of your chat
40
+
41
+ **Model Selection**
42
+ - **google/gemini-2.0-flash-001**: Fast, reliable, good for general tasks
43
+ - **anthropic/claude-3.5-haiku**: Great for complex reasoning and analysis
44
+ - **openai/gpt-4o-nano**: Balanced performance and cost
45
+ - **mistralai/mistral-medium**: Good for technical topics
46
+
47
+ **API Key Variable Name**
48
+ - Default: `OPENROUTER_API_KEY`
49
+ - This is the secret name you'll create in HuggingFace Space settings
50
+ - Only change if you have specific naming requirements
51
+
52
+ **Access Code (Optional)**
53
+ - Leave empty for public access
54
+ - Set a code to restrict access to students/specific users
55
+ - Code is stored securely as an environment variable
56
+ """)
57
+
58
+ with gr.Accordion("πŸ€– Assistant Configuration", open=False):
59
+ gr.Markdown("""
60
+ ### System Prompt Design
61
+
62
+ The system prompt defines your assistant's personality, knowledge, and behavior.
63
+
64
+ **Best Practices:**
65
+ - Be specific about the assistant's role and purpose
66
+ - Include behavioral guidelines and constraints
67
+ - Mention the intended audience (students, researchers, etc.)
68
+ - List key capabilities and tasks
69
+
70
+ **Research Template**
71
+ - Pre-configured for academic research assistance
72
+ - Includes MLA citation formatting
73
+ - Emphasizes fact-checking and evidence-based responses
74
+ - Automatically enables dynamic URL fetching
75
+
76
+ **Custom Categories**
77
+ - Break down your system prompt into structured sections:
78
+ - **Role and Purpose**: What is the assistant and what does it do?
79
+ - **Intended Audience**: Who will use this assistant?
80
+ - **Key Tasks**: What specific capabilities should it have?
81
+ - **Additional Context**: Extra instructions or constraints
82
+
83
+ **Example System Prompts:**
84
+ ```
85
+ Biology Course Assistant:
86
+ "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."
87
+
88
+ Research Writing Helper:
89
+ "You are a research writing assistant. Help students with citation formatting, argument structure, and source analysis. Focus on academic writing standards and proper documentation."
90
+ ```
91
+ """)
92
+
93
+ with gr.Accordion("πŸ’¬ Example Prompts", open=False):
94
+ gr.Markdown("""
95
+ ### Creating Effective Example Prompts
96
+
97
+ Example prompts appear as clickable suggestions in your chat interface.
98
+
99
+ **Guidelines:**
100
+ - Write 3-6 clear, specific examples
101
+ - Show the range of what your assistant can do
102
+ - Match your intended use cases
103
+ - Include URLs if your assistant can process them
104
+
105
+ **Format:**
106
+ - One prompt per line
107
+ - Keep each prompt under 100 characters for better display
108
+ - Use natural, conversational language
109
+
110
+ **Examples by Use Case:**
111
+
112
+ **Course Assistant:**
113
+ ```
114
+ Can you explain photosynthesis in simple terms?
115
+ Help me understand the difference between mitosis and meiosis
116
+ What should I focus on for the midterm exam?
117
+ ```
118
+
119
+ **Research Assistant:**
120
+ ```
121
+ Analyze this research paper: https://example.com/paper.pdf
122
+ Help me fact-check claims about climate change
123
+ What citation format should I use for this source?
124
+ ```
125
+
126
+ **Writing Helper:**
127
+ ```
128
+ Review my thesis statement for clarity
129
+ Help me organize my argument structure
130
+ Suggest improvements for this paragraph
131
+ ```
132
+ """)
133
+
134
+ with gr.Accordion("πŸ”§ Tool Settings & Grounding", open=False):
135
+ gr.Markdown("""
136
+ ### Tool Configuration Options
137
+
138
+ **Dynamic URL Fetching**
139
+ - Allows assistant to fetch content from URLs mentioned in conversations
140
+ - Useful for research and fact-checking tasks
141
+ - Automatically extracts text content from web pages
142
+ - Limited to 3 URLs per message for performance
143
+
144
+ **Document RAG (Retrieval-Augmented Generation)**
145
+ - Upload PDF, DOCX, TXT, or MD files as knowledge base
146
+ - Assistant can search and reference uploaded documents
147
+ - Perfect for course materials, policies, or reference documents
148
+ - Files are embedded in your deployment package
149
+
150
+ **URL Grounding**
151
+ - Add up to 4 URLs that provide static context
152
+ - Content is fetched once and included in every response
153
+ - Great for course syllabi, institutional policies, or reference materials
154
+ - Content is cached to avoid repeated fetching
155
+
156
+ **When to Use Each:**
157
+ - **Static URLs**: Course policies, syllabi, reference materials
158
+ - **Dynamic URLs**: Research tasks where students provide links
159
+ - **Document RAG**: Large document collections, textbooks, course readers
160
+
161
+ **File Size Limits:**
162
+ - Individual files: 10MB maximum
163
+ - Total RAG package: Recommended under 50MB for deployment
164
+ """)
165
+
166
+ with gr.Accordion("πŸŽ›οΈ Advanced Settings", open=False):
167
+ gr.Markdown("""
168
+ ### Model Parameters
169
+
170
+ **Temperature (0.0 - 2.0)**
171
+ - **0.0-0.3**: Very focused, deterministic responses
172
+ - **0.4-0.7**: Balanced creativity and consistency (recommended)
173
+ - **0.8-1.2**: More creative and varied responses
174
+ - **1.3-2.0**: Highly creative, potentially unpredictable
175
+
176
+ **Max Response Tokens (50-4096)**
177
+ - Controls maximum length of assistant responses
178
+ - **50-200**: Short, concise answers
179
+ - **200-500**: Medium responses (recommended for most cases)
180
+ - **500-1000**: Longer, detailed explanations
181
+ - **1000+**: Extended analysis and comprehensive responses
182
+
183
+ **Token Usage Notes:**
184
+ - Tokens include both input (your prompt + context) and output
185
+ - Longer contexts (documents, URLs) use more input tokens
186
+ - Monitor usage through OpenRouter dashboard
187
+ - Consider costs when setting high token limits
188
+ """)
189
+
190
+ with gr.Accordion("πŸš€ Deployment Process", open=False):
191
+ gr.Markdown("""
192
+ ### Step-by-Step Deployment
193
+
194
+ **1. Generate Package**
195
+ - Click "Generate Deployment Package" in the Configuration tab
196
+ - Download the zip file when ready
197
+ - Contains: app.py, requirements.txt, README.md, config.json
198
+
199
+ **2. Create HuggingFace Space**
200
+ - Go to [huggingface.co/spaces](https://huggingface.co/spaces)
201
+ - Click "Create new Space"
202
+ - Choose a name and set to Public or Private
203
+ - **Important**: Select "Gradio" as the SDK
204
+ - Click "Create Space"
205
+
206
+ **3. Upload Files**
207
+ - In your new Space, click the "Files" tab
208
+ - Upload `app.py` and `requirements.txt` from your zip
209
+ - Wait for the "Building" status to complete
210
+
211
+ **4. Add API Key**
212
+ - Go to Settings (gear icon) β†’ "Variables and secrets"
213
+ - Click "New secret"
214
+ - Name: Your API key variable name (usually `OPENROUTER_API_KEY`)
215
+ - Value: Your OpenRouter API key (get from openrouter.ai/keys)
216
+ - Click "Add"
217
+
218
+ **5. Configure Access (Optional)**
219
+ - If you set an access code, add another secret:
220
+ - Name: `SPACE_ACCESS_CODE`
221
+ - Value: Your chosen access code
222
+ - Students will need this code to use the assistant
223
+
224
+ **6. Test and Share**
225
+ - Go back to "App" tab
226
+ - Your Space should be running!
227
+ - Test with example prompts
228
+ - Share the Space URL with students
229
+ """)
230
+
231
+ with gr.Accordion("πŸ”§ Troubleshooting", open=False):
232
+ gr.Markdown("""
233
+ ### Common Issues and Solutions
234
+
235
+ **"Please set your API key" message**
236
+ - Check that you added the API key secret in Space settings
237
+ - Verify the secret name matches your configuration
238
+ - Ensure your OpenRouter account has credits
239
+
240
+ **Building Failed**
241
+ - Check `requirements.txt` formatting (no extra spaces/characters)
242
+ - Verify all required dependencies are listed
243
+ - Try reuploading files if build gets stuck
244
+
245
+ **Error 401 (Unauthorized)**
246
+ - Invalid API key or incorrect secret name
247
+ - Check OpenRouter account status and credits
248
+ - Regenerate API key if needed
249
+
250
+ **Error 429 (Too Many Requests)**
251
+ - Rate limit exceeded
252
+ - Wait a few minutes before trying again
253
+ - Consider upgrading OpenRouter plan for higher limits
254
+
255
+ **Assistant not responding**
256
+ - Check browser console for JavaScript errors
257
+ - Verify model name is correct and available
258
+ - Test with simple prompts first
259
+
260
+ **Access code not working**
261
+ - Verify `SPACE_ACCESS_CODE` secret is set correctly
262
+ - Check for typos in the access code
263
+ - Case-sensitive matching
264
+
265
+ **Documents not loading (RAG)**
266
+ - Check file formats are supported (PDF, DOCX, TXT, MD)
267
+ - Verify file sizes are under 10MB
268
+ - Ensure RAG dependencies are installed
269
+
270
+ **URLs not fetching content**
271
+ - Check URLs are publicly accessible
272
+ - Some sites block automated requests
273
+ - Verify dynamic URL fetching is enabled if needed
274
+ """)
275
+
276
+ with gr.Accordion("πŸ’‘ Best Practices", open=False):
277
+ gr.Markdown("""
278
+ ### Optimization Tips
279
+
280
+ **Performance**
281
+ - Use appropriate model for your use case
282
+ - Set reasonable token limits
283
+ - Cache static content with URL grounding
284
+ - Limit document uploads to essential materials
285
+
286
+ **User Experience**
287
+ - Write clear, helpful example prompts
288
+ - Include usage instructions in Space description
289
+ - Test thoroughly before sharing with students
290
+ - Provide clear access instructions if using codes
291
+
292
+ **Security**
293
+ - Never include API keys in code or README
294
+ - Use environment variables for all secrets
295
+ - Set appropriate access controls
296
+ - Monitor usage and costs regularly
297
+
298
+ **Maintenance**
299
+ - Regularly check for model updates
300
+ - Monitor student feedback and usage patterns
301
+ - Update grounding URLs if content changes
302
+ - Keep documentation current
303
+
304
+ **Cost Management**
305
+ - Start with lower token limits and adjust as needed
306
+ - Monitor usage through OpenRouter dashboard
307
+ - Consider setting up usage alerts
308
+ - Educate users on efficient prompting
309
+ """)
310
+
311
+ with gr.Accordion("πŸ“š Additional Resources", open=False):
312
+ gr.Markdown("""
313
+ ### Helpful Links
314
+
315
+ **HuggingFace Documentation**
316
+ - [Spaces Overview](https://huggingface.co/docs/hub/spaces-overview)
317
+ - [Gradio on Spaces](https://huggingface.co/docs/hub/spaces-gradio)
318
+ - [Environment Variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets)
319
+
320
+ **OpenRouter Documentation**
321
+ - [API Keys](https://openrouter.ai/keys)
322
+ - [Model Comparison](https://openrouter.ai/models)
323
+ - [Pricing](https://openrouter.ai/docs#models)
324
+
325
+ **Gradio Documentation**
326
+ - [Chat Interface](https://gradio.app/docs/chatinterface)
327
+ - [Components](https://gradio.app/docs/)
328
+ - [Sharing Apps](https://gradio.app/sharing-your-app/)
329
+
330
+ **Community Support**
331
+ - [HuggingFace Community Forums](https://discuss.huggingface.co/)
332
+ - [Gradio Discord](https://discord.gg/feTf9x3ZSB)
333
+
334
+ **Educational Use Cases**
335
+ - Course assistants for Q&A
336
+ - Research writing support
337
+ - Study guide generation
338
+ - Document analysis tools
339
+ - Language practice partners
340
+ """)
341
+
342
+ def export_conversation_to_markdown(conversation_history):
343
+ """Export conversation history to markdown format"""
344
+ if not conversation_history:
345
+ return "No conversation to export."
346
+
347
+ markdown_content = f"""# Conversation Export
348
+ Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
349
+
350
+ ---
351
+
352
+ """
353
+
354
+ for i, message in enumerate(conversation_history):
355
+ if isinstance(message, dict):
356
+ role = message.get('role', 'unknown')
357
+ content = message.get('content', '')
358
+
359
+ if role == 'user':
360
+ markdown_content += f"## User Message {(i//2) + 1}\n\n{content}\n\n"
361
+ elif role == 'assistant':
362
+ markdown_content += f"## Assistant Response {(i//2) + 1}\n\n{content}\n\n---\n\n"
363
+
364
+ return markdown_content