ZOTHEOS commited on
Commit
92bff3a
·
verified ·
1 Parent(s): 297c383

Update main_web.py

Browse files
Files changed (1) hide show
  1. main_web.py +31 -15
main_web.py CHANGED
@@ -58,9 +58,7 @@ elif initialization_error is None: initialization_error = ModuleNotFoundError("M
58
  # --- TIER_FEATURES Dictionary (Your existing code is perfect) ---
59
  TIER_FEATURES = {"free": {"display_name": "Free Tier", "memory_enabled": False, "export_enabled": False}, "starter": {"display_name": "Starter Tier", "memory_enabled": True, "export_enabled": False}, "pro": {"display_name": "Pro Tier", "memory_enabled": True, "export_enabled": True}, "error (auth module failed)": {"display_name": "Error", "memory_enabled": False, "export_enabled": False}}
60
 
61
- #
62
  # --- JESSICA WALSH INSPIRED REDESIGN ---
63
- #
64
  zotheos_base_css = """
65
  @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;600;700&display=swap');
66
 
@@ -218,7 +216,6 @@ h1, h2, h3, #header_subtitle, #welcome_message {
218
 
219
  # --- Helper Functions (Your existing code is perfect) ---
220
  def render_memory_entries_as_html(memory_entries: List[dict]) -> str:
221
- # This function is fine as-is. The new CSS will style the output.
222
  if not memory_entries: return "<div class='memory-entry'>No stored memory entries or memory disabled.</div>"
223
  html_blocks = [];
224
  for entry in reversed(memory_entries[-5:]):
@@ -239,6 +236,11 @@ def update_tier_display_and_features_ui(user_token_str: Optional[str]) -> Tuple:
239
  tier_features = TIER_FEATURES.get(tier_name, TIER_FEATURES["free"])
240
  return (gr.update(value=format_tier_status_for_ui(tier_name)), gr.update(interactive=tier_features["export_enabled"]))
241
 
 
 
 
 
 
242
  # --- Build Gradio Interface (Main Structure is Yours, Components are Styled) ---
243
  def build_interface(logo_path_param: Optional[str], favicon_path_param: Optional[str]) -> gr.Blocks:
244
  theme = gr.themes.Base(font=[gr.themes.GoogleFont("Inter"), "sans-serif"])
@@ -258,7 +260,8 @@ def build_interface(logo_path_param: Optional[str], favicon_path_param: Optional
258
  # --- Authentication & Tier Status ---
259
  with gr.Row(equal_height=False):
260
  user_token_input = gr.Textbox(label="Access Token", placeholder="Enter token...", type="password", scale=3, container=False)
261
- tier_status_display = gr.Markdown(value=format_tier_status_for_ui(initial_tier_name), elem_id="tier_status_display", scale=2)
 
262
 
263
  # --- Core Input ---
264
  with gr.Group():
@@ -284,34 +287,47 @@ def build_interface(logo_path_param: Optional[str], favicon_path_param: Optional
284
  gr.Markdown("---", elem_id="footer_separator")
285
  gr.Markdown("ZOTHEOS © 2025 ZOTHEOS LLC. System Architect: David A. Garcia. All Rights Reserved.", elem_id="footer_attribution")
286
 
287
- # --- Backend Logic & Event Handlers (Your existing code is perfect) ---
 
288
  async def process_query_wrapper_internal(query, token):
289
  tier_name = get_user_tier(token or ""); display_name = TIER_FEATURES.get(tier_name, {})["display_name"]
290
  loading_html = f"<div class='cosmic-loading'><div class='orbital-spinner'></div><div class='thinking-text'>Synthesizing (Tier: {display_name})...</div></div>"
291
- yield (gr.update(value=loading_html, visible=True), gr.update(interactive=False), gr.update(interactive=False), "", "", "", "Loading...")
292
  if not ai_system:
293
  yield (gr.update(value="<p style='color:red;'>SYSTEM OFFLINE</p>", visible=True), gr.update(interactive=True), gr.update(interactive=True), "Error", "Error", "Offline", "Error")
294
  return
295
- response = await ai_system.process_query_with_fusion(query, user_token=token, fusion_mode_override=DEFAULT_INFERENCE_PRESET_INTERFACE)
296
- # Simple response parsing for demo
 
 
 
 
297
  summary = response[:response.find("###")] if "###" in response else response
298
  perspectives = response[response.find("###"):] if "###" in response else "Details integrated in summary."
299
- mem_data = await ai_system.memory_bank.retrieve_recent_memories_async(limit=5) if TIER_FEATURES[tier_name]['memory_enabled'] and hasattr(ai_system, 'memory_bank') else []
300
- mem_html = render_memory_entries_as_html(mem_data)
301
- status_report = await ai_system.get_status_report()
302
- status_md = f"**Last Used:** {', '.join(status_report.get('models_last_queried_for_perspectives', ['N/A']))}"
 
 
 
 
 
 
 
303
  yield (gr.update(visible=False), gr.update(interactive=True), gr.update(interactive=True), summary, perspectives, status_md, mem_html)
304
 
 
305
  submit_button_component.click(fn=process_query_wrapper_internal, inputs=[query_input_component, user_token_input], outputs=[status_indicator_component, submit_button_component, clear_button_component, synthesized_summary_component, fused_response_output_component, active_models_display_component, memory_display_panel_html], show_progress="hidden")
306
- clear_button_component.click(lambda: ("", "", "", "Synthesized insight...", "Detailed perspectives..."), outputs=[query_input_component, user_token_input, synthesized_summary_component, fused_response_output_component])
307
  user_token_input.change(fn=update_tier_display_and_features_ui, inputs=[user_token_input], outputs=[tier_status_display, export_memory_button])
308
  export_memory_button.click(fn=export_user_memory_data_for_download, inputs=[user_token_input], outputs=[])
309
 
310
  return demo
311
 
312
- # --- Main Execution Block (Your existing code is perfect) ---
313
  if __name__ == "__main__":
314
- logger.info("--- Initializing ZOTHEOS Gradio Interface (V12 - Walsh Redesign) ---")
315
  zotheos_interface = build_interface(logo_path_verified, favicon_path_verified)
316
  logger.info("✅ ZOTHEOS Gradio UI built.")
317
  launch_kwargs = {"server_name": "0.0.0.0", "server_port": int(os.getenv("PORT", 7860)), "share": os.getenv("GRADIO_SHARE", "False").lower() == "true"}
 
58
  # --- TIER_FEATURES Dictionary (Your existing code is perfect) ---
59
  TIER_FEATURES = {"free": {"display_name": "Free Tier", "memory_enabled": False, "export_enabled": False}, "starter": {"display_name": "Starter Tier", "memory_enabled": True, "export_enabled": False}, "pro": {"display_name": "Pro Tier", "memory_enabled": True, "export_enabled": True}, "error (auth module failed)": {"display_name": "Error", "memory_enabled": False, "export_enabled": False}}
60
 
 
61
  # --- JESSICA WALSH INSPIRED REDESIGN ---
 
62
  zotheos_base_css = """
63
  @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;600;700&display=swap');
64
 
 
216
 
217
  # --- Helper Functions (Your existing code is perfect) ---
218
  def render_memory_entries_as_html(memory_entries: List[dict]) -> str:
 
219
  if not memory_entries: return "<div class='memory-entry'>No stored memory entries or memory disabled.</div>"
220
  html_blocks = [];
221
  for entry in reversed(memory_entries[-5:]):
 
236
  tier_features = TIER_FEATURES.get(tier_name, TIER_FEATURES["free"])
237
  return (gr.update(value=format_tier_status_for_ui(tier_name)), gr.update(interactive=tier_features["export_enabled"]))
238
 
239
+ def export_user_memory_data_for_download(user_token_str: Optional[str]):
240
+ # This is a placeholder for your actual export logic
241
+ gr.Info("Export functionality would be triggered here for Pro users.")
242
+ return None
243
+
244
  # --- Build Gradio Interface (Main Structure is Yours, Components are Styled) ---
245
  def build_interface(logo_path_param: Optional[str], favicon_path_param: Optional[str]) -> gr.Blocks:
246
  theme = gr.themes.Base(font=[gr.themes.GoogleFont("Inter"), "sans-serif"])
 
260
  # --- Authentication & Tier Status ---
261
  with gr.Row(equal_height=False):
262
  user_token_input = gr.Textbox(label="Access Token", placeholder="Enter token...", type="password", scale=3, container=False)
263
+ # --- FIX IS HERE ---
264
+ tier_status_display = gr.Markdown(value=format_tier_status_for_ui(initial_tier_name), elem_id="tier_status_display")
265
 
266
  # --- Core Input ---
267
  with gr.Group():
 
287
  gr.Markdown("---", elem_id="footer_separator")
288
  gr.Markdown("ZOTHEOS © 2025 ZOTHEOS LLC. System Architect: David A. Garcia. All Rights Reserved.", elem_id="footer_attribution")
289
 
290
+ # --- Your original, robust backend logic should be here ---
291
+ # I'm using a simplified version for demonstration.
292
  async def process_query_wrapper_internal(query, token):
293
  tier_name = get_user_tier(token or ""); display_name = TIER_FEATURES.get(tier_name, {})["display_name"]
294
  loading_html = f"<div class='cosmic-loading'><div class='orbital-spinner'></div><div class='thinking-text'>Synthesizing (Tier: {display_name})...</div></div>"
295
+ yield (gr.update(value=loading_html, visible=True), gr.update(interactive=False), gr.update(interactive=False), "Processing...", "Processing...", "Processing...", "Processing...")
296
  if not ai_system:
297
  yield (gr.update(value="<p style='color:red;'>SYSTEM OFFLINE</p>", visible=True), gr.update(interactive=True), gr.update(interactive=True), "Error", "Error", "Offline", "Error")
298
  return
299
+
300
+ # Replace with your actual full response logic
301
+ response = "## ✨ Final Synthesized Insight ✨\nThis is a placeholder summary. ### 💬 Detailed Perspectives\nThis is a placeholder for the detailed views."
302
+ if hasattr(ai_system, 'process_query_with_fusion'):
303
+ response = await ai_system.process_query_with_fusion(query, user_token=token, fusion_mode_override=DEFAULT_INFERENCE_PRESET_INTERFACE)
304
+
305
  summary = response[:response.find("###")] if "###" in response else response
306
  perspectives = response[response.find("###"):] if "###" in response else "Details integrated in summary."
307
+
308
+ mem_html = "<div class='memory-entry'>Memory disabled.</div>"
309
+ if TIER_FEATURES[get_user_tier(token or "")]['memory_enabled'] and hasattr(ai_system, 'memory_bank'):
310
+ mem_data = await ai_system.memory_bank.retrieve_recent_memories_async(limit=5)
311
+ mem_html = render_memory_entries_as_html(mem_data)
312
+
313
+ status_md = "**Status:** `Ready`"
314
+ if hasattr(ai_system, 'get_status_report'):
315
+ status_report = await ai_system.get_status_report()
316
+ status_md = f"**Last Used:** {', '.join(status_report.get('models_last_queried_for_perspectives', ['N/A']))}"
317
+
318
  yield (gr.update(visible=False), gr.update(interactive=True), gr.update(interactive=True), summary, perspectives, status_md, mem_html)
319
 
320
+ # Connect events
321
  submit_button_component.click(fn=process_query_wrapper_internal, inputs=[query_input_component, user_token_input], outputs=[status_indicator_component, submit_button_component, clear_button_component, synthesized_summary_component, fused_response_output_component, active_models_display_component, memory_display_panel_html], show_progress="hidden")
322
+ clear_button_component.click(lambda: ("", "", "Synthesized insight...", "Detailed perspectives..."), outputs=[query_input_component, user_token_input, synthesized_summary_component, fused_response_output_component])
323
  user_token_input.change(fn=update_tier_display_and_features_ui, inputs=[user_token_input], outputs=[tier_status_display, export_memory_button])
324
  export_memory_button.click(fn=export_user_memory_data_for_download, inputs=[user_token_input], outputs=[])
325
 
326
  return demo
327
 
328
+ # --- Main Execution Block ---
329
  if __name__ == "__main__":
330
+ logger.info("--- Initializing ZOTHEOS Gradio Interface (V13 - Walsh Redesign, Corrected) ---")
331
  zotheos_interface = build_interface(logo_path_verified, favicon_path_verified)
332
  logger.info("✅ ZOTHEOS Gradio UI built.")
333
  launch_kwargs = {"server_name": "0.0.0.0", "server_port": int(os.getenv("PORT", 7860)), "share": os.getenv("GRADIO_SHARE", "False").lower() == "true"}