ZOTHEOS commited on
Commit
9dba011
·
verified ·
1 Parent(s): 609ec31

Update main_web.py

Browse files
Files changed (1) hide show
  1. main_web.py +70 -70
main_web.py CHANGED
@@ -1,119 +1,119 @@
1
- # FILE: main_web.py (Hugging Face Demo - FINAL v1)
2
 
3
  import gradio as gr
4
  import asyncio
5
  import logging
6
  import os
7
  import sys
8
- from typing import Optional, Dict, Any, List
9
- import json
10
- import subprocess
11
 
12
- # --- Constants & Logger ---
13
  APP_TITLE = "ZOTHEOS - Ethical Fusion AI"
14
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
15
  logger = logging.getLogger("ZOTHEOS_Interface_HF")
16
 
17
- # --- Asset & Link Configuration ---
18
  def get_asset_path(filename: str) -> str:
19
- # In HF Spaces, assets are in the root or /assets. This handles both.
20
  return filename if os.path.exists(filename) else os.path.join('assets', filename)
21
 
22
  logo_path_verified = get_asset_path("zotheos_logo.png")
23
- GUMROAD_LINK = "https://zotheos.gumroad.com/l/jibfv" # Your actual Gumroad link
24
 
25
- # --- Core Logic Imports & Initialization ---
26
  try:
27
  from modules.main_fusion_public import MainFusionPublic
28
  ai_system = MainFusionPublic()
29
  except Exception as e:
30
- logger.error(f"CRITICAL: Failed to initialize AI system: {e}", exc_info=True)
31
  ai_system = None
32
 
33
- # --- DEFINITIVE "OBSIDIAN" CSS THEME v2.0 ---
34
- zotheos_desktop_css = """
35
  @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;600;700&display=swap');
36
- body { background: linear-gradient(135deg, #000000, #1c1c1c) !important; background-attachment: fixed !important; color: #f0f0f0 !important; font-family: 'Inter', sans-serif !important; }
37
- .gradio-container { background: transparent !important; max-width: 1100px !important; margin: 2rem auto !important; padding: 2rem !important; }
38
- #header_logo img { max-height: 80px !important; filter: brightness(0) invert(1) !important; margin-bottom: 1rem !important; }
39
- #header_subtitle { font-family: 'Bebas Neue', cursive !important; font-size: 2.2rem !important; text-transform: uppercase !important; letter-spacing: 3px !important; line-height: 1.2 !important; }
40
- #header_tagline { color: #a0a0a0 !important; font-size: 1.1rem !important; margin-top: -5px !important; margin-bottom: 3rem !important; text-align: center; }
41
- .gradio-textbox, .gradio-accordion { background-color: #121212 !important; border: 1px solid #333333 !important; border-radius: 12px !important;}
42
- .gradio-textbox textarea { font-size: 1.1rem !important; color: #f0f0f0 !important; }
43
- .result-box { background-color: rgba(18, 18, 18, 0.9) !important; border: 1px solid #333333 !important; border-radius: 12px !important; padding: 1.5rem 2rem !important; backdrop-filter: blur(5px); }
44
- .result-box h2 { font-family: 'Bebas Neue', cursive !important; font-size: 1.7rem !important; color: white !important; border-bottom: 1px solid #333333; padding-bottom: 0.75rem; margin-bottom: 1.5rem; text-align: left; letter-spacing: 1.5px !important; line-height: 1.3 !important; }
45
- .cosmic-loading { padding: 3rem; text-align:center; } .orbital-spinner { width:40px;height:40px;border-radius:50%;animation:spin 1s linear infinite;margin:0 auto 15px auto; border: 4px solid #333; border-top-color: white;} @keyframes spin{to{transform:rotate(360deg)}}
46
- .cta-button { background: #FFFFFF !important; color: #000000 !important; font-weight: bold !important; } .cta-button:hover { background: #e0e0e0 !important; }
47
  footer { display: none !important; }
48
  """
49
 
50
  # --- Build Gradio Interface ---
51
  def build_interface():
52
- zotheos_theme = gr.themes.Base(primary_hue=gr.themes.colors.neutral, secondary_hue=gr.themes.colors.neutral).set(
53
- button_primary_background_fill="white", button_primary_background_fill_hover="#e0e0e0", button_primary_text_color="black",
54
- button_secondary_background_fill="#2C2C2C", button_secondary_text_color="white", block_radius="12px"
55
  )
56
 
57
- with gr.Blocks(theme=zotheos_theme, css=zotheos_desktop_css, title=APP_TITLE) as demo:
58
- with gr.Column(elem_classes="gradio-container"):
59
- gr.Image(value=logo_path_verified, elem_id="header_logo", show_label=False, container=False, interactive=False)
60
- gr.Markdown("Ethical Fusion AI for Synthesized Intelligence", elem_id="header_subtitle")
61
- gr.Markdown("Fusing perspectives for deeper truth.", elem_id="header_tagline")
62
-
63
  with gr.Accordion("🔥 Get the Full Offline Desktop Version", open=True):
64
  gr.Markdown("This web demo uses smaller, slower models. For the full-power, GPU-accelerated, 100% private experience, download the ZOTHEOS Public Beta for your Windows PC.")
65
  gr.Button("Download Full Version on Gumroad", link=GUMROAD_LINK, elem_classes="cta-button")
66
 
67
- gr.Markdown("---")
68
-
69
  with gr.Row():
70
- with gr.Column(scale=4):
71
- query_input = gr.Textbox(label="Your Inquiry:", placeholder="e.g., Analyze the ethical implications of AI in art...", lines=8)
72
- with gr.Row():
73
- clear_button = gr.Button("Clear", variant="secondary")
74
- submit_button = gr.Button("Process Inquiry (Web Demo)", variant="primary")
75
- with gr.Column(scale=1):
76
- # Export button removed for web demo simplicity
77
- with gr.Accordion("System Status & Models", open=False):
78
- active_models_display = gr.Markdown("**Status:** Online")
79
- with gr.Accordion("Recent Interactions", open=False):
80
- memory_display_panel = gr.HTML("<div style='color: #a0a0a0;'>Session memory is active.</div>")
81
 
82
- status_indicator = gr.HTML(visible=False)
83
- with gr.Column(elem_id="results_column", visible=False) as results_box:
84
- with gr.Column(elem_classes="result-box"):
85
- synthesized_summary_output = gr.Markdown()
86
- fusion_output = gr.Markdown()
 
 
87
 
88
- # --- UNBREAKABLE EVENT HANDLER ---
89
- async def process_query_wrapper(query):
90
- loading_html = "<div class='cosmic-loading'><div class='orbital-spinner'></div></div>"
91
- yield { status_indicator: gr.update(value=loading_html, visible=True), results_box: gr.update(visible=False), submit_button: gr.update(interactive=False) }
92
 
93
- if not ai_system:
94
- summary_text, perspectives_text = "## SYSTEM OFFLINE", "[The AI engine failed to load.]"
95
- else:
96
- response = await ai_system.process_query_with_fusion(query)
97
- summary_text = response.split("###")[0] if "###" in response else response
98
- perspectives_text = "###" + response.split("###", 1)[1] if "###" in response else ""
99
- mem_data = await ai_system.memory_bank.retrieve_recent_memories_async()
100
- memory_display_panel.update(value=render_memory_entries_as_html(mem_data))
101
 
102
- yield {
103
- status_indicator: gr.update(visible=False), results_box: gr.update(visible=True),
104
- synthesized_summary_output: summary_text, fusion_output: perspectives_text,
105
- submit_button: gr.update(interactive=True)
106
  }
107
 
108
  submit_button.click(
109
- fn=process_query_wrapper, inputs=[query_input],
110
- outputs=[status_indicator, results_box, synthesized_summary_output, fusion_output, submit_button]
111
- )
 
 
 
 
 
112
  clear_button.click(lambda: ("", gr.update(visible=False), "", ""), outputs=[query_input, results_box, synthesized_summary_output, fusion_output])
 
113
  return demo
114
 
115
  # --- Main Execution Block ---
116
  if __name__ == "__main__":
117
- logger.info("--- Initializing ZOTHEOS Hugging Face Demo (v3.0 - Professional) ---")
118
  zotheos_interface = build_interface()
119
  zotheos_interface.queue().launch()
 
1
+ # FILE: main_web.py (Hugging Face Demo - FINAL v1.0 - Obsidian Pro)
2
 
3
  import gradio as gr
4
  import asyncio
5
  import logging
6
  import os
7
  import sys
8
+ from typing import Optional, Dict, Any
 
 
9
 
10
+ # --- Basic Setup ---
11
  APP_TITLE = "ZOTHEOS - Ethical Fusion AI"
12
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
13
  logger = logging.getLogger("ZOTHEOS_Interface_HF")
14
 
 
15
  def get_asset_path(filename: str) -> str:
 
16
  return filename if os.path.exists(filename) else os.path.join('assets', filename)
17
 
18
  logo_path_verified = get_asset_path("zotheos_logo.png")
19
+ GUMROAD_LINK = "https://zotheos.gumroad.com/l/jibfv"
20
 
21
+ # --- Core Logic Imports ---
22
  try:
23
  from modules.main_fusion_public import MainFusionPublic
24
  ai_system = MainFusionPublic()
25
  except Exception as e:
26
+ logger.error(f"CRITICAL: Failed to initialize AI system: {e}")
27
  ai_system = None
28
 
29
+ # --- DEFINITIVE "OBSIDIAN PRO" CSS ---
30
+ zotheos_pro_css = """
31
  @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;600;700&display=swap');
32
+ body { background: #0a0a0a !important; font-family: 'Inter', sans-serif !important; }
33
+ .gradio-container { max-width: 960px !important; margin: 0 auto !important; padding-top: 2rem !important; }
34
+ #main_layout { display:flex; flex-direction:column; align-items:center; gap: 1.5rem; }
35
+ #header_logo img { max-height: 70px !important; filter: brightness(0) invert(1) !important; }
36
+ #header_subtitle { font-family: 'Bebas Neue', cursive !important; font-size: 2rem !important; letter-spacing: 2px !important; text-align: center; }
37
+ #header_tagline { color: #a0a0a0 !important; text-align: center; margin-top: -1rem !important; }
38
+ .gradio-accordion { background-color: #1a1a1a !important; border: 1px solid #333 !important; }
39
+ .cta-button { background: #FFFFFF !important; color: #000000 !important; font-weight: bold !important; }
40
+ .gradio-textbox textarea { font-size: 1.1rem !important; }
41
+ #results_box { background-color: rgba(18, 18, 18, 0.9) !important; border: 1px solid #333 !important; backdrop-filter: blur(5px); }
42
+ #results_box h2 { font-family: 'Bebas Neue', cursive !important; font-size: 1.5rem !important; border-bottom: 1px solid #333; padding-bottom: 0.75rem; margin-bottom: 1rem; }
43
  footer { display: none !important; }
44
  """
45
 
46
  # --- Build Gradio Interface ---
47
  def build_interface():
48
+ theme = gr.themes.Base(primary_hue=gr.themes.colors.neutral, secondary_hue=gr.themes.colors.neutral).set(
49
+ button_primary_background_fill="white", button_primary_text_color="black", block_radius="12px"
 
50
  )
51
 
52
+ with gr.Blocks(theme=theme, css=zotheos_pro_css, title=APP_TITLE) as demo:
53
+ with gr.Column(elem_id="main_layout"):
54
+ gr.Image(value=logo_path_verified, elem_id="header_logo", show_label=False, container=False)
55
+ gr.Markdown("<h1 id='header_subtitle'>Ethical Fusion AI for Synthesized Intelligence</h1>", elem_id="header-title-wrapper")
56
+ gr.Markdown("<p id='header_tagline'>Fusing perspectives for deeper truth.</p>", elem_id="tagline-wrapper")
57
+
58
  with gr.Accordion("🔥 Get the Full Offline Desktop Version", open=True):
59
  gr.Markdown("This web demo uses smaller, slower models. For the full-power, GPU-accelerated, 100% private experience, download the ZOTHEOS Public Beta for your Windows PC.")
60
  gr.Button("Download Full Version on Gumroad", link=GUMROAD_LINK, elem_classes="cta-button")
61
 
62
+ query_input = gr.Textbox(label="Your Inquiry:", placeholder="e.g., What is universal peace?", lines=5)
63
+
64
  with gr.Row():
65
+ clear_button = gr.Button("Clear")
66
+ submit_button = gr.Button("Process Inquiry (Web Demo)", variant="primary")
67
+
68
+ # --- REAL-TIME PROGRESS BAR ---
69
+ progress_bar = gr.Progress(track_tqdm=True, label="Synthesizing...", visible=False)
70
+
71
+ with gr.Column(elem_id="results_box", visible=False) as results_box:
72
+ synthesized_summary_output = gr.Markdown()
73
+ fusion_output = gr.Markdown()
 
 
74
 
75
+ # --- Backend Logic ---
76
+ async def process_query(query, progress=gr.Progress(track_tqdm=True)):
77
+ if not ai_system:
78
+ return {"results_box": gr.update(visible=True), "synthesized_summary_output": "## SYSTEM OFFLINE\n\n[The AI engine failed to load.]", "fusion_output": ""}
79
+
80
+ progress(0, desc="Initiating Fusion...")
81
+ await asyncio.sleep(0.5)
82
 
83
+ # This is a simplified progress simulation for the web demo
84
+ for i in progress.tqdm(range(10), desc="Querying AI Cores..."):
85
+ await asyncio.sleep(0.2)
 
86
 
87
+ progress(0.5, desc="Generating Final Synthesis...")
88
+
89
+ response = await ai_system.process_query_with_fusion(query)
90
+ summary = response.split("###")[0].replace("## ✨ ZOTHEOS Final Synthesized Insight ✨", "").strip()
91
+ perspectives = "###" + response.split("###", 1)[1] if "###" in response else ""
92
+
93
+ for i in progress.tqdm(range(5), desc="Formatting Response..."):
94
+ await asyncio.sleep(0.1)
95
 
96
+ return {
97
+ results_box: gr.update(visible=True),
98
+ synthesized_summary_output: "## ZOTHEOS Final Synthesized Insight ✨\n\n" + summary,
99
+ fusion_output: perspectives
100
  }
101
 
102
  submit_button.click(
103
+ fn=process_query,
104
+ inputs=query_input,
105
+ outputs=[results_box, synthesized_summary_output, fusion_output],
106
+ show_progress="hidden" # We use our custom progress bar
107
+ ).then(lambda: gr.update(visible=True), outputs=progress_bar).then(
108
+ process_query, inputs=query_input, outputs=[results_box, synthesized_summary_output, fusion_output]
109
+ ).then(lambda: gr.update(visible=False), outputs=progress_bar)
110
+
111
  clear_button.click(lambda: ("", gr.update(visible=False), "", ""), outputs=[query_input, results_box, synthesized_summary_output, fusion_output])
112
+
113
  return demo
114
 
115
  # --- Main Execution Block ---
116
  if __name__ == "__main__":
117
+ logger.info("--- Initializing ZOTHEOS Hugging Face Demo (v4.0 - Obsidian Pro) ---")
118
  zotheos_interface = build_interface()
119
  zotheos_interface.queue().launch()