Spaces:
Running
Running
File size: 6,987 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 |
# UI Simplification Implementation Guide
## Overview
This guide shows how to simplify the configuration interface in app.py to make it less intimidating and more space-efficient.
## Key Improvements
### 1. Simplified Variable Names
Replace technical environment variable names with user-friendly alternatives:
```python
# Instead of:
api_key_var = gr.Textbox(
label="API Key Configuration (Required)",
value="OPENROUTER_API_KEY",
info="Set this secret in HuggingFace Space Settings..."
)
# Use:
api_key_var = gr.Textbox(
label="API Key Name",
value="MY_API_KEY",
info="You'll set this in HuggingFace later"
)
```
### 2. Compact Layout
Reduce vertical space usage:
```python
# Group related fields in rows
with gr.Row():
model = gr.Dropdown(
label="AI Model",
choices=[("Fast & Smart", "google/gemini-2.0-flash-001")],
scale=2
)
with gr.Column(scale=1):
temperature = gr.Slider(
label="Creativity",
minimum=0, maximum=2, value=0.7
)
```
### 3. Progressive Disclosure
Hide advanced options by default:
```python
# Essential fields visible
system_prompt = gr.Textbox(
label="Assistant Instructions",
placeholder="Tell your assistant how to behave...",
lines=3
)
# Advanced settings hidden
with gr.Accordion("βοΈ Advanced (Optional)", open=False):
# Less common settings here
```
### 4. Friendly Labels and Descriptions
**Before:**
- "System Prompt" β "Assistant Instructions"
- "Max Response Tokens" β "Response Length"
- "Temperature" β "Creativity Level"
- "Grounding URLs" β "Reference Materials"
- "Enable Dynamic URL Fetching" β "Let assistant read links from chat"
### 5. Visual Hierarchy
Use emojis and formatting to create clear sections:
```python
gr.Markdown("## π Quick Setup")
gr.Markdown("### β¨ Your Assistant")
gr.Markdown("### π Add Resources (Optional)")
```
## Implementation Steps
### Step 1: Update the Configuration Tab Layout
Replace the current configuration section (lines 1526-1732 in app.py) with:
```python
with gr.Tab("Configuration"):
gr.Markdown("# π Create Your AI Assistant")
gr.Markdown("Set up your custom assistant in just a few steps!")
with gr.Column():
# Simplified model selection
model = gr.Dropdown(
label="Choose Assistant Type",
choices=[
("Fast & Smart (Recommended)", "google/gemini-2.0-flash-001"),
("Advanced Analysis", "anthropic/claude-3.5-haiku"),
("Code Specialist", "mistralai/devstral-small")
],
value="google/gemini-2.0-flash-001"
)
# Main configuration card
with gr.Group():
gr.Markdown("### β¨ Configure Your Assistant")
# Template selector at top
template_selector = gr.Radio(
label="Start with a template or create custom",
choices=[
("Custom", "None"),
("Study Helper", "Research Template"),
("Teacher", "Socratic Template")
],
value="None",
type="value"
)
system_prompt = gr.Textbox(
label="How should your assistant behave?",
placeholder="Example: You are a friendly tutor who explains concepts clearly...",
lines=3
)
examples_text = gr.Textbox(
label="Starter Questions (one per line)",
placeholder="What can you help me with?\nExplain this concept",
lines=2
)
# Collapsible sections for optional features
with gr.Accordion("π Add Resources (Optional)", open=False):
url1 = gr.Textbox(
label="Main Reference",
placeholder="https://course-website.edu"
)
url2 = gr.Textbox(
label="Additional Reference",
placeholder="https://textbook.com"
)
enable_dynamic_urls = gr.Checkbox(
label="Let assistant read links from conversations",
value=True
)
with gr.Accordion("π Security (Optional)", open=False):
api_key_var = gr.Textbox(
label="API Key Name",
value="MY_API_KEY",
info="Simple name for your API key"
)
access_code = gr.Textbox(
label="Access Password Name",
value="SPACE_PASSWORD",
info="Only if you want a private space"
)
# Action buttons
with gr.Row():
preview_btn = gr.Button("ποΈ Preview", variant="secondary")
generate_btn = gr.Button("π Create Assistant", variant="primary", size="lg")
```
### Step 2: Add Mobile-Responsive CSS
Add this CSS to make the form work well on all screen sizes:
```css
/* Add to the CSS section */
.gradio-container {
max-width: 800px !important;
margin: 0 auto;
}
/* Compact spacing */
.form { gap: 0.75rem !important; }
/* Mobile responsive */
@media (max-width: 768px) {
.gradio-container { padding: 1rem !important; }
button { width: 100%; }
.gr-row { flex-direction: column !important; }
}
```
### Step 3: Simplify Success Messages
Update the success message (around line 1173):
```python
success_msg = f"""β
**Your assistant is ready!**
**Next steps:**
1. Download your package below
2. Create a new Space at [huggingface.co/spaces](https://huggingface.co/spaces)
3. Upload the files
4. Add your API key: `{api_key_var}` = your OpenRouter key
**That's it! Your assistant will be live in 2 minutes.**
"""
```
## Benefits
1. **Less Intimidating**: Friendly language and clear hierarchy
2. **Faster Setup**: Essential fields visible, advanced hidden
3. **Mobile Friendly**: Works on phones and tablets
4. **Clearer Purpose**: Users understand what each field does
5. **Progressive Disclosure**: Complexity revealed only when needed
## Testing the Simplified UI
1. **Desktop View**: Ensure all elements fit without scrolling
2. **Mobile View**: Test on phone-sized screens
3. **Tablet View**: Verify responsive layout
4. **Quick Setup**: Time how long it takes to fill out
5. **User Testing**: Get feedback from non-technical users
## Variable Name Mapping
For backward compatibility, map friendly names to technical ones:
```python
# In generate_zip function
var_mapping = {
"MY_API_KEY": "OPENROUTER_API_KEY",
"SPACE_PASSWORD": "SPACE_ACCESS_CODE",
"TEACHER_PASSWORD": "FACULTY_CONFIG_PASSWORD"
}
# Use the technical name in the generated code
actual_var = var_mapping.get(api_key_var, api_key_var)
```
This ensures the generated spaces still work correctly while presenting friendly names to users. |