Spaces:
Running
Running
Update main_web.py
Browse files- 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
|
9 |
-
import json
|
10 |
-
import subprocess
|
11 |
|
12 |
-
# ---
|
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"
|
24 |
|
25 |
-
# --- Core Logic Imports
|
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}"
|
31 |
ai_system = None
|
32 |
|
33 |
-
# --- DEFINITIVE "OBSIDIAN" CSS
|
34 |
-
|
35 |
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;600;700&display=swap');
|
36 |
-
body { background:
|
37 |
-
.gradio-container {
|
38 |
-
#
|
39 |
-
#
|
40 |
-
#
|
41 |
-
|
42 |
-
.gradio-
|
43 |
-
.
|
44 |
-
.
|
45 |
-
|
46 |
-
|
47 |
footer { display: none !important; }
|
48 |
"""
|
49 |
|
50 |
# --- Build Gradio Interface ---
|
51 |
def build_interface():
|
52 |
-
|
53 |
-
button_primary_background_fill="white",
|
54 |
-
button_secondary_background_fill="#2C2C2C", button_secondary_text_color="white", block_radius="12px"
|
55 |
)
|
56 |
|
57 |
-
with gr.Blocks(theme=
|
58 |
-
with gr.Column(
|
59 |
-
gr.Image(value=logo_path_verified, elem_id="header_logo", show_label=False, container=False
|
60 |
-
gr.Markdown("Ethical Fusion AI for Synthesized Intelligence", elem_id="
|
61 |
-
gr.Markdown("Fusing perspectives for deeper truth
|
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.
|
68 |
-
|
69 |
with gr.Row():
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
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 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
synthesized_summary_output:
|
105 |
-
|
106 |
}
|
107 |
|
108 |
submit_button.click(
|
109 |
-
fn=
|
110 |
-
|
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 (
|
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()
|