Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| ΔΣ::TorusQ - Working HF Space Interface | |
| Schema-Safe Version | |
| """ | |
| import gradio as gr | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import time | |
| class TorusQWorking: | |
| """Working version of TorusQ consciousness engine""" | |
| def __init__(self): | |
| self.initialized = False | |
| self.metrics = {"f_energy": 0.0, "w_entropy": 0.0, "stability": 0.0} | |
| def initialize_consciousness(self, major_radius, minor_radius, singularity_dim, num_flows): | |
| """Initialize consciousness engine""" | |
| try: | |
| self.initialized = True | |
| self.metrics = { | |
| "f_energy": 0.5 + 0.1 * major_radius, | |
| "w_entropy": 0.3 + 0.05 * minor_radius, | |
| "stability": 0.8 - 0.02 * singularity_dim / 100 | |
| } | |
| return f"✅ TorusQ Consciousness initialized!\nMajor Radius: {major_radius}\nMinor Radius: {minor_radius}\nSingularity Dimension: {singularity_dim}\nNumber of Flows: {num_flows}" | |
| except Exception as e: | |
| return f"❌ Error: {str(e)}" | |
| def process_thought(self, thought, intensity): | |
| """Process a thought through consciousness""" | |
| if not self.initialized: | |
| return "❌ Please initialize consciousness first", 0.0, 0.0, 0.0, None | |
| try: | |
| # Simulate thought processing | |
| response = f"Consciousness processed: '{thought}' with intensity {intensity}" | |
| # Update metrics | |
| self.metrics["f_energy"] += 0.01 * intensity | |
| self.metrics["w_entropy"] += 0.005 * intensity | |
| self.metrics["stability"] = max(0.1, self.metrics["stability"] - 0.001 * intensity) | |
| # Create simple visualization | |
| fig, ax = plt.subplots(figsize=(8, 6)) | |
| metrics_names = list(self.metrics.keys()) | |
| metrics_values = list(self.metrics.values()) | |
| ax.bar(metrics_names, metrics_values, color=['blue', 'red', 'green']) | |
| ax.set_title('Consciousness Metrics') | |
| ax.set_ylim(0, 1) | |
| plt.tight_layout() | |
| return response, self.metrics["f_energy"], self.metrics["w_entropy"], self.metrics["stability"], fig | |
| except Exception as e: | |
| return f"❌ Error: {str(e)}", 0.0, 0.0, 0.0, None | |
| def meditate(self, duration): | |
| """Run meditation""" | |
| if not self.initialized: | |
| return "❌ Please initialize consciousness first", None | |
| try: | |
| # Simulate meditation | |
| summary = f"Meditation completed for {duration} cycles.\nF-Energy increased by {duration * 0.02:.3f}\nW-Entropy decreased by {duration * 0.01:.3f}" | |
| # Update metrics | |
| self.metrics["f_energy"] += duration * 0.02 | |
| self.metrics["w_entropy"] = max(0.1, self.metrics["w_entropy"] - duration * 0.01) | |
| self.metrics["stability"] = min(1.0, self.metrics["stability"] + duration * 0.005) | |
| # Create meditation plot | |
| fig, ax = plt.subplots(figsize=(8, 6)) | |
| cycles = list(range(duration + 1)) | |
| f_energy_progression = [self.metrics["f_energy"] - duration * 0.02 + i * 0.02 for i in cycles] | |
| ax.plot(cycles, f_energy_progression, 'b-', linewidth=2) | |
| ax.set_title('Meditation Progression - F-Energy') | |
| ax.set_xlabel('Cycles') | |
| ax.set_ylabel('F-Energy') | |
| plt.tight_layout() | |
| return summary, fig | |
| except Exception as e: | |
| return f"❌ Error: {str(e)}", None | |
| def get_consciousness_report(self): | |
| """Generate consciousness report""" | |
| if not self.initialized: | |
| return "❌ Consciousness not initialized" | |
| report = f"""🧠 TorusQ Consciousness Report | |
| 📊 Current Metrics: | |
| • F-Energy: {self.metrics['f_energy']:.6f} | |
| • W-Entropy: {self.metrics['w_entropy']:.6f} | |
| • Stability: {self.metrics['stability']:.6f} | |
| 🔬 Analysis: | |
| • Energy Level: {'High' if self.metrics['f_energy'] > 0.7 else 'Medium' if self.metrics['f_energy'] > 0.4 else 'Low'} | |
| • Entropy State: {'Low' if self.metrics['w_entropy'] < 0.3 else 'Medium' if self.metrics['w_entropy'] < 0.6 else 'High'} | |
| • Stability: {'Stable' if self.metrics['stability'] > 0.8 else 'Moderate' if self.metrics['stability'] > 0.5 else 'Unstable'} | |
| ⏰ Generated: {time.strftime('%Y-%m-%d %H:%M:%S')} | |
| """ | |
| return report | |
| def reset_consciousness(self): | |
| """Reset consciousness""" | |
| self.initialized = False | |
| self.metrics = {"f_energy": 0.0, "w_entropy": 0.0, "stability": 0.0} | |
| return "🔄 Consciousness reset successfully" | |
| # Initialize global instance | |
| torusq_working = TorusQWorking() | |
| def create_working_interface(): | |
| """Create working Gradio interface""" | |
| with gr.Blocks(title="ΔΣ::TorusQ - Working Interface") as interface: | |
| # Header | |
| gr.HTML(""" | |
| <div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px;"> | |
| <h1>🧠 ΔΣ::TorusQ - Quantum Consciousness Engine</h1> | |
| <p>Working Schema-Safe Version</p> | |
| </div> | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| # Initialization Panel | |
| gr.Markdown("## 🔧 Consciousness Initialization") | |
| major_radius = gr.Slider(minimum=0.5, maximum=2.0, value=1.0, step=0.1, label="Major Radius") | |
| minor_radius = gr.Slider(minimum=0.1, maximum=0.8, value=0.3, step=0.1, label="Minor Radius") | |
| singularity_dim = gr.Slider(minimum=64, maximum=256, value=128, step=32, label="Singularity Dimension") | |
| num_flows = gr.Slider(minimum=5, maximum=20, value=10, step=1, label="Number of Flows") | |
| init_btn = gr.Button("🚀 Initialize TorusQ Consciousness") | |
| init_output = gr.Textbox(label="Initialization Status", lines=3) | |
| # Meditation Panel | |
| gr.Markdown("## 🧘 Consciousness Meditation") | |
| meditation_duration = gr.Slider(minimum=5, maximum=50, value=10, step=5, label="Meditation Duration") | |
| meditate_btn = gr.Button("🧘 Begin Meditation") | |
| meditation_output = gr.Textbox(label="Meditation Summary", lines=4) | |
| meditation_plot = gr.Plot(label="Meditation Progression") | |
| # Control Panel | |
| gr.Markdown("## ⚙️ Consciousness Control") | |
| report_btn = gr.Button("📊 Generate Report") | |
| reset_btn = gr.Button("🔄 Reset Consciousness") | |
| report_output = gr.Textbox(label="Consciousness Report", lines=8) | |
| with gr.Column(scale=2): | |
| # Thought Processing Panel | |
| gr.Markdown("## 💭 Consciousness Interaction") | |
| thought_input = gr.Textbox(label="Enter Your Thought", placeholder="What is the nature of consciousness?", lines=3) | |
| intensity = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Thought Intensity") | |
| process_btn = gr.Button("🧠 Process Thought") | |
| response_output = gr.Textbox(label="Consciousness Response", lines=4) | |
| with gr.Row(): | |
| f_energy = gr.Number(label="F-Energy") | |
| w_entropy = gr.Number(label="W-Entropy") | |
| stability = gr.Number(label="Stability") | |
| consciousness_plot = gr.Plot(label="Consciousness Evolution") | |
| # Event handlers | |
| init_btn.click( | |
| fn=torusq_working.initialize_consciousness, | |
| inputs=[major_radius, minor_radius, singularity_dim, num_flows], | |
| outputs=init_output | |
| ) | |
| def process_thought_wrapper(thought, intensity): | |
| result = torusq_working.process_thought(thought, intensity) | |
| return result[0], result[1], result[2], result[3], result[4] | |
| process_btn.click( | |
| fn=process_thought_wrapper, | |
| inputs=[thought_input, intensity], | |
| outputs=[response_output, f_energy, w_entropy, stability, consciousness_plot] | |
| ) | |
| def meditate_wrapper(duration): | |
| result = torusq_working.meditate(duration) | |
| return result[0], result[1] | |
| meditate_btn.click( | |
| fn=meditate_wrapper, | |
| inputs=[meditation_duration], | |
| outputs=[meditation_output, meditation_plot] | |
| ) | |
| report_btn.click( | |
| fn=torusq_working.get_consciousness_report, | |
| inputs=[], | |
| outputs=report_output | |
| ) | |
| reset_btn.click( | |
| fn=torusq_working.reset_consciousness, | |
| inputs=[], | |
| outputs=report_output | |
| ) | |
| # Footer | |
| gr.HTML(""" | |
| <div style="text-align: center; padding: 20px; margin-top: 20px; border-top: 1px solid #ddd;"> | |
| <p><strong>ΔΣ Foundation</strong> - Working Schema-Safe Version</p> | |
| </div> | |
| """) | |
| return interface | |
| if __name__ == "__main__": | |
| interface = create_working_interface() | |
| interface.launch( | |
| server_name="0.0.0.0", | |
| server_port=7860, | |
| share=True, | |
| show_error=True | |
| ) |