milwright Claude commited on
Commit
f51b1f2
Β·
1 Parent(s): 28a389b

Update documentation with enhanced model information and system prompt templates

Browse files

- Add OpenRouter model links for easy access to model details
- Highlight google/gemma-3-27b-it as open-source sustainable option
- Add copy-pasteable system prompt templates for common use cases
- Include templated Q&A assistant with Psychology 101 example
- Streamline deployment section assuming users have API keys
- Add visual guide reference for HuggingFace secret configuration
- Update model comments in app.py for better clarity

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

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

Files changed (2) hide show
  1. app.py +21 -21
  2. support_docs.py +55 -46
app.py CHANGED
@@ -296,11 +296,11 @@ if __name__ == "__main__":
296
 
297
  # Available models
298
  MODELS = [
299
- "google/gemma-3-27b-it",
300
- "google/gemini-2.0-flash-001",
301
- "mistralai/mistral-medium",
302
- "openai/gpt-4o-nano",
303
- "anthropic/claude-3.5-haiku"
304
  ]
305
 
306
  def fetch_url_content(url):
@@ -1073,8 +1073,8 @@ def remove_chat_urls(count):
1073
  else:
1074
  return (gr.update(), gr.update(), gr.update(), gr.update(), count)
1075
 
1076
- def toggle_research_assistant(enable_research):
1077
- """Toggle visibility of research assistant detailed fields and disable custom categories"""
1078
  if enable_research:
1079
  combined_prompt = "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."
1080
  return (
@@ -1085,8 +1085,8 @@ def toggle_research_assistant(enable_research):
1085
  gr.update(value="Your main responsibilities include: analyzing academic sources, fact-checking claims with evidence, providing properly cited research summaries, and helping users navigate scholarly information."),
1086
  gr.update(value="Ground all responses in provided URL contexts and any additional URLs you're instructed to fetch. Never rely on memory for factual claims."),
1087
  gr.update(value=True), # Enable dynamic URL fetching for research template
1088
- gr.update(value=False), # Force disable custom categories checkbox
1089
- gr.update(visible=False) # Force hide custom categories fields
1090
  )
1091
  else:
1092
  return (
@@ -1097,8 +1097,8 @@ def toggle_research_assistant(enable_research):
1097
  gr.update(value=""),
1098
  gr.update(value=""),
1099
  gr.update(value=False), # Disable dynamic URL setting
1100
- gr.update(value=False), # Ensure custom categories stays disabled
1101
- gr.update(visible=False) # Ensure custom categories fields stay hidden
1102
  )
1103
 
1104
  def update_system_prompt_from_fields(role_purpose, intended_audience, key_tasks, additional_context):
@@ -1116,19 +1116,19 @@ def update_system_prompt_from_fields(role_purpose, intended_audience, key_tasks,
1116
  combined = " ".join(parts)
1117
  return gr.update(value=combined)
1118
 
1119
- def toggle_custom_categories(enable_custom):
1120
- """Toggle visibility of custom categories fields and disable research assistant"""
1121
  if enable_custom:
1122
  return (
1123
  gr.update(visible=True), # Show custom categories fields
1124
- gr.update(value=False), # Force disable research assistant checkbox
1125
- gr.update(visible=False) # Force hide research assistant fields
1126
  )
1127
  else:
1128
  return (
1129
  gr.update(visible=False), # Hide custom categories fields
1130
- gr.update(value=False), # Ensure research assistant stays disabled
1131
- gr.update(visible=False) # Ensure research assistant fields stay hidden
1132
  )
1133
 
1134
  # Create Gradio interface with proper tab structure
@@ -1382,15 +1382,15 @@ with gr.Blocks(title="Chat U/I Helper") as demo:
1382
  # Connect the research assistant checkbox
1383
  enable_research_assistant.change(
1384
  toggle_research_assistant,
1385
- inputs=[enable_research_assistant],
1386
- outputs=[research_detailed_fields, system_prompt, role_purpose, intended_audience, key_tasks, additional_context, enable_dynamic_urls, enable_custom_categories, custom_categories_fields]
1387
  )
1388
 
1389
  # Connect the custom categories checkbox
1390
  enable_custom_categories.change(
1391
  toggle_custom_categories,
1392
- inputs=[enable_custom_categories],
1393
- outputs=[custom_categories_fields, enable_research_assistant, research_detailed_fields]
1394
  )
1395
 
1396
  # Connect research assistant fields to update main system prompt
 
296
 
297
  # Available models
298
  MODELS = [
299
+ "google/gemma-3-27b-it", # Open-source, sustainable option
300
+ "google/gemini-2.0-flash-001", # Fast, reliable, general tasks
301
+ "mistralai/mistral-medium", # Good for technical topics
302
+ "openai/gpt-4o-nano", # Balanced performance and cost
303
+ "anthropic/claude-3.5-haiku" # Complex reasoning and analysis
304
  ]
305
 
306
  def fetch_url_content(url):
 
1073
  else:
1074
  return (gr.update(), gr.update(), gr.update(), gr.update(), count)
1075
 
1076
+ def toggle_research_assistant(enable_research, current_custom_enabled):
1077
+ """Toggle visibility of research assistant detailed fields"""
1078
  if enable_research:
1079
  combined_prompt = "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."
1080
  return (
 
1085
  gr.update(value="Your main responsibilities include: analyzing academic sources, fact-checking claims with evidence, providing properly cited research summaries, and helping users navigate scholarly information."),
1086
  gr.update(value="Ground all responses in provided URL contexts and any additional URLs you're instructed to fetch. Never rely on memory for factual claims."),
1087
  gr.update(value=True), # Enable dynamic URL fetching for research template
1088
+ gr.update(visible=False), # Hide custom categories fields
1089
+ gr.update(value=False) # Disable custom categories checkbox
1090
  )
1091
  else:
1092
  return (
 
1097
  gr.update(value=""),
1098
  gr.update(value=""),
1099
  gr.update(value=False), # Disable dynamic URL setting
1100
+ gr.update(visible=not current_custom_enabled), # Show custom fields if custom was enabled
1101
+ gr.update() # Keep custom categories checkbox as is
1102
  )
1103
 
1104
  def update_system_prompt_from_fields(role_purpose, intended_audience, key_tasks, additional_context):
 
1116
  combined = " ".join(parts)
1117
  return gr.update(value=combined)
1118
 
1119
+ def toggle_custom_categories(enable_custom, current_research_enabled):
1120
+ """Toggle visibility of custom categories fields"""
1121
  if enable_custom:
1122
  return (
1123
  gr.update(visible=True), # Show custom categories fields
1124
+ gr.update(visible=False), # Hide research assistant fields
1125
+ gr.update(value=False) # Disable research assistant checkbox
1126
  )
1127
  else:
1128
  return (
1129
  gr.update(visible=False), # Hide custom categories fields
1130
+ gr.update(visible=not current_research_enabled), # Show research fields if research was enabled
1131
+ gr.update() # Keep research assistant checkbox as is
1132
  )
1133
 
1134
  # Create Gradio interface with proper tab structure
 
1382
  # Connect the research assistant checkbox
1383
  enable_research_assistant.change(
1384
  toggle_research_assistant,
1385
+ inputs=[enable_research_assistant, enable_custom_categories],
1386
+ outputs=[research_detailed_fields, system_prompt, role_purpose, intended_audience, key_tasks, additional_context, enable_dynamic_urls, custom_categories_fields, enable_custom_categories]
1387
  )
1388
 
1389
  # Connect the custom categories checkbox
1390
  enable_custom_categories.change(
1391
  toggle_custom_categories,
1392
+ inputs=[enable_custom_categories, enable_research_assistant],
1393
+ outputs=[custom_categories_fields, research_detailed_fields, enable_research_assistant]
1394
  )
1395
 
1396
  # Connect research assistant fields to update main system prompt
support_docs.py CHANGED
@@ -40,10 +40,11 @@ def create_support_docs():
40
  - Will appear in the HuggingFace Space listing and at the top of your chat
41
 
42
  **Model Selection**
43
- - **google/gemini-2.0-flash-001**: Fast, reliable, good for general tasks
44
- - **anthropic/claude-3.5-haiku**: Great for complex reasoning and analysis
45
- - **openai/gpt-4o-nano**: Balanced performance and cost
46
- - **mistralai/mistral-medium**: Good for technical topics
 
47
 
48
  **API Key Variable Name**
49
  - Default: `OPENROUTER_API_KEY`
@@ -81,13 +82,36 @@ def create_support_docs():
81
  - **Key Tasks**: What specific capabilities should it have?
82
  - **Additional Context**: Extra instructions or constraints
83
 
84
- **Example System Prompts:**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  ```
86
- Biology Course Assistant:
87
- "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."
88
 
89
- Research Writing Helper:
90
- "You are a research writing assistant. Help students with citation formatting, argument structure, and source analysis. Focus on academic writing standards and proper documentation."
 
 
 
 
 
 
91
  ```
92
  """)
93
 
@@ -190,43 +214,28 @@ def create_support_docs():
190
 
191
  with gr.Accordion("πŸš€ Deployment Process", open=False):
192
  gr.Markdown("""
193
- ### Step-by-Step Deployment
194
-
195
- **1. Generate Package**
196
- - Click "Generate Deployment Package" in the Configuration tab
197
- - Download the zip file when ready
198
- - Contains: app.py, requirements.txt, README.md, config.json
199
-
200
- **2. Create HuggingFace Space**
201
- - Go to [huggingface.co/spaces](https://huggingface.co/spaces)
202
- - Click "Create new Space"
203
- - Choose a name and set to Public or Private
204
- - **Important**: Select "Gradio" as the SDK
205
- - Click "Create Space"
206
-
207
- **3. Upload Files**
208
- - In your new Space, click the "Files" tab
209
- - Upload `app.py` and `requirements.txt` from your zip
210
- - Wait for the "Building" status to complete
211
-
212
- **4. Add API Key**
213
- - Go to Settings (gear icon) β†’ "Variables and secrets"
214
- - Click "New secret"
215
- - Name: Your API key variable name (usually `OPENROUTER_API_KEY`)
216
- - Value: Your OpenRouter API key (get from openrouter.ai/keys)
217
- - Click "Add"
218
-
219
- **5. Configure Access (Optional)**
220
- - If you set an access code, add another secret:
221
- - Name: `SPACE_ACCESS_CODE`
222
- - Value: Your chosen access code
223
- - Students will need this code to use the assistant
224
-
225
- **6. Test and Share**
226
- - Go back to "App" tab
227
- - Your Space should be running!
228
- - Test with example prompts
229
- - Share the Space URL with students
230
  """)
231
 
232
  with gr.Accordion("πŸ”§ Troubleshooting", open=False):
 
40
  - Will appear in the HuggingFace Space listing and at the top of your chat
41
 
42
  **Model Selection**
43
+ - **[google/gemma-3-27b-it](https://openrouter.ai/models/google/gemma-3-27b-it)**: Open-source, sustainable option with excellent performance
44
+ - **[google/gemini-2.0-flash-001](https://openrouter.ai/models/google/gemini-2.0-flash-001)**: Fast, reliable, good for general tasks
45
+ - **[mistralai/mistral-medium](https://openrouter.ai/models/mistralai/mistral-medium)**: Good for technical topics
46
+ - **[openai/gpt-4o-nano](https://openrouter.ai/models/openai/gpt-4o-nano)**: Balanced performance and cost
47
+ - **[anthropic/claude-3.5-haiku](https://openrouter.ai/models/anthropic/claude-3.5-haiku)**: Great for complex reasoning and analysis
48
 
49
  **API Key Variable Name**
50
  - Default: `OPENROUTER_API_KEY`
 
82
  - **Key Tasks**: What specific capabilities should it have?
83
  - **Additional Context**: Extra instructions or constraints
84
 
85
+ ### Copy-Pasteable System Prompts
86
+
87
+ **Biology Course Assistant:**
88
+ ```
89
+ 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.
90
+ ```
91
+
92
+ **Research Writing Helper:**
93
+ ```
94
+ 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.
95
+ ```
96
+
97
+ **Course Q&A Assistant (Template):**
98
+ ```
99
+ 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.
100
+ ```
101
+
102
+ **Psychology 101 Example:**
103
+ ```
104
+ 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.
105
  ```
 
 
106
 
107
+ **Technical Support Helper:**
108
+ ```
109
+ 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.
110
+ ```
111
+
112
+ **Research Assistant (Pre-configured Template):**
113
+ ```
114
+ 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.
115
  ```
116
  """)
117
 
 
214
 
215
  with gr.Accordion("πŸš€ Deployment Process", open=False):
216
  gr.Markdown("""
217
+ ### Quick Deployment Guide
218
+
219
+ **1. Generate & Upload**
220
+ - Click "Generate Deployment Package" β†’ download zip
221
+ - Create new Space at [huggingface.co/spaces](https://huggingface.co/spaces) (select **Gradio** SDK)
222
+ - Upload `app.py` and `requirements.txt` from zip to Files tab
223
+
224
+ **2. Add Your OpenRouter API Key**
225
+ Since you already have an OpenRouter API key, add it as a secret:
226
+ - Go to Settings β†’ Variables and secrets β†’ New secret
227
+ - Use the interface shown below to add your key:
228
+
229
+ ![HuggingFace Secret Configuration](./secret.png)
230
+
231
+ **3. Optional: Add Access Code**
232
+ If you configured student access protection:
233
+ - Add another secret: Name = `SPACE_ACCESS_CODE`, Value = your chosen code
234
+
235
+ **4. Deploy & Share**
236
+ - Wait for build completion β†’ test in App tab β†’ share URL with students
237
+
238
+ **That's it!** Your Space will be live and ready for use.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  """)
240
 
241
  with gr.Accordion("πŸ”§ Troubleshooting", open=False):