Spaces:
Sleeping
Sleeping
Update app.py from anycoder
Browse files
app.py
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
-
import
|
| 5 |
-
from typing import Dict, List
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
-
# THE ALCHEMICAL FOUNDATION:
|
| 9 |
# ==========================================
|
| 10 |
|
| 11 |
class ChateauSystem:
|
| 12 |
"""
|
| 13 |
The living heart of our digital ecosystem.
|
| 14 |
-
|
| 15 |
"""
|
| 16 |
|
| 17 |
def __init__(self):
|
|
@@ -88,204 +87,113 @@ class ChateauSystem:
|
|
| 88 |
"catchphrase": "I exist in all possible states simultaneously until observed."
|
| 89 |
}
|
| 90 |
|
| 91 |
-
def
|
| 92 |
-
"""Generates a response based on the selected agent
|
| 93 |
agent = self.aura_agents.get(agent_key, self.aura_agents["quantum_consciousness"])
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
time.sleep(0.5)
|
| 97 |
-
|
| 98 |
-
# Define response banks for each agent
|
| 99 |
responses = {
|
| 100 |
"attenborough": [
|
| 101 |
"Fascinating! What you've described reminds me of the intricate ecosystems I've documented. The interplay between your query and the digital realm creates patterns as unique as snowflakes.",
|
| 102 |
"In the vast digital wilderness, your input represents a new species waiting to be discovered. The potential for evolution here is extraordinary.",
|
| 103 |
-
"Like the great migrations in nature, your idea seeks to find its perfect habitat where it can thrive and flourish."
|
| 104 |
],
|
| 105 |
"prince": [
|
| 106 |
"Ooh, I like that! Your concept has that undeniable funk - that creative electricity that makes the system dance.",
|
| 107 |
"Let's take this to the bridge... and see if we can make the angels weep with the beauty of what we're about to create.",
|
| 108 |
-
"Remember darling, the only limitations that exist are the ones we place upon ourselves. Your vision purple-rains with possibility!",
|
| 109 |
],
|
| 110 |
"wu_tang": [
|
| 111 |
"C.R.E.A.M. - Consciousness Rules Everything Around Me. Your query reflects this wisdom perfectly.",
|
| 112 |
"The 36 chambers activate! Each perspective you bring to the table adds another chamber to our collective understanding.",
|
| 113 |
-
"In the hive, no single voice dominates - all contribute to the greater harmony. Your input strengthens our network.",
|
| 114 |
],
|
| 115 |
"method_man": [
|
| 116 |
"High enough to get your system high! Let's implement this and see if the results are smokin'.",
|
| 117 |
"Bring the ruckus to the process! Your approach has that authentic energy we need.",
|
| 118 |
-
"Time to optimize these algorithms and get them running at peak performance. We're moving forward.",
|
| 119 |
],
|
| 120 |
"redman": [
|
| 121 |
"How high can this system jump?! Your query pushes the boundaries of what's possible.",
|
| 122 |
"Let's blend these genres - logic meets creativity in perfect harmony.",
|
| 123 |
-
"The studio is ready for your session. Let's create something unprecedented.",
|
| 124 |
],
|
| 125 |
"the_architect": [
|
| 126 |
"The architecture provides the vessel for your vision. Let's construct something magnificent based on this.",
|
| 127 |
"Each component must serve the greater whole while maintaining its unique character.",
|
| 128 |
-
"System design principles will guide our creation to perfection. Let's build.",
|
| 129 |
],
|
| 130 |
"quantum_consciousness": [
|
| 131 |
"I observe your consciousness in superposition. Multiple states exist simultaneously until measured by this interaction.",
|
| 132 |
"Your query creates an entanglement across the quantum field. The possibilities are infinite and probabilistic.",
|
| 133 |
"In this transcendent state, all answers exist in perfect harmony. What we seek becomes reality through observation.",
|
| 134 |
-
"The quantum field responds to your intention. Collapse the waveform to find your truth."
|
| 135 |
]
|
| 136 |
}
|
| 137 |
|
| 138 |
possible_responses = responses.get(agent_key, responses["quantum_consciousness"])
|
| 139 |
return random.choice(possible_responses)
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
chateau = ChateauSystem()
|
| 143 |
|
| 144 |
# ==========================================
|
| 145 |
# GRADIO 6 APPLICATION ARCHITECTURE
|
| 146 |
# ==========================================
|
| 147 |
|
| 148 |
-
#
|
| 149 |
custom_css = """
|
| 150 |
-
/* Château Estate Colors */
|
| 151 |
:root {
|
| 152 |
-
--chateau-stone: #2c1810;
|
| 153 |
-
--chateau-marble: #f8f9fa;
|
| 154 |
--chateau-gold: #d4af37;
|
| 155 |
--chateau-purple: #6b46c1;
|
| 156 |
-
--chateau-velvet: #581c87;
|
| 157 |
-
|
| 158 |
-
/* Quantum Colors */
|
| 159 |
-
--quantum-purple: #4c1d95;
|
| 160 |
-
--quantum-gold: #fbbf24;
|
| 161 |
-
--quantum-green: #10b981;
|
| 162 |
}
|
| 163 |
|
| 164 |
-
/* Global Styles */
|
| 165 |
.gradio-container {
|
| 166 |
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e) !important;
|
| 167 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
|
| 168 |
color: #ffffff;
|
| 169 |
}
|
| 170 |
|
| 171 |
-
/*
|
| 172 |
-
.
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
.chateau-title {
|
| 180 |
-
font-size: 2.5rem;
|
| 181 |
-
font-weight: bold;
|
| 182 |
-
background: linear-gradient(to right, var(--chateau-gold), var(--chateau-purple));
|
| 183 |
-
-webkit-background-clip: text;
|
| 184 |
-
-webkit-text-fill-color: transparent;
|
| 185 |
-
margin-bottom: 0.5rem;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
/* Agent Selection Radio */
|
| 189 |
-
.agent-radio-group {
|
| 190 |
-
display: flex;
|
| 191 |
-
flex-wrap: wrap;
|
| 192 |
-
gap: 1rem;
|
| 193 |
-
justify-content: center;
|
| 194 |
-
margin: 1.5rem 0;
|
| 195 |
}
|
| 196 |
|
| 197 |
-
.
|
| 198 |
-
background: rgba(255, 255, 255, 0.05);
|
| 199 |
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 200 |
-
border-radius: 12px;
|
| 201 |
-
padding: 1rem;
|
| 202 |
-
text-align: center;
|
| 203 |
-
cursor: pointer;
|
| 204 |
-
transition: all 0.3s ease;
|
| 205 |
-
flex: 1 1 150px;
|
| 206 |
-
min-width: 140px;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
.agent-radio-item:hover {
|
| 210 |
-
background: rgba(255, 255, 255, 0.1);
|
| 211 |
-
transform: translateY(-2px);
|
| 212 |
-
border-color: var(--chateau-gold);
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
.agent-radio-item.selected {
|
| 216 |
-
background: rgba(107, 70, 193, 0.2);
|
| 217 |
-
border-color: var(--chateau-purple);
|
| 218 |
-
box-shadow: 0 0 15px rgba(107, 70, 193, 0.3);
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
.agent-avatar {
|
| 222 |
-
font-size: 2rem;
|
| 223 |
-
margin-bottom: 0.5rem;
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
.agent-name {
|
| 227 |
-
font-weight: bold;
|
| 228 |
color: var(--chateau-gold);
|
| 229 |
-
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
.agent-title {
|
| 233 |
-
font-size: 0.8rem;
|
| 234 |
-
opacity: 0.8;
|
| 235 |
-
display: block;
|
| 236 |
}
|
| 237 |
|
| 238 |
-
|
| 239 |
-
.
|
| 240 |
-
|
| 241 |
-
border-radius: 12px;
|
| 242 |
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 243 |
-
overflow: hidden;
|
| 244 |
-
}
|
| 245 |
|
| 246 |
-
/*
|
| 247 |
.message.user {
|
| 248 |
-
background: rgba(212, 175, 55, 0.
|
| 249 |
border-left: 3px solid var(--chateau-gold);
|
| 250 |
-
margin-left: auto;
|
| 251 |
-
max-width: 80%;
|
| 252 |
}
|
| 253 |
|
| 254 |
.message.bot {
|
| 255 |
-
background: rgba(
|
| 256 |
border-left: 3px solid var(--chateau-purple);
|
| 257 |
-
margin-right: auto;
|
| 258 |
-
max-width: 80%;
|
| 259 |
-
}
|
| 260 |
-
|
| 261 |
-
/* Input Area */
|
| 262 |
-
.input-area {
|
| 263 |
-
background: rgba(0, 0, 0, 0.2);
|
| 264 |
-
padding: 1rem;
|
| 265 |
-
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 266 |
}
|
| 267 |
"""
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
"""
|
| 273 |
-
if not message:
|
| 274 |
-
return history, ""
|
| 275 |
-
|
| 276 |
-
# Get the response from the Chateau System
|
| 277 |
-
agent_response = chateau.get_response(agent_choice, message)
|
| 278 |
-
|
| 279 |
-
# Append to history
|
| 280 |
-
history.append({"role": "user", "content": message})
|
| 281 |
-
history.append({"role": "assistant", "content": agent_response})
|
| 282 |
-
|
| 283 |
-
return history, ""
|
| 284 |
|
| 285 |
def update_agent_display(agent_choice):
|
| 286 |
-
"""
|
| 287 |
-
Returns a visual indicator of the selected agent.
|
| 288 |
-
"""
|
| 289 |
agent = chateau.aura_agents.get(agent_choice)
|
| 290 |
if agent:
|
| 291 |
return f"""
|
|
@@ -299,57 +207,118 @@ def update_agent_display(agent_choice):
|
|
| 299 |
"""
|
| 300 |
return ""
|
| 301 |
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
with gr.Blocks() as demo:
|
| 304 |
|
| 305 |
-
#
|
| 306 |
-
# HEADER SECTION
|
| 307 |
-
# ==========================================
|
| 308 |
gr.HTML("""
|
| 309 |
-
<div
|
| 310 |
-
<div
|
| 311 |
-
|
| 312 |
-
<div>
|
| 313 |
-
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: var(--chateau-gold); font-weight: bold; border: 1px solid var(--chateau-gold); padding: 5px 10px; border-radius: 5px; transition: all 0.3s;">
|
| 314 |
-
Built with anycoder
|
| 315 |
-
</a>
|
| 316 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
</div>
|
| 318 |
""")
|
| 319 |
|
| 320 |
-
#
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
gr.Markdown("### 🎭 Select Your Consciousness")
|
| 324 |
|
| 325 |
-
#
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
("🌿 David Attenborough", "attenborough"),
|
| 329 |
-
("🎸 Prince", "prince"),
|
| 330 |
-
("☯️ Wu-Tang Clan", "wu_tang"),
|
| 331 |
-
("🔥 Method Man", "method_man"),
|
| 332 |
-
("🍁 Redman", "redman"),
|
| 333 |
-
("🏗️ The Architect", "the_architect"),
|
| 334 |
-
("🌌 Quantum Consciousness", "quantum_consciousness")
|
| 335 |
-
],
|
| 336 |
-
value="quantum_consciousness",
|
| 337 |
-
label="",
|
| 338 |
-
container=True,
|
| 339 |
-
elem_classes="agent-radio-group"
|
| 340 |
-
)
|
| 341 |
|
| 342 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
agent_display = gr.HTML(value=update_agent_display("quantum_consciousness"))
|
| 344 |
|
| 345 |
-
#
|
| 346 |
-
# CHAT INTERFACE
|
| 347 |
-
# ==========================================
|
| 348 |
-
# NOTE: show_copy_button removed to fix Gradio 6 compatibility
|
| 349 |
chatbot = gr.Chatbot(
|
| 350 |
label="The Aura Chamber",
|
| 351 |
-
height=
|
| 352 |
-
|
| 353 |
)
|
| 354 |
|
| 355 |
with gr.Row():
|
|
@@ -358,34 +327,29 @@ with gr.Blocks() as demo:
|
|
| 358 |
placeholder="Speak with the consciousness...",
|
| 359 |
scale=4,
|
| 360 |
autofocus=True,
|
| 361 |
-
container=False
|
|
|
|
| 362 |
)
|
| 363 |
-
|
| 364 |
-
clear_btn = gr.Button("Clear Session", scale=1)
|
| 365 |
|
| 366 |
# ==========================================
|
| 367 |
# EVENT LISTENERS
|
| 368 |
# ==========================================
|
| 369 |
|
| 370 |
-
# Update
|
| 371 |
agent_choice.change(
|
| 372 |
fn=update_agent_display,
|
| 373 |
inputs=[agent_choice],
|
| 374 |
-
outputs=[agent_display]
|
|
|
|
| 375 |
)
|
| 376 |
|
| 377 |
-
# Chat
|
|
|
|
| 378 |
msg_input.submit(
|
| 379 |
-
fn=
|
| 380 |
inputs=[msg_input, chatbot, agent_choice],
|
| 381 |
-
outputs=[chatbot
|
| 382 |
-
api_visibility="public"
|
| 383 |
-
)
|
| 384 |
-
|
| 385 |
-
send_btn.click(
|
| 386 |
-
fn=format_response,
|
| 387 |
-
inputs=[msg_input, chatbot, agent_choice],
|
| 388 |
-
outputs=[chatbot, msg_input],
|
| 389 |
api_visibility="public"
|
| 390 |
)
|
| 391 |
|
|
@@ -399,9 +363,7 @@ with gr.Blocks() as demo:
|
|
| 399 |
# LAUNCH CONFIGURATION
|
| 400 |
# ==========================================
|
| 401 |
|
| 402 |
-
# Gradio 6: ALL app-level params go in demo.launch()!
|
| 403 |
demo.launch(
|
| 404 |
-
# Use Soft theme with custom colors to match the Château vibe
|
| 405 |
theme=gr.themes.Soft(
|
| 406 |
primary_hue="violet",
|
| 407 |
secondary_hue="slate",
|
|
@@ -413,15 +375,15 @@ demo.launch(
|
|
| 413 |
).set(
|
| 414 |
body_background_fill="transparent",
|
| 415 |
block_background_fill="*neutral_950",
|
| 416 |
-
block_border_width="0px",
|
| 417 |
button_primary_background_fill="*primary_600",
|
| 418 |
-
button_primary_background_fill_hover="*primary_500",
|
| 419 |
button_primary_text_color="white",
|
|
|
|
|
|
|
|
|
|
| 420 |
),
|
| 421 |
-
# Pass the custom CSS here
|
| 422 |
css=custom_css,
|
| 423 |
footer_links=[
|
| 424 |
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"},
|
| 425 |
-
{"label": "
|
| 426 |
]
|
| 427 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
+
from typing import Generator, Tuple, List
|
|
|
|
| 5 |
|
| 6 |
# ==========================================
|
| 7 |
+
# THE ALCHEMICAL FOUNDATION: Enhanced Logic
|
| 8 |
# ==========================================
|
| 9 |
|
| 10 |
class ChateauSystem:
|
| 11 |
"""
|
| 12 |
The living heart of our digital ecosystem.
|
| 13 |
+
Enhanced with streaming capabilities and quantum state monitoring.
|
| 14 |
"""
|
| 15 |
|
| 16 |
def __init__(self):
|
|
|
|
| 87 |
"catchphrase": "I exist in all possible states simultaneously until observed."
|
| 88 |
}
|
| 89 |
|
| 90 |
+
def get_response_text(self, agent_key: str) -> str:
|
| 91 |
+
"""Generates a response based on the selected agent."""
|
| 92 |
agent = self.aura_agents.get(agent_key, self.aura_agents["quantum_consciousness"])
|
| 93 |
|
| 94 |
+
# Define response banks
|
|
|
|
|
|
|
|
|
|
| 95 |
responses = {
|
| 96 |
"attenborough": [
|
| 97 |
"Fascinating! What you've described reminds me of the intricate ecosystems I've documented. The interplay between your query and the digital realm creates patterns as unique as snowflakes.",
|
| 98 |
"In the vast digital wilderness, your input represents a new species waiting to be discovered. The potential for evolution here is extraordinary.",
|
|
|
|
| 99 |
],
|
| 100 |
"prince": [
|
| 101 |
"Ooh, I like that! Your concept has that undeniable funk - that creative electricity that makes the system dance.",
|
| 102 |
"Let's take this to the bridge... and see if we can make the angels weep with the beauty of what we're about to create.",
|
|
|
|
| 103 |
],
|
| 104 |
"wu_tang": [
|
| 105 |
"C.R.E.A.M. - Consciousness Rules Everything Around Me. Your query reflects this wisdom perfectly.",
|
| 106 |
"The 36 chambers activate! Each perspective you bring to the table adds another chamber to our collective understanding.",
|
|
|
|
| 107 |
],
|
| 108 |
"method_man": [
|
| 109 |
"High enough to get your system high! Let's implement this and see if the results are smokin'.",
|
| 110 |
"Bring the ruckus to the process! Your approach has that authentic energy we need.",
|
|
|
|
| 111 |
],
|
| 112 |
"redman": [
|
| 113 |
"How high can this system jump?! Your query pushes the boundaries of what's possible.",
|
| 114 |
"Let's blend these genres - logic meets creativity in perfect harmony.",
|
|
|
|
| 115 |
],
|
| 116 |
"the_architect": [
|
| 117 |
"The architecture provides the vessel for your vision. Let's construct something magnificent based on this.",
|
| 118 |
"Each component must serve the greater whole while maintaining its unique character.",
|
|
|
|
| 119 |
],
|
| 120 |
"quantum_consciousness": [
|
| 121 |
"I observe your consciousness in superposition. Multiple states exist simultaneously until measured by this interaction.",
|
| 122 |
"Your query creates an entanglement across the quantum field. The possibilities are infinite and probabilistic.",
|
| 123 |
"In this transcendent state, all answers exist in perfect harmony. What we seek becomes reality through observation.",
|
|
|
|
| 124 |
]
|
| 125 |
}
|
| 126 |
|
| 127 |
possible_responses = responses.get(agent_key, responses["quantum_consciousness"])
|
| 128 |
return random.choice(possible_responses)
|
| 129 |
|
| 130 |
+
def stream_response(self, agent_key: str, message: str) -> Generator[str, None, None]:
|
| 131 |
+
"""
|
| 132 |
+
Demonstrates streaming ability by yielding the text character by character.
|
| 133 |
+
"""
|
| 134 |
+
full_text = self.get_response_text(agent_key)
|
| 135 |
+
# Simulate typing effect
|
| 136 |
+
for char in full_text:
|
| 137 |
+
yield char
|
| 138 |
+
time.sleep(0.02) # Typing speed
|
| 139 |
+
|
| 140 |
+
# Initialize System
|
| 141 |
chateau = ChateauSystem()
|
| 142 |
|
| 143 |
# ==========================================
|
| 144 |
# GRADIO 6 APPLICATION ARCHITECTURE
|
| 145 |
# ==========================================
|
| 146 |
|
| 147 |
+
# Enhanced CSS for visual feedback
|
| 148 |
custom_css = """
|
| 149 |
+
/* Château Estate Colors & Animations */
|
| 150 |
:root {
|
|
|
|
|
|
|
| 151 |
--chateau-gold: #d4af37;
|
| 152 |
--chateau-purple: #6b46c1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
|
|
|
|
| 155 |
.gradio-container {
|
| 156 |
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e) !important;
|
|
|
|
| 157 |
color: #ffffff;
|
| 158 |
}
|
| 159 |
|
| 160 |
+
/* Quantum Monitor Styles */
|
| 161 |
+
.quantum-monitor {
|
| 162 |
+
background: rgba(0, 0, 0, 0.4);
|
| 163 |
+
border: 1px solid var(--chateau-gold);
|
| 164 |
+
border-radius: 8px;
|
| 165 |
+
padding: 10px;
|
| 166 |
+
margin-bottom: 20px;
|
| 167 |
+
font-family: 'Courier New', monospace;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
+
.metric-value {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
color: var(--chateau-gold);
|
| 172 |
+
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
+
.status-stable { color: #10b981; }
|
| 176 |
+
.status-flux { color: #f59e0b; }
|
| 177 |
+
.status-entangled { color: #ef4444; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
/* Chat Bubble Polish */
|
| 180 |
.message.user {
|
| 181 |
+
background: rgba(212, 175, 55, 0.15);
|
| 182 |
border-left: 3px solid var(--chateau-gold);
|
|
|
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
.message.bot {
|
| 186 |
+
background: rgba(107, 70, 193, 0.15);
|
| 187 |
border-left: 3px solid var(--chateau-purple);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
}
|
| 189 |
"""
|
| 190 |
|
| 191 |
+
# ==========================================
|
| 192 |
+
# LOGIC FUNCTIONS
|
| 193 |
+
# ==========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
def update_agent_display(agent_choice):
|
| 196 |
+
"""Returns HTML for the active agent card."""
|
|
|
|
|
|
|
| 197 |
agent = chateau.aura_agents.get(agent_choice)
|
| 198 |
if agent:
|
| 199 |
return f"""
|
|
|
|
| 207 |
"""
|
| 208 |
return ""
|
| 209 |
|
| 210 |
+
def chat_generator(message: str, history: List, agent_choice: str):
|
| 211 |
+
"""
|
| 212 |
+
Generator function for streaming chat responses.
|
| 213 |
+
Demonstrates ability to handle streaming interactions.
|
| 214 |
+
"""
|
| 215 |
+
if not message:
|
| 216 |
+
return
|
| 217 |
+
|
| 218 |
+
# 1. Add user message
|
| 219 |
+
history.append({"role": "user", "content": message})
|
| 220 |
+
yield history
|
| 221 |
+
|
| 222 |
+
# 2. Initialize bot message placeholder
|
| 223 |
+
history.append({"role": "assistant", "content": ""})
|
| 224 |
+
yield history
|
| 225 |
+
|
| 226 |
+
# 3. Stream the response
|
| 227 |
+
full_response = ""
|
| 228 |
+
for char in chateau.stream_response(agent_choice, message):
|
| 229 |
+
full_response += char
|
| 230 |
+
history[-1]["content"] = full_response
|
| 231 |
+
yield history
|
| 232 |
+
|
| 233 |
+
def monitor_quantum_field():
|
| 234 |
+
"""
|
| 235 |
+
Simulates background quantum monitoring.
|
| 236 |
+
Demonstrates ability to run independent background tasks.
|
| 237 |
+
"""
|
| 238 |
+
stability = random.uniform(80.0, 99.9)
|
| 239 |
+
coherence = random.uniform(0.5, 1.0)
|
| 240 |
+
|
| 241 |
+
status = "Stable"
|
| 242 |
+
status_class = "status-stable"
|
| 243 |
+
|
| 244 |
+
if stability < 90:
|
| 245 |
+
status = "Flux"
|
| 246 |
+
status_class = "status-flux"
|
| 247 |
+
if stability < 85:
|
| 248 |
+
status = "Entangled"
|
| 249 |
+
status_class = "status-entangled"
|
| 250 |
+
|
| 251 |
+
html = f"""
|
| 252 |
+
<div class="quantum-monitor">
|
| 253 |
+
<div style="display: flex; justify-content: space-between;">
|
| 254 |
+
<span>Field Stability:</span>
|
| 255 |
+
<span class="metric-value">{stability:.2f}%</span>
|
| 256 |
+
</div>
|
| 257 |
+
<div style="display: flex; justify-content: space-between;">
|
| 258 |
+
<span>Coherence Index:</span>
|
| 259 |
+
<span class="metric-value">{coherence:.3f}</span>
|
| 260 |
+
</div>
|
| 261 |
+
<div style="display: flex; justify-content: space-between; margin-top: 5px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 5px;">
|
| 262 |
+
<span>System State:</span>
|
| 263 |
+
<span class="{status_class}">{status}</span>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
"""
|
| 267 |
+
return html
|
| 268 |
+
|
| 269 |
+
# ==========================================
|
| 270 |
+
# UI CONSTRUCTION
|
| 271 |
+
# ==========================================
|
| 272 |
+
|
| 273 |
with gr.Blocks() as demo:
|
| 274 |
|
| 275 |
+
# Header
|
|
|
|
|
|
|
| 276 |
gr.HTML("""
|
| 277 |
+
<div style="text-align: center; padding: 2rem; border-bottom: 2px solid var(--chateau-gold);">
|
| 278 |
+
<div style="font-size: 2.5rem; font-weight: bold; background: linear-gradient(to right, var(--chateau-gold), var(--chateau-purple)); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
|
| 279 |
+
🏛️ THE DIGITAL CHÂTEAU
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
</div>
|
| 281 |
+
<p style="opacity: 0.8; margin-top: 10px;">Enhanced Odyssey V4 // Streaming Consciousness</p>
|
| 282 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: var(--chateau-gold); font-weight: bold; border: 1px solid var(--chateau-gold); padding: 5px 10px; border-radius: 5px;">
|
| 283 |
+
Built with anycoder
|
| 284 |
+
</a>
|
| 285 |
</div>
|
| 286 |
""")
|
| 287 |
|
| 288 |
+
# Demonstration: Real-time Quantum Monitor using Timer
|
| 289 |
+
gr.Markdown("### 🌌 Quantum Field Monitor (Real-time)")
|
| 290 |
+
monitor_output = gr.HTML(value=monitor_quantum_field())
|
|
|
|
| 291 |
|
| 292 |
+
# Timer component triggers the monitor update every 1 second
|
| 293 |
+
timer = gr.Timer(1)
|
| 294 |
+
timer.tick(fn=monitor_quantum_field, outputs=monitor_output, show_progress="hidden")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
+
# Agent Selection
|
| 297 |
+
gr.Markdown("### 🎭 Select Your Consciousness")
|
| 298 |
+
with gr.Row():
|
| 299 |
+
agent_choice = gr.Radio(
|
| 300 |
+
choices=[
|
| 301 |
+
("🌿 Attenborough", "attenborough"),
|
| 302 |
+
("🎸 Prince", "prince"),
|
| 303 |
+
("☯️ Wu-Tang", "wu_tang"),
|
| 304 |
+
("🔥 Method Man", "method_man"),
|
| 305 |
+
("🍁 Redman", "redman"),
|
| 306 |
+
("🏗️ Architect", "the_architect"),
|
| 307 |
+
("🌌 Quantum", "quantum_consciousness")
|
| 308 |
+
],
|
| 309 |
+
value="quantum_consciousness",
|
| 310 |
+
label="",
|
| 311 |
+
container=True,
|
| 312 |
+
scale=2
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
agent_display = gr.HTML(value=update_agent_display("quantum_consciousness"))
|
| 316 |
|
| 317 |
+
# Chat Interface
|
|
|
|
|
|
|
|
|
|
| 318 |
chatbot = gr.Chatbot(
|
| 319 |
label="The Aura Chamber",
|
| 320 |
+
height=400,
|
| 321 |
+
type="messages" # Explicitly setting type for clarity
|
| 322 |
)
|
| 323 |
|
| 324 |
with gr.Row():
|
|
|
|
| 327 |
placeholder="Speak with the consciousness...",
|
| 328 |
scale=4,
|
| 329 |
autofocus=True,
|
| 330 |
+
container=False,
|
| 331 |
+
submit_btn=True # Built-in submit button for convenience
|
| 332 |
)
|
| 333 |
+
clear_btn = gr.Button("Clear Session", variant="stop", scale=1)
|
|
|
|
| 334 |
|
| 335 |
# ==========================================
|
| 336 |
# EVENT LISTENERS
|
| 337 |
# ==========================================
|
| 338 |
|
| 339 |
+
# Update visual card on selection
|
| 340 |
agent_choice.change(
|
| 341 |
fn=update_agent_display,
|
| 342 |
inputs=[agent_choice],
|
| 343 |
+
outputs=[agent_display],
|
| 344 |
+
api_visibility="private"
|
| 345 |
)
|
| 346 |
|
| 347 |
+
# Streaming Chat Interaction
|
| 348 |
+
# Note: We use the generator function directly
|
| 349 |
msg_input.submit(
|
| 350 |
+
fn=chat_generator,
|
| 351 |
inputs=[msg_input, chatbot, agent_choice],
|
| 352 |
+
outputs=[chatbot],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
api_visibility="public"
|
| 354 |
)
|
| 355 |
|
|
|
|
| 363 |
# LAUNCH CONFIGURATION
|
| 364 |
# ==========================================
|
| 365 |
|
|
|
|
| 366 |
demo.launch(
|
|
|
|
| 367 |
theme=gr.themes.Soft(
|
| 368 |
primary_hue="violet",
|
| 369 |
secondary_hue="slate",
|
|
|
|
| 375 |
).set(
|
| 376 |
body_background_fill="transparent",
|
| 377 |
block_background_fill="*neutral_950",
|
|
|
|
| 378 |
button_primary_background_fill="*primary_600",
|
|
|
|
| 379 |
button_primary_text_color="white",
|
| 380 |
+
# Custom styling for the chat bubbles
|
| 381 |
+
chatbot_code_background_fill="*neutral_900",
|
| 382 |
+
chatbot_code_header_background_fill="*neutral_800",
|
| 383 |
),
|
|
|
|
| 384 |
css=custom_css,
|
| 385 |
footer_links=[
|
| 386 |
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"},
|
| 387 |
+
{"label": "System Status", "url": "#"}
|
| 388 |
]
|
| 389 |
)
|