pikamomo Claude Sonnet 4.6 commited on
Commit
082a8c7
·
1 Parent(s): d77e9cc

Add configurable UI settings (colors, font, avatar) to config and admin panel

Browse files
Files changed (4) hide show
  1. admin.py +63 -1
  2. app.py +14 -3
  3. config/chatbot_settings.json +5 -1
  4. src/config.py +4 -0
admin.py CHANGED
@@ -10,6 +10,7 @@ from dotenv import load_dotenv
10
  from qdrant_client import QdrantClient, models
11
  from src.ingestion import ingest_document
12
  from src.scraper import process_and_store_webpage
 
13
 
14
  load_dotenv()
15
 
@@ -271,6 +272,35 @@ def delete_document(source_name):
271
  return f"❌ Deletion failed:\n{str(e)}"
272
 
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  # ==================== Gradio Interface (5.49) ====================
275
 
276
  with gr.Blocks(
@@ -376,7 +406,39 @@ with gr.Blocks(
376
  outputs=delete_output
377
  )
378
 
379
- # Tab 5: Help
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  with gr.Tab("ℹ️ Help"):
381
  gr.Markdown("""
382
  ### Usage Guide
 
10
  from qdrant_client import QdrantClient, models
11
  from src.ingestion import ingest_document
12
  from src.scraper import process_and_store_webpage
13
+ from src.config import load_settings, save_settings
14
 
15
  load_dotenv()
16
 
 
272
  return f"❌ Deletion failed:\n{str(e)}"
273
 
274
 
275
+ def get_current_settings():
276
+ """Load current settings and return as individual values for the UI."""
277
+ s = load_settings()
278
+ return (
279
+ s["disclaimer"],
280
+ s["welcome_message"],
281
+ s["bot_avatar_url"],
282
+ s["primary_color"],
283
+ s["secondary_color"],
284
+ s["font_family"],
285
+ )
286
+
287
+
288
+ def save_chatbot_settings(disclaimer, welcome_message, bot_avatar_url, primary_color, secondary_color, font_family):
289
+ """Save chatbot settings to config file."""
290
+ try:
291
+ s = load_settings()
292
+ s["disclaimer"] = disclaimer
293
+ s["welcome_message"] = welcome_message
294
+ s["bot_avatar_url"] = bot_avatar_url
295
+ s["primary_color"] = primary_color
296
+ s["secondary_color"] = secondary_color
297
+ s["font_family"] = font_family
298
+ save_settings(s)
299
+ return "✅ Settings saved! Restart the chatbot space for changes to take effect."
300
+ except Exception as e:
301
+ return f"❌ Failed to save: {str(e)}"
302
+
303
+
304
  # ==================== Gradio Interface (5.49) ====================
305
 
306
  with gr.Blocks(
 
406
  outputs=delete_output
407
  )
408
 
409
+ # Tab 5: Chatbot Settings
410
+ with gr.Tab("⚙️ Chatbot Settings"):
411
+ gr.Markdown("### Chatbot Appearance & Text Settings")
412
+ gr.Markdown("Changes take effect after the chatbot space restarts.")
413
+
414
+ with gr.Row():
415
+ with gr.Column():
416
+ setting_primary_color = gr.ColorPicker(label="Primary Color (buttons, links)")
417
+ setting_secondary_color = gr.ColorPicker(label="Secondary Color (background)")
418
+ setting_font = gr.Textbox(label="Font Family", placeholder="Arial, sans-serif")
419
+ setting_avatar = gr.Textbox(label="Bot Avatar Image URL", placeholder="https://...")
420
+
421
+ with gr.Column():
422
+ setting_disclaimer = gr.Textbox(label="Disclaimer Text (Markdown)", lines=6)
423
+ setting_welcome = gr.Textbox(label="Welcome Message (Markdown)", lines=8)
424
+
425
+ save_settings_btn = gr.Button("💾 Save Settings", variant="primary", size="lg")
426
+ settings_output = gr.Textbox(label="Result", lines=2)
427
+
428
+ save_settings_btn.click(
429
+ save_chatbot_settings,
430
+ inputs=[setting_disclaimer, setting_welcome, setting_avatar,
431
+ setting_primary_color, setting_secondary_color, setting_font],
432
+ outputs=settings_output
433
+ )
434
+
435
+ demo.load(
436
+ get_current_settings,
437
+ outputs=[setting_disclaimer, setting_welcome, setting_avatar,
438
+ setting_primary_color, setting_secondary_color, setting_font]
439
+ )
440
+
441
+ # Tab 6: Help
442
  with gr.Tab("ℹ️ Help"):
443
  gr.Markdown("""
444
  ### Usage Guide
app.py CHANGED
@@ -121,11 +121,22 @@ def chat_response(message: str, history: list, session_id: str, request: gr.Requ
121
  _settings = load_settings()
122
  DISCLAIMER_TEXT = _settings["disclaimer"]
123
  WELCOME_MESSAGE = _settings["welcome_message"]
 
 
 
 
 
 
 
 
 
 
124
 
125
  # Create Gradio interface (Gradio 5.49 API)
126
  with gr.Blocks(
127
- title="HR Intervals AI Assistant",
128
- theme=gr.themes.Soft()
 
129
  ) as demo:
130
 
131
  gr.Markdown("""
@@ -149,7 +160,7 @@ with gr.Blocks(
149
  height=500,
150
  show_label=False,
151
  type='messages',
152
- avatar_images=(None, "https://em-content.zobj.net/thumbs/120/apple/354/robot_1f916.png"),
153
  value=[{"role": "assistant", "content": WELCOME_MESSAGE}]
154
  ),
155
  textbox=gr.Textbox(
 
121
  _settings = load_settings()
122
  DISCLAIMER_TEXT = _settings["disclaimer"]
123
  WELCOME_MESSAGE = _settings["welcome_message"]
124
+ BOT_AVATAR_URL = _settings["bot_avatar_url"]
125
+ PRIMARY_COLOR = _settings["primary_color"]
126
+ SECONDARY_COLOR = _settings["secondary_color"]
127
+ FONT_FAMILY = _settings["font_family"]
128
+
129
+ _custom_css = f"""
130
+ * {{ font-family: {FONT_FAMILY} !important; }}
131
+ .gradio-container button.primary {{ background-color: {PRIMARY_COLOR} !important; border-color: {PRIMARY_COLOR} !important; }}
132
+ .gradio-container {{ background-color: {SECONDARY_COLOR} !important; }}
133
+ """
134
 
135
  # Create Gradio interface (Gradio 5.49 API)
136
  with gr.Blocks(
137
+ title="HR Intervals AI Assistant",
138
+ theme=gr.themes.Soft(),
139
+ css=_custom_css
140
  ) as demo:
141
 
142
  gr.Markdown("""
 
160
  height=500,
161
  show_label=False,
162
  type='messages',
163
+ avatar_images=(None, BOT_AVATAR_URL),
164
  value=[{"role": "assistant", "content": WELCOME_MESSAGE}]
165
  ),
166
  textbox=gr.Textbox(
config/chatbot_settings.json CHANGED
@@ -1,4 +1,8 @@
1
  {
2
  "disclaimer": "**This tool is designed to provide general HR-related information and draft policy suggestions.**\n\n- This is **NOT** a substitute for professional legal or HR advice\n- For legal compliance and important decisions, consult a qualified attorney or HR professional\n- Do **NOT** share personal information about specific individuals\n\nBy using this tool, you acknowledge that you understand these limitations.",
3
- "welcome_message": "👋 **Welcome to the HR Intervals AI Assistant!**\n\n⚠️ **Important Disclaimer:**\n\nThis tool is designed to provide general HR-related information and draft policy suggestions. It is not a substitute for professional legal or HR advice. For legal compliance and to ensure the best outcome for your organization, we recommend consulting a qualified attorney or HR professional before implementing any policies or making decisions based on the information provided.\n\n---\n\nHow can I help you today? **Try asking:**\n\n• What should I include in a remote work policy?\n• How do I handle employee terminations properly?\n• What are best practices for hiring in Canada?\n• Tell me about workplace safety requirements"
 
 
 
 
4
  }
 
1
  {
2
  "disclaimer": "**This tool is designed to provide general HR-related information and draft policy suggestions.**\n\n- This is **NOT** a substitute for professional legal or HR advice\n- For legal compliance and important decisions, consult a qualified attorney or HR professional\n- Do **NOT** share personal information about specific individuals\n\nBy using this tool, you acknowledge that you understand these limitations.",
3
+ "welcome_message": "👋 **Welcome to the HR Intervals AI Assistant!**\n\n⚠️ **Important Disclaimer:**\n\nThis tool is designed to provide general HR-related information and draft policy suggestions. It is not a substitute for professional legal or HR advice. For legal compliance and to ensure the best outcome for your organization, we recommend consulting a qualified attorney or HR professional before implementing any policies or making decisions based on the information provided.\n\n---\n\nHow can I help you today? **Try asking:**\n\n• What should I include in a remote work policy?\n• How do I handle employee terminations properly?\n• What are best practices for hiring in Canada?\n• Tell me about workplace safety requirements",
4
+ "bot_avatar_url": "https://em-content.zobj.net/thumbs/120/apple/354/robot_1f916.png",
5
+ "primary_color": "#0066cc",
6
+ "secondary_color": "#f0f4f8",
7
+ "font_family": "Arial, sans-serif"
8
  }
src/config.py CHANGED
@@ -36,6 +36,10 @@ _DEFAULTS = {
36
  "• What are best practices for hiring in Canada?\n"
37
  "• Tell me about workplace safety requirements"
38
  ),
 
 
 
 
39
  }
40
 
41
 
 
36
  "• What are best practices for hiring in Canada?\n"
37
  "• Tell me about workplace safety requirements"
38
  ),
39
+ "bot_avatar_url": "https://em-content.zobj.net/thumbs/120/apple/354/robot_1f916.png",
40
+ "primary_color": "#0066cc",
41
+ "secondary_color": "#f0f4f8",
42
+ "font_family": "Arial, sans-serif",
43
  }
44
 
45