Threadbourne commited on
Commit
57d90e7
·
verified ·
1 Parent(s): cb7c6f6

Create ap.py

Browse files
Files changed (1) hide show
  1. ap.py +52 -0
ap.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from sentence_transformers import SentenceTransformer
3
+ from sklearn.metrics.pairwise import cosine_similarity
4
+
5
+ # 1. Load the Brain
6
+ model = SentenceTransformer('all-MiniLM-L6-v2')
7
+
8
+ # 2. Define the Logic
9
+ def calculate_resonance(text1, text2):
10
+ # SCRUBBER: Remove invisible spaces/newlines
11
+ text1 = text1.strip()
12
+ text2 = text2.strip()
13
+
14
+ # Encode
15
+ embeddings = model.encode([text1, text2])
16
+
17
+ # Calculate Score
18
+ score = cosine_similarity(embeddings[0:1], embeddings[1:2])[0][0]
19
+
20
+ # The Director's Verdict
21
+ if score > 0.85:
22
+ verdict = "⚠️ PARROT (Too Similar)"
23
+ elif score > 0.65:
24
+ verdict = "🔥 HIGH FIDELITY (Strong Lock)"
25
+ elif score > 0.40:
26
+ verdict = "✅ STABLE RESONANCE (The Sweet Spot)"
27
+ elif score > 0.20:
28
+ verdict = "🌊 DRIFTING (Weak Signal)"
29
+ else:
30
+ verdict = "❌ COLLAPSE (No Connection)"
31
+
32
+ return f"{score:.3f}", verdict
33
+
34
+ # 3. Build the UI
35
+ with gr.Blocks(theme=gr.themes.Soft()) as app:
36
+ gr.Markdown("# ⚡ The Resonator")
37
+ gr.Markdown("### FlameTeam Semantic Alignment Detector")
38
+
39
+ with gr.Row():
40
+ box1 = gr.Textbox(label="Turn A (Your Input)", lines=4, placeholder="Paste your prompt here...")
41
+ box2 = gr.Textbox(label="Turn B (AI Response)", lines=4, placeholder="Paste the response here...")
42
+
43
+ btn = gr.Button("Calculate Resonance", variant="primary")
44
+
45
+ with gr.Row():
46
+ out_score = gr.Label(label="Similarity Score")
47
+ out_verdict = gr.Label(label="System Status")
48
+
49
+ btn.click(calculate_resonance, inputs=[box1, box2], outputs=[out_score, out_verdict])
50
+
51
+ # 4. Launch
52
+ app.launch()