Spaces:
Running
Running
milwright
commited on
Commit
Β·
663172e
1
Parent(s):
a4b4814
update ui: change button emojis, reorganize docs with accordions, fix broken images
Browse files
app.py
CHANGED
@@ -252,20 +252,18 @@ class SpaceGenerator:
|
|
252 |
interactive=False # Make non-editable
|
253 |
)
|
254 |
|
255 |
-
# Instructions
|
256 |
with gr.Accordion("π Step-by-Step Instructions", open=False):
|
257 |
gr.Markdown(
|
258 |
-
"""
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
|
264 |
**Step 2: Access Variables and Secrets**
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-

|
269 |
|
270 |
**Step 3: Add Required Secrets**
|
271 |
|
@@ -274,15 +272,17 @@ class SpaceGenerator:
|
|
274 |
1. **API_KEY** - Your OpenRouter API key (required)
|
275 |
- Get your key at: https://openrouter.ai/keys
|
276 |
- Value should start with `sk-or-`
|
|
|
277 |
|
278 |
2. **HF_TOKEN** - Your HuggingFace token (optional)
|
279 |
- Enables automatic configuration updates
|
280 |
- Get your token at: https://huggingface.co/settings/tokens
|
281 |
-
-
|
282 |
|
283 |
3. **ACCESS_CODE** - Password protection (optional)
|
284 |
- Set any password to restrict access
|
285 |
-
-
|
|
|
286 |
"""
|
287 |
)
|
288 |
|
@@ -297,8 +297,8 @@ class SpaceGenerator:
|
|
297 |
|
298 |
# Action Buttons
|
299 |
with gr.Row():
|
300 |
-
preview_btn = gr.Button("
|
301 |
-
generate_btn = gr.Button("Generate Deployment Package", variant="primary")
|
302 |
|
303 |
# Output Section
|
304 |
with gr.Column(visible=False) as output_section:
|
@@ -802,7 +802,7 @@ class SpaceGenerator:
|
|
802 |
'preview_ready': True
|
803 |
}
|
804 |
|
805 |
-
gr.Info("Preview updated! Switch to the Preview tab to test your assistant.")
|
806 |
return config
|
807 |
|
808 |
def _generate_package(self, name, tagline, description, system_prompt, model,
|
@@ -940,48 +940,212 @@ huggingface-hub>=0.20.0"""
|
|
940 |
|
941 |
def _get_support_docs(self):
|
942 |
"""Get support documentation content"""
|
943 |
-
return """
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
958 |
- Try example prompts
|
|
|
959 |
- Export conversation history
|
960 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
961 |
|
962 |
-
### Step 3: Generate Deployment Package
|
963 |
Click **Generate Deployment Package** to create:
|
964 |
-
|
965 |
-
|
966 |
-
-
|
967 |
-
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
985 |
|
986 |
def _create_readme(self, title, tagline, description, model, api_key_var, access_code):
|
987 |
"""Create README.md content"""
|
|
|
252 |
interactive=False # Make non-editable
|
253 |
)
|
254 |
|
255 |
+
# Instructions without broken images
|
256 |
with gr.Accordion("π Step-by-Step Instructions", open=False):
|
257 |
gr.Markdown(
|
258 |
+
"""### How to Configure Secrets in HuggingFace Spaces
|
259 |
|
260 |
+
**Step 1: Navigate to Settings**
|
261 |
+
- Go to your HuggingFace Space
|
262 |
+
- Click on the βοΈ **Settings** tab at the top
|
263 |
|
264 |
**Step 2: Access Variables and Secrets**
|
265 |
+
- Scroll down to find **Variables and secrets** section
|
266 |
+
- Click on **New secret** button
|
|
|
|
|
267 |
|
268 |
**Step 3: Add Required Secrets**
|
269 |
|
|
|
272 |
1. **API_KEY** - Your OpenRouter API key (required)
|
273 |
- Get your key at: https://openrouter.ai/keys
|
274 |
- Value should start with `sk-or-`
|
275 |
+
- This enables AI responses
|
276 |
|
277 |
2. **HF_TOKEN** - Your HuggingFace token (optional)
|
278 |
- Enables automatic configuration updates
|
279 |
- Get your token at: https://huggingface.co/settings/tokens
|
280 |
+
- Select "write" permission when creating token
|
281 |
|
282 |
3. **ACCESS_CODE** - Password protection (optional)
|
283 |
- Set any password to restrict access
|
284 |
+
- Users will need this code to access your Space
|
285 |
+
- Leave empty for public access
|
286 |
"""
|
287 |
)
|
288 |
|
|
|
297 |
|
298 |
# Action Buttons
|
299 |
with gr.Row():
|
300 |
+
preview_btn = gr.Button("π¬ Preview Configuration", variant="secondary")
|
301 |
+
generate_btn = gr.Button("π³οΈ Generate Deployment Package", variant="primary")
|
302 |
|
303 |
# Output Section
|
304 |
with gr.Column(visible=False) as output_section:
|
|
|
802 |
'preview_ready': True
|
803 |
}
|
804 |
|
805 |
+
gr.Info("β
Preview updated! β¬οΈ Switch to the Preview tab to test your assistant.")
|
806 |
return config
|
807 |
|
808 |
def _generate_package(self, name, tagline, description, system_prompt, model,
|
|
|
940 |
|
941 |
def _get_support_docs(self):
|
942 |
"""Get support documentation content"""
|
943 |
+
return """# ChatUI Helper Documentation
|
944 |
+
|
945 |
+
Welcome to ChatUI Helper! This tool helps you create customizable AI chat interfaces for deployment on HuggingFace Spaces.
|
946 |
+
|
947 |
+
<details open>
|
948 |
+
<summary><h2>π Quick Start Guide</h2></summary>
|
949 |
+
|
950 |
+
1. **Configure** your assistant using templates or custom settings
|
951 |
+
2. **Preview** your configuration to test it works
|
952 |
+
3. **Generate** your deployment package
|
953 |
+
4. **Deploy** to HuggingFace Spaces
|
954 |
+
|
955 |
+
</details>
|
956 |
+
|
957 |
+
<details>
|
958 |
+
<summary><h2>π Step 1: Configure Your Space</h2></summary>
|
959 |
+
|
960 |
+
The **Configuration Tab** provides these sections:
|
961 |
+
|
962 |
+
### 1. Quick Start Templates
|
963 |
+
- Choose from pre-configured academic templates
|
964 |
+
- Or start with "None (Custom)" for full control
|
965 |
+
- Your custom values are preserved when switching templates
|
966 |
+
|
967 |
+
### 2. Space Identity
|
968 |
+
- **Assistant Name**: Your AI assistant's display name
|
969 |
+
- **Theme**: Choose from Default, Soft, Glass, Monochrome, or Base
|
970 |
+
- **Tagline**: Brief description (60 chars max) for the Space header
|
971 |
+
- **Description**: Full markdown description for the README
|
972 |
+
|
973 |
+
### 3. System Configuration
|
974 |
+
- **System Prompt**: Define your assistant's behavior and knowledge
|
975 |
+
- **Model**: Select from available OpenRouter models
|
976 |
+
- **Temperature**: Control response creativity (0-2)
|
977 |
+
- **Max Tokens**: Set response length limit (50-4096)
|
978 |
+
|
979 |
+
### 4. Example Prompts
|
980 |
+
- Add 3-5 sample prompts that showcase capabilities
|
981 |
+
- These appear as quick-start buttons for users
|
982 |
+
- Use the β/β buttons to add/remove examples
|
983 |
+
|
984 |
+
### 5. URL Grounding
|
985 |
+
- Add reference URLs for context (up to 10)
|
986 |
+
- First 2 URLs are primary sources (always loaded)
|
987 |
+
- Additional URLs are secondary references
|
988 |
+
- Content is fetched and provided as context
|
989 |
+
|
990 |
+
### 6. API Configuration
|
991 |
+
- **API_KEY**: Required OpenRouter API key variable
|
992 |
+
- **HF_TOKEN**: Optional for auto-configuration updates
|
993 |
+
- **ACCESS_CODE**: Optional password protection
|
994 |
+
|
995 |
+
### 7. Upload Configuration
|
996 |
+
- Import existing config.json files
|
997 |
+
- Quickly restore previous configurations
|
998 |
+
|
999 |
+
</details>
|
1000 |
+
|
1001 |
+
<details>
|
1002 |
+
<summary><h2>π¬ Step 2: Preview Your Assistant</h2></summary>
|
1003 |
+
|
1004 |
+
The **Preview Tab** allows you to:
|
1005 |
+
|
1006 |
+
### Test Configuration
|
1007 |
+
- Sends real API requests using your local API key
|
1008 |
+
- Uses the exact configuration from Step 1
|
1009 |
+
- Displays responses in the chat interface
|
1010 |
+
|
1011 |
+
### Features Available
|
1012 |
- Try example prompts
|
1013 |
+
- Upload files (if enabled)
|
1014 |
- Export conversation history
|
1015 |
+
- View active configuration
|
1016 |
+
|
1017 |
+
### API Key Setup
|
1018 |
+
- Set your OpenRouter API key as environment variable
|
1019 |
+
- Default variable name: `API_KEY`
|
1020 |
+
- Get your key at: https://openrouter.ai/keys
|
1021 |
+
|
1022 |
+
</details>
|
1023 |
+
|
1024 |
+
<details>
|
1025 |
+
<summary><h2>π³οΈ Step 3: Generate Deployment Package</h2></summary>
|
1026 |
|
|
|
1027 |
Click **Generate Deployment Package** to create:
|
1028 |
+
|
1029 |
+
### Package Contents
|
1030 |
+
- **app.py**: Complete Gradio application
|
1031 |
+
- **requirements.txt**: Python dependencies
|
1032 |
+
- **config.json**: Configuration backup
|
1033 |
+
- **README.md**: Deployment instructions
|
1034 |
+
|
1035 |
+
### Deployment Steps
|
1036 |
+
1. Download the generated ZIP file
|
1037 |
+
2. Create a new HuggingFace Space
|
1038 |
+
3. Upload all files from the package
|
1039 |
+
4. Configure secrets in Space settings
|
1040 |
+
|
1041 |
+
</details>
|
1042 |
+
|
1043 |
+
<details>
|
1044 |
+
<summary><h2>π HuggingFace Secrets Setup</h2></summary>
|
1045 |
+
|
1046 |
+
### Required Secret
|
1047 |
+
**API_KEY** (or your configured variable name)
|
1048 |
+
- Get from: https://openrouter.ai/keys
|
1049 |
+
- Must start with: `sk-or-`
|
1050 |
+
- Add in: Settings β Variables and secrets
|
1051 |
+
|
1052 |
+
### Optional Secrets
|
1053 |
+
**HF_TOKEN**
|
1054 |
+
- Enables automatic configuration updates
|
1055 |
+
- Get from: https://huggingface.co/settings/tokens
|
1056 |
+
- Needs write permissions
|
1057 |
+
|
1058 |
+
**ACCESS_CODE**
|
1059 |
+
- Password protects your Space
|
1060 |
+
- Set any password value
|
1061 |
+
- Share with authorized users only
|
1062 |
+
|
1063 |
+
### How to Add Secrets
|
1064 |
+
1. Go to your Space Settings (βοΈ icon)
|
1065 |
+
2. Find "Variables and secrets" section
|
1066 |
+
3. Click "New secret"
|
1067 |
+
4. Enter the variable name and value
|
1068 |
+
5. Save your changes
|
1069 |
+
|
1070 |
+
</details>
|
1071 |
+
|
1072 |
+
<details>
|
1073 |
+
<summary><h2>π¨ Template System</h2></summary>
|
1074 |
+
|
1075 |
+
### Available Templates
|
1076 |
+
- **STEM Adventure Games**: Interactive STEM learning
|
1077 |
+
- **Socratic Dialogue Partner**: Philosophical discussions
|
1078 |
+
- **Business Strategy Advisor**: Strategic planning assistant
|
1079 |
+
- **Creative Writing Coach**: Writing improvement helper
|
1080 |
+
- **Research Assistant**: Academic research support
|
1081 |
+
|
1082 |
+
### Template Features
|
1083 |
+
- Pre-configured prompts and examples
|
1084 |
+
- Optimized model settings
|
1085 |
+
- Relevant grounding URLs
|
1086 |
+
- Domain-specific system prompts
|
1087 |
+
|
1088 |
+
### Custom Values
|
1089 |
+
- Your custom settings are preserved
|
1090 |
+
- Switch templates without losing work
|
1091 |
+
- Return to "None (Custom)" to restore
|
1092 |
+
|
1093 |
+
</details>
|
1094 |
+
|
1095 |
+
<details>
|
1096 |
+
<summary><h2>π§ Troubleshooting</h2></summary>
|
1097 |
+
|
1098 |
+
### Common Issues
|
1099 |
+
|
1100 |
+
**Build Errors**
|
1101 |
+
- Check requirements.txt compatibility
|
1102 |
+
- Ensure Gradio version β₯ 5.39.0
|
1103 |
+
- Verify all dependencies are available
|
1104 |
+
|
1105 |
+
**API Errors**
|
1106 |
+
- Verify API_KEY is set correctly
|
1107 |
+
- Check API key starts with 'sk-or-'
|
1108 |
+
- Ensure you have API credits
|
1109 |
+
|
1110 |
+
**Access Issues**
|
1111 |
+
- ACCESS_CODE must match exactly
|
1112 |
+
- Check for extra spaces in password
|
1113 |
+
- Verify secret is properly saved
|
1114 |
+
|
1115 |
+
**Preview Not Working**
|
1116 |
+
- Set API_KEY in local environment
|
1117 |
+
- Check browser console for errors
|
1118 |
+
- Ensure configuration is saved
|
1119 |
+
|
1120 |
+
</details>
|
1121 |
+
|
1122 |
+
<details>
|
1123 |
+
<summary><h2>π‘ Tips & Best Practices</h2></summary>
|
1124 |
+
|
1125 |
+
### System Prompts
|
1126 |
+
- Be specific about capabilities
|
1127 |
+
- Include examples of desired behavior
|
1128 |
+
- Set clear boundaries and limitations
|
1129 |
+
|
1130 |
+
### Model Selection
|
1131 |
+
- Gemini Flash: Fast, cost-effective
|
1132 |
+
- Claude Sonnet: High quality reasoning
|
1133 |
+
- GPT-4: Broad knowledge base
|
1134 |
+
- Llama: Open source alternative
|
1135 |
+
|
1136 |
+
### URL Grounding
|
1137 |
+
- Use authoritative sources
|
1138 |
+
- Keep URLs up to date
|
1139 |
+
- Primary URLs load on every request
|
1140 |
+
- Secondary URLs provide additional context
|
1141 |
+
|
1142 |
+
### Security
|
1143 |
+
- Never commit API keys to code
|
1144 |
+
- Use environment variables only
|
1145 |
+
- Enable ACCESS_CODE for sensitive Spaces
|
1146 |
+
- Regularly rotate API keys
|
1147 |
+
|
1148 |
+
</details>"""
|
1149 |
|
1150 |
def _create_readme(self, title, tagline, description, model, api_key_var, access_code):
|
1151 |
"""Create README.md content"""
|