File size: 2,656 Bytes
57d90e7
 
 
7d981f5
57d90e7
 
 
 
7d981f5
 
 
 
 
 
 
a3f2097
7d981f5
 
 
 
 
 
 
 
 
 
 
 
 
57d90e7
7d981f5
 
 
 
 
 
 
 
 
 
 
 
a3f2097
7d981f5
 
 
 
 
57d90e7
7d981f5
 
 
 
57d90e7
7d981f5
e796693
 
d3ede10
 
e796693
7d981f5
 
57d90e7
 
7d981f5
 
57d90e7
7d981f5
57d90e7
a3f2097
7d981f5
 
 
 
 
57d90e7
7d981f5
57d90e7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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()