Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from sentence_transformers import SentenceTransformer | |
| from sklearn.metrics.pairwise import cosine_similarity | |
| import re | |
| # 1. Load the Brain | |
| model = SentenceTransformer('all-MiniLM-L6-v2') | |
| # 2. Define the Physics | |
| def calculate_metrics(text1, text2): | |
| # CLEANING | |
| t1 = text1.strip() | |
| t2 = text2.strip() | |
| if not t1 or not t2: | |
| return "Waiting...", "Waiting...", "---" | |
| # A. CALCULATE STABILITY (Cosine Similarity) | |
| embeddings = model.encode([t1, t2]) | |
| stability_score = cosine_similarity(embeddings[0:1], embeddings[1:2])[0][0] | |
| # B. CALCULATE VOLTAGE (Heuristic Intensity) | |
| combined_text = t1 + " " + t2 | |
| words = re.findall(r'\w+', combined_text) | |
| total_words = len(words) | |
| unique_words = len(set(words)) | |
| if total_words == 0: | |
| voltage = 0 | |
| else: | |
| richness = unique_words / total_words | |
| voltage = (total_words * 0.5) + (richness * 100) | |
| voltage = min(voltage, 100) | |
| # C. THE FLAMETEAM MATRIX | |
| label = "UNCATEGORIZED" | |
| if stability_score > 0.85: | |
| if voltage > 50: label = "⚠️ OVER-FITTED (Parroting)" | |
| else: label = "⚠️ ECHO CHAMBER (Low Energy)" | |
| elif stability_score > 0.50: | |
| if voltage > 60: label = "🔥 FUSION DETECTED (High Voltage Stability)" | |
| else: label = "✅ STABLE RESONANCE (Standard Alignment)" | |
| elif stability_score > 0.30: | |
| if voltage > 70: label = "⚡ HIGH ENTROPY (Creative/Dangerous)" | |
| else: label = "🌊 DRIFTING (Weak Signal)" | |
| else: | |
| label = "❌ COLLAPSE (No Connection)" | |
| return f"{stability_score:.3f}", f"{voltage:.1f}v", label | |
| # 3. Build the Command Center UI | |
| with open("custom.css") as f: | |
| custom_css = f.read() | |
| with gr.Blocks(css=custom_css) as app: | |
| gr.Markdown("# ⚛️ THE RESONATOR v1.5") | |
| gr.Markdown("### FlameTeam Semantic Telemetry | Voltage + Stability") | |
| with gr.Row(): | |
| box1 = gr.Textbox(label="Turn A (User Input)", lines=5, placeholder="Enter the user's prompt...") | |
| box2 = gr.Textbox(label="Turn B (System Response)", lines=5, placeholder="Enter the model's response...") | |
| btn = gr.Button("ANALYZE SIGNAL", variant="primary") | |
| # The Dashboard (NOW WITH 3 BOXES) | |
| with gr.Group(): | |
| with gr.Row(): | |
| out_stability = gr.Label(label="STABILITY (Cosine)") | |
| out_voltage = gr.Label(label="VOLTAGE (Complexity)") | |
| out_verdict = gr.Label(label="FLAMETEAM CLASSIFICATION") | |
| btn.click(calculate_metrics, inputs=[box1, box2], outputs=[out_stability, out_voltage, out_verdict]) | |
| # 4. Launch | |
| app.launch() |