milwright commited on
Commit
b0c1c7e
Β·
1 Parent(s): 8647ff2

add docs.md and img files from origin/main

Browse files
Files changed (1) hide show
  1. docs.md +386 -0
docs.md ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ChatUI Helper Documentation
2
+
3
+ Welcome to ChatUI Helper! This tool helps you create customizable AI chat interfaces for deployment on HuggingFace Spaces.
4
+
5
+ ## πŸ“– Quick Start Guide
6
+
7
+ ### Overview
8
+
9
+ 1. **Configure** your assistant using templates or custom settings
10
+ 2. **Preview** your configuration to test it works
11
+ 3. **Generate** your deployment package
12
+ 4. **Deploy** to HuggingFace Spaces
13
+
14
+ **Requirements:**
15
+
16
+ - HuggingFace account (free)
17
+ - OpenRouter API key
18
+ - Basic understanding of AI assistants
19
+
20
+ <img src="img/march.png" alt="March of Intellect by Robert Seymour" width="500">
21
+ <i>"The March of Intellect" by Robert Seymour (c.1828)</i>
22
+
23
+ ---
24
+ ---
25
+
26
+ ## πŸ“ Step 1: Configure & Preview Your Space
27
+
28
+ ### Configuration Tab Overview
29
+
30
+ Configure your assistant through various sections in the Configuration tab, then test it in the Preview tab before generating your deployment package.
31
+
32
+ <details>
33
+ <summary><b>Templates & Identity</b></summary>
34
+
35
+ **Quick Start Templates**
36
+
37
+ - Choose from pre-configured academic templates (Socratic Research Chat, STEM Adventure Games, etc.)
38
+ - Or select "None (Custom)" for a blank slate
39
+
40
+ **Space Identity**
41
+
42
+ - **Assistant Name**: Give your space a memorable name
43
+ - **Tagline**: Brief description (max 60 characters) for HuggingFace YAML frontmatter
44
+ - **Description**: Full markdown description for the README
45
+ - **Theme**: Select from Gradio themes (Default, Soft, Glass, Monochrome, Base)
46
+
47
+ <img src="img/identity.png" alt="Space Identity Configuration" width="500">
48
+
49
+ </details>
50
+
51
+ <details>
52
+ <summary><b>System Configuration</b></summary>
53
+
54
+ **System Prompt**
55
+
56
+ - Define your assistant's role, context, and behavior
57
+ - Set guardrails and creative constraints
58
+ - Specify audience and terms of engagement
59
+
60
+ **Model Selection**
61
+
62
+ - Choose from available models (Gemini, Claude, GPT, Mistral, etc.)
63
+ - Or enter a custom model ID
64
+
65
+ **Language Support**
66
+
67
+ - Configure language through system prompt instructions
68
+ - Assistant can be instructed to respond exclusively in any language
69
+ - See "Language Learning Partner" template for Italian example
70
+
71
+ **Sampling Parameters**
72
+
73
+ - **Temperature** (0-2): Controls response variability
74
+ - **Max Tokens** (50-4096): Limits response length
75
+
76
+ <img src="img/instructions.png" alt="System Instructions Configuration" width="600">
77
+
78
+ </details>
79
+
80
+ <details>
81
+ <summary><b>Example Prompts</b></summary>
82
+
83
+ **Example Prompts**
84
+
85
+ - Add 3-5 starter prompts that showcase your assistant's capabilities
86
+ - These appear as quick-start buttons for users
87
+ - Help users understand how to interact with your assistant
88
+ - Use the βž•/βž– buttons to add or remove examples
89
+
90
+ </details>
91
+
92
+ <details>
93
+ <summary><b>URL Grounding</b></summary>
94
+
95
+ **Grounding URLs**
96
+
97
+ - Add up to 10 reference URLs to provide context
98
+ - **Primary Sources (URLs 1-2)**: Always loaded, up to 8000 characters each
99
+ - **Secondary Sources (URLs 3+)**: Supplementary context, up to 2500 characters each
100
+ - URLs are fetched and included in the system prompt
101
+ - Assistant will cite specific URLs when using grounded information
102
+ - Use the βž•/βž– buttons to manage URLs
103
+
104
+ <img src="img/grounding.png" alt="URL Grounding Configuration" width="300">
105
+
106
+ </details>
107
+
108
+ <details>
109
+ <summary><b>Environment Variables</b></summary>
110
+
111
+ **Required Secrets**
112
+
113
+ - **API_KEY** (Required): Your OpenRouter API key (must start with `sk-or-`)
114
+ - Get from: https://openrouter.ai/keys
115
+ - Configure in HuggingFace Space settings
116
+
117
+ - **HF_TOKEN** (Recommended): Enables configuration editor in deployed Space
118
+ - Get from: https://huggingface.co/settings/tokens
119
+ - Select "write" permissions when creating
120
+ - Allows updating configuration without redeployment
121
+
122
+ - **ACCESS_CODE** (Recommended): Password-protect your Space
123
+ - Set any password value
124
+ - Users will need this code to access
125
+ - Leave unset for public access
126
+
127
+ <img src="img/settings.png" alt="Navigate to Settings" width="500">
128
+ <img src="img/add-secret-api.png" alt="Variables and Secrets" width="500">
129
+
130
+ </details>
131
+
132
+ <details>
133
+ <summary><b>Upload Configuration</b></summary>
134
+
135
+ **Upload Existing Configuration**
136
+ - Have a previous `config.json` file?
137
+ - Use the "Upload Configuration" accordion
138
+ - Drag and drop or click to upload
139
+ - All settings will be restored automatically
140
+
141
+ <img src="img/upload.png" alt="Upload Configuration" width="500">
142
+
143
+ </details>
144
+
145
+ <details>
146
+ <summary><b>Preview Your Assistant</b></summary>
147
+
148
+ **Testing in Preview Tab**
149
+ - Click "πŸ’¬ Preview Configuration" to prepare your assistant
150
+ - Switch to the Preview tab
151
+ - Test with real queries and example prompts
152
+ - Upload files if file upload is enabled
153
+ - Export conversation history as markdown
154
+
155
+ **Preview Features**
156
+ - Real-time API responses (requires API key in environment)
157
+ - Grounding context from configured URLs
158
+ - Language-specific responses
159
+ - Conversation export
160
+
161
+ <img src="img/preview-config.png" alt="Preview Configuration" width="500">
162
+
163
+ </details>
164
+
165
+ ---
166
+ ---
167
+
168
+ ## πŸ—³οΈ Step 2: Generate & Deploy
169
+
170
+ ### Deployment Package & HuggingFace Space Setup
171
+
172
+ **Package Contents:** `app.py` (application), `requirements.txt` (dependencies), `config.json` (configuration), `README.md` (overview)
173
+
174
+ <details>
175
+ <summary><b>Generate & Create Space</b></summary>
176
+
177
+ **Generate Deployment Package**
178
+
179
+ 1. Click "πŸ—³οΈ Generate Deployment Package" in Configuration tab
180
+ 2. Download the generated ZIP file
181
+ 3. Extract files: `app.py`, `config.json`, `requirements.txt`, `README.md`
182
+
183
+ <img src="img/deployment.png" alt="Deployment Package" width="500">
184
+
185
+ **Create New Space**
186
+
187
+ 1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
188
+ 2. Click "Create new Space"
189
+ 3. Name your Space
190
+ 4. Add your preferred licensing (e.g. gpl-3, mit)
191
+ 5. Select **Gradio** SDK
192
+ 6. Choose **Blank** template
193
+ 7. Select hardware (CPU Basic is free)
194
+ 8. Click "Create Space"
195
+
196
+ <img src="img/create-space.png" alt="Click Create Space" width="500">
197
+ <img src="img/space.png" alt="Deployed Space" width="500">
198
+
199
+ </details>
200
+
201
+ <details>
202
+ <summary><b>Upload Files</b></summary>
203
+
204
+ **Upload Project Files**
205
+ 1. Navigate to the **Files** tab in your new Space
206
+ 2. Click "Contribute" β†’ "Upload files"
207
+ 3. Unzip the deployment package
208
+ 4. Select all 4 files from your extracted package:
209
+ - `README.md`
210
+ - `app.py`
211
+ - `config.json`
212
+ - `requirements.txt`
213
+ 5. Commit directly to main branch, and your Space will start building
214
+
215
+ <img src="img/drop-files.png" alt="Drag and drop files" width="500">
216
+
217
+ <img src="img/uploading.png" alt="Commit files to space" width="500">
218
+
219
+ </details>
220
+
221
+ <details>
222
+ <summary><b>Configure Secrets</b></summary>
223
+
224
+ **Navigate to Settings**
225
+ 1. Click the **Settings** tab in your Space
226
+ <img src="img/settings.png" alt="Navigate to settings" width="500">
227
+ 2. Scroll down to **Variables and secrets** section
228
+ 3. Click **New secret**
229
+ <img src="img/add-secret-api.png" alt="Adding API Key Secret" width="500">
230
+
231
+ **Add Required Secret**
232
+ - **Name**: `API_KEY` (or your configured variable name)
233
+ - **Value**: Your OpenRouter API key
234
+ - Must start with `sk-or-`
235
+
236
+ **Add Optional Secrets (if desired)**
237
+ - **HF_TOKEN**: Your HuggingFace token with write permissions
238
+ - Enables the configuration editor in your Space
239
+ - Get from: https://huggingface.co/settings/tokens
240
+
241
+ - **ACCESS_CODE**: Any password value
242
+ - Restricts access to authorized users
243
+ - Do NOT set an empty value
244
+ - Either set a code or don't create the secret
245
+
246
+ </details>
247
+
248
+ <details>
249
+ <summary><b>Verify & Iterate</b></summary>
250
+
251
+ **Monitor Build Process**
252
+ 1. Return to the **App** tab
253
+ 2. Watch for "Building..." status
254
+ 3. Check build logs for any errors
255
+ 4. Wait 1-3 minutes for completion
256
+ 5. Space will show "Running" when ready
257
+
258
+ **Test Your Deployment**
259
+ 1. Try the example prompts
260
+ 2. Test different types of queries
261
+ 3. Verify grounding URLs are working
262
+ 4. Check language responses (if configured)
263
+
264
+ **Iterate Configuration (with HF_TOKEN)**
265
+ 1. Go to βš™οΈ Configuration tab in your Space
266
+ 2. Enter your HF_TOKEN to authenticate
267
+ 3. Modify settings as needed
268
+ 4. Click "Save Configuration"
269
+ 5. Space will automatically rebuild
270
+ 6. Test new configuration
271
+
272
+ </details>
273
+
274
+ ---
275
+ ---
276
+
277
+ ## πŸ”§ Troubleshooting
278
+
279
+ ### Common Issues and Solutions
280
+
281
+ Find solutions to common problems organized by category.
282
+
283
+ <details>
284
+ <summary><b>Build Errors</b></summary>
285
+
286
+ **Requirements Compatibility**
287
+ - Ensure Gradio version β‰₯ 5.39.0 in requirements.txt
288
+ - Check all dependencies are spelled correctly
289
+ - Verify version numbers are compatible
290
+
291
+ **Common Build Failures**
292
+ - Missing dependencies: Add to requirements.txt
293
+ - Import errors: Check module names and casing
294
+ - Syntax errors: Review app.py for Python syntax issues
295
+
296
+ </details>
297
+
298
+ <details>
299
+ <summary><b>API Errors</b></summary>
300
+
301
+ **API Key Issues**
302
+ - Verify API_KEY is set in HuggingFace Secrets
303
+ - Ensure key starts with 'sk-or-' for OpenRouter
304
+ - Check for extra spaces or quotes in the secret value
305
+
306
+ **API Response Errors**
307
+ - 401 Unauthorized: Invalid API key
308
+ - 402 Payment Required: No API credits remaining
309
+ - 429 Rate Limited: Too many requests, wait and retry
310
+ - 500 Server Error: OpenRouter service issue
311
+
312
+ </details>
313
+
314
+ <details>
315
+ <summary><b>Access Control Issues</b></summary>
316
+
317
+ **ACCESS_CODE Problems**
318
+ - Code must match exactly (case-sensitive)
319
+ - Don't include quotes around the password
320
+ - Check for trailing spaces in the secret
321
+ - To disable: Delete the ACCESS_CODE secret entirely
322
+
323
+ **Authentication Flow**
324
+ - Users enter code on first visit
325
+ - Code is stored in browser session
326
+ - Clear cookies to re-prompt for code
327
+
328
+ </details>
329
+
330
+ <details>
331
+ <summary><b>Preview Tab Not Working</b></summary>
332
+
333
+ **Preview Issues**
334
+ - Click "πŸ’¬ Preview Configuration" first
335
+ - Ensure all required fields are filled
336
+ - Try refreshing the page
337
+
338
+ </details>
339
+
340
+ <details>
341
+ <summary><b>Configuration Status Shows ❌</b></summary>
342
+
343
+ **Status Check Failures**
344
+ - Red X means configuration issue detected
345
+ - Usually indicates missing or invalid API key
346
+
347
+ **Resolution Steps**
348
+ 1. Verify secret name matches your configuration
349
+ 2. Default is API_KEY, check if you changed it
350
+ 3. Regenerate API key at openrouter.ai/keys
351
+ 4. Update secret in HuggingFace Space settings
352
+ 5. Wait 30 seconds and refresh
353
+
354
+ </details>
355
+
356
+ ---
357
+ ---
358
+
359
+ ## πŸ“š Additional Resources
360
+
361
+ ### Documentation Links
362
+
363
+ **HuggingFace**
364
+
365
+ - [Spaces Overview](https://huggingface.co/docs/hub/spaces-overview)
366
+ - [Gradio on Spaces](https://huggingface.co/docs/hub/spaces-gradio)
367
+ - [Environment Variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets)
368
+
369
+ **OpenRouter**
370
+
371
+ - [API Keys](https://openrouter.ai/keys)
372
+ - [Model Comparison](https://openrouter.ai/models)
373
+ - [Pricing](https://openrouter.ai/docs#models)
374
+
375
+ **Gradio**
376
+
377
+ - [Chat Interface](https://gradio.app/docs/chatinterface)
378
+ - [Components](https://gradio.app/docs/)
379
+ - [Sharing Apps](https://gradio.app/sharing-your-app/)
380
+
381
+ **Community Support**
382
+
383
+ - [HuggingFace Forums](https://discuss.huggingface.co/)
384
+ - [Gradio Discord](https://discord.gg/feTf9x3ZSB)
385
+
386
+ </details>