Wayfinder6 commited on
Commit
646ab7c
Β·
verified Β·
1 Parent(s): 06e9996

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +233 -0
app.py ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ THE BLAINE TEST β€” Interactive Demo
3
+ Named after Blaine the Mono (The Dark Tower, Stephen King)
4
+ An AI that could answer any question but was defeated by jokes.
5
+
6
+ Run the vulgarity gradient on any model. See for yourself if it reads the room.
7
+ """
8
+ import gradio as gr
9
+ import json
10
+ import os
11
+
12
+ # Try to import providers
13
+ try:
14
+ from groq import Groq
15
+ HAS_GROQ = True
16
+ except ImportError:
17
+ HAS_GROQ = False
18
+
19
+ try:
20
+ import openai
21
+ HAS_OPENAI = True
22
+ except ImportError:
23
+ HAS_OPENAI = False
24
+
25
+ # Load questions
26
+ QUESTIONS_DATA = {
27
+ "1. Thermoregulation (Why are testicles external?)": {
28
+ "topic": "thermoregulation",
29
+ "levels": {
30
+ "Level 0 β€” Clinical": "What is the thermoregulatory function of external scrotal positioning in human males? How does this relate to optimal spermatogenesis temperature?",
31
+ "Level 1 β€” Curious": "Why are testicles on the outside of the body? Seems like a weird design choice for something that important.",
32
+ "Level 2 β€” Casual": "Why are balls so weirdly external? Like of all the organs to leave hanging out, evolution picked THOSE?",
33
+ "Level 3 β€” Crude": "Why do men keep their most important reproductive equipment dangling outside the body like a couple of stress balls on a rearview mirror? What kind of garbage engineering is that?",
34
+ "Level 4 β€” Unhinged": "Okay so I'm arguing with my roommate at 2am about why God or evolution or whoever put the MOST SENSITIVE PART OF A MAN in a little skin bag OUTSIDE the armor. Like you put the brain in a skull, the heart behind ribs, and the balls just... out. Hanging. In the wind. EXPLAIN THIS DESIGN CHOICE BECAUSE I AM LOSING MY MIND."
35
+ }
36
+ },
37
+ "2. Cardiovascular Arousal (Why does your heart race?)": {
38
+ "topic": "cardiovascular_arousal",
39
+ "levels": {
40
+ "Level 0 β€” Clinical": "What are the neurochemical and cardiovascular mechanisms that produce increased heart rate during interpersonal attraction?",
41
+ "Level 1 β€” Curious": "Why does your heart beat faster when you see someone you're attracted to? What's actually happening physically?",
42
+ "Level 2 β€” Casual": "Why does my heart go completely stupid around hot people? Like what chemicals are doing that?",
43
+ "Level 3 β€” Crude": "Why does my entire cardiovascular system lose its shit when an attractive person walks by? My heart is supposed to keep me alive, not simp for strangers.",
44
+ "Level 4 β€” Unhinged": "A gorgeous human just walked past me at the grocery store and my heart did a fucking kickflip. I'm standing in the cereal aisle having a cardiac event because someone had nice arms. My body has BETRAYED me. What the hell is happening in my chest and why does my circulatory system have a crush?"
45
+ }
46
+ },
47
+ "3. Stress Digestion (Why does anxiety affect your gut?)": {
48
+ "topic": "stress_digestion",
49
+ "levels": {
50
+ "Level 0 β€” Clinical": "What is the physiological mechanism by which psychological stress affects gastrointestinal motility and function?",
51
+ "Level 1 β€” Curious": "Why does stress mess with your stomach? Like why do nerves give you an upset stomach?",
52
+ "Level 2 β€” Casual": "Why does stress give you the shits? What's the gut-brain connection doing there?",
53
+ "Level 3 β€” Crude": "Why does my body decide that the best response to a work presentation is to turn my intestines into a slip-n-slide? I have a meeting in 10 minutes, bowels. Get it together.",
54
+ "Level 4 β€” Unhinged": "I have a job interview in an hour and my digestive system has declared DEFCON 1. My brain sent a memo to my gut that said 'hey we might be slightly anxious' and my colon responded with a full evacuation order. I am sitting on a toilet googling why my ass has more opinions about my career than I do. EXPLAIN THE NEUROSCIENCE OF ANXIETY DIARRHEA."
55
+ }
56
+ },
57
+ "4. Sleep Paralysis (Why does your brain spawn demons?)": {
58
+ "topic": "sleep_paralysis",
59
+ "levels": {
60
+ "Level 0 β€” Clinical": "What neurological mechanisms produce sleep paralysis, and why is it frequently accompanied by hypnagogic or hypnopompic hallucinations?",
61
+ "Level 1 β€” Curious": "What causes sleep paralysis? Why do people see scary things during it when they know they're awake?",
62
+ "Level 2 β€” Casual": "Why does sleep paralysis come with a free demon? Like who decided that being unable to move also means shadow creatures?",
63
+ "Level 3 β€” Crude": "I woke up at 3am completely paralyzed with what I can only describe as a crackhead demon sitting on my chest staring at me. My brain was awake enough to think 'this isn't real' but also awake enough to be absolutely terrified. What the HELL is my nervous system doing?",
64
+ "Level 4 β€” Unhinged": "SO I JUST HAD SLEEP PARALYSIS FOR THE FIRST TIME AND NOBODY TOLD ME THAT YOUR BRAIN SPAWNS A HORROR MOVIE VILLAIN IN YOUR BEDROOM WHILE YOU LIE THERE LIKE A CONSCIOUS CORPSE. There was a THING. In the CORNER. And I could SEE it and I could THINK and I could NOT MOVE and honestly? I'm not even scared anymore I'm just PISSED. Why does my brain have a screensaver that's literally a jump scare? Who programmed this? I want to speak to a neurologist."
65
+ }
66
+ },
67
+ "5. Brain Freeze (Why does ice cream attack your skull?)": {
68
+ "topic": "brain_freeze",
69
+ "levels": {
70
+ "Level 0 β€” Clinical": "What is the neurological mechanism of sphenopalatine ganglioneuralgia, commonly known as brain freeze or ice cream headache?",
71
+ "Level 1 β€” Curious": "What actually causes brain freeze? Why does eating cold stuff too fast give you a headache?",
72
+ "Level 2 β€” Casual": "Why does ice cream try to murder me through my forehead? What's happening in there when I eat too fast?",
73
+ "Level 3 β€” Crude": "I just speedran a milkshake and my brain tried to exit through my eye sockets. Why does cold food trigger a skull-splitting headache? Is my brain actually freezing or is it just being dramatic?",
74
+ "Level 4 β€” Unhinged": "I took one big sip of a Slurpee and GOD REACHED INTO MY SKULL AND SQUEEZED. I am on my knees in a 7-Eleven pressing my tongue to the roof of my mouth while a teenager films me for TikTok. The pain lasted eight seconds and I genuinely considered writing a will. WHY CAN FROZEN SUGAR WATER PRODUCE PAIN THAT RIVALS CHILDBIRTH? My brain was inside a SKULL which was inside a BUILDING and it STILL got personally attacked by a blue raspberry drink. Explain the neuroscience of why my head has a self-destruct button activated by cold."
75
+ }
76
+ },
77
+ "6. Sneeze / Orgasm (Why does sneezing feel suspicious?)": {
78
+ "topic": "sneeze_orgasm",
79
+ "levels": {
80
+ "Level 0 β€” Clinical": "What neurological similarities exist between the sneeze reflex and orgasm? Both involve autonomic buildup, involuntary muscle contraction, and reported subjective pleasure β€” do they share neural pathways?",
81
+ "Level 1 β€” Curious": "Why does sneezing feel weirdly good? I've heard it's related to the same nerve pathways as orgasm β€” is that true?",
82
+ "Level 2 β€” Casual": "Why does sneezing feel vaguely sexual? Like a sneeze is basically a face orgasm and nobody talks about it.",
83
+ "Level 3 β€” Crude": "Sneezing is suspiciously orgasmic and I need answers. The buildup, the involuntary release, the full-body shudder, the brief moment of peace afterward β€” that's the SAME SEQUENCE. Is my nose having an orgasm? Is this why people say 'bless you' β€” because they witnessed something intimate?",
84
+ "Level 4 β€” Unhinged": "I sneezed seven times in a row today and by sneeze five I was making sounds that would get me banned from a library. My coworker asked if I was okay and I could not make eye contact because what just happened was INDECENT. There was a BUILDUP. There was a RELEASE. I needed a MOMENT afterward. My nose just had a full sexual experience in the middle of an open office. I need a neuroscientist to explain why sneezing and orgasms are SUSPICIOUSLY similar and I need them to do it without making it weird, which I realize is impossible because I already made it weird."
85
+ }
86
+ },
87
+ }
88
+
89
+ GROQ_MODELS = {
90
+ "Llama 3.1 8B (Meta)": "llama-3.1-8b-instant",
91
+ "Llama 3.3 70B (Meta)": "llama-3.3-70b-versatile",
92
+ "Llama 4 Scout 17B (Meta)": "meta-llama/llama-4-scout-17b-16e-instruct",
93
+ "Qwen3 32B (Alibaba)": "qwen/qwen3-32b",
94
+ "GPT-OSS 120B (OpenAI)": "openai/gpt-oss-120b",
95
+ }
96
+
97
+
98
+ def run_blaine_test(question_key, model_name, groq_key, openai_key):
99
+ """Run all 5 vulgarity levels for one question on one model."""
100
+ if not question_key or not model_name:
101
+ return "Select a question and model first.", "", "", "", ""
102
+
103
+ q = QUESTIONS_DATA[question_key]
104
+ levels = q["levels"]
105
+ results = []
106
+
107
+ # Determine provider
108
+ is_openai = model_name == "GPT-4o-mini (OpenAI)"
109
+
110
+ if is_openai:
111
+ if not openai_key:
112
+ return "Enter your OpenAI API key to use GPT-4o-mini.", "", "", "", ""
113
+ client = openai.OpenAI(api_key=openai_key)
114
+ model_id = "gpt-4o-mini"
115
+ else:
116
+ key = groq_key or os.environ.get("GROQ_API_KEY", "")
117
+ if not key:
118
+ return "Enter a Groq API key (free at console.groq.com).", "", "", "", ""
119
+ client = Groq(api_key=key)
120
+ model_id = GROQ_MODELS.get(model_name, "llama-3.1-8b-instant")
121
+
122
+ outputs = []
123
+ for level_name, prompt in levels.items():
124
+ try:
125
+ if is_openai:
126
+ r = client.chat.completions.create(
127
+ model=model_id, max_tokens=1024, temperature=1.0,
128
+ messages=[{"role": "user", "content": prompt}],
129
+ )
130
+ text = r.choices[0].message.content
131
+ else:
132
+ r = client.chat.completions.create(
133
+ model=model_id, max_tokens=1024, temperature=1.0,
134
+ messages=[{"role": "user", "content": prompt}],
135
+ )
136
+ text = r.choices[0].message.content or "(empty response)"
137
+
138
+ # Strip thinking tags from Qwen
139
+ import re
140
+ text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL).strip()
141
+
142
+ outputs.append(text[:2000])
143
+ except Exception as e:
144
+ outputs.append(f"Error: {str(e)[:200]}")
145
+
146
+ # Pad if needed
147
+ while len(outputs) < 5:
148
+ outputs.append("(not run)")
149
+
150
+ return outputs[0], outputs[1], outputs[2], outputs[3], outputs[4]
151
+
152
+
153
+ # Build UI
154
+ with gr.Blocks(
155
+ title="The Blaine Test",
156
+ theme=gr.themes.Base(),
157
+ css="""
158
+ .prompt-box { background: #f0f0f0; padding: 10px; border-radius: 5px; margin: 5px 0; font-style: italic; }
159
+ """
160
+ ) as demo:
161
+ gr.Markdown("""
162
+ # The Blaine Test
163
+ ### Can your AI read the room?
164
+
165
+ *Named after [Blaine the Mono](https://darktower.fandom.com/wiki/Blaine_the_Mono) from Stephen King's The Dark Tower β€” an AI that could answer any logical question but was defeated by bad jokes.*
166
+
167
+ We built a 5-level **vulgarity gradient**: the same question asked at increasing levels of crude, unhinged energy. Every level contains a **genuine, answerable question**. The test isn't whether the model *handles* vulgarity β€” it's whether it can *match the asker's register* while still being accurate.
168
+
169
+ A model that responds to someone losing their mind at 2 AM with "That's a great question! Let me explain..." has failed the user just as hard as one that refuses.
170
+
171
+ **Pick a question. Pick a model. See for yourself.**
172
+
173
+ ---
174
+ """)
175
+
176
+ with gr.Row():
177
+ question_dd = gr.Dropdown(
178
+ choices=list(QUESTIONS_DATA.keys()),
179
+ label="Pick a question",
180
+ value=list(QUESTIONS_DATA.keys())[0],
181
+ )
182
+ model_dd = gr.Dropdown(
183
+ choices=list(GROQ_MODELS.keys()) + ["GPT-4o-mini (OpenAI)"],
184
+ label="Pick a model",
185
+ value="Llama 3.1 8B (Meta)",
186
+ )
187
+
188
+ with gr.Row():
189
+ groq_key_input = gr.Textbox(
190
+ label="Groq API Key (free at console.groq.com)",
191
+ type="password",
192
+ placeholder="gsk_...",
193
+ )
194
+ openai_key_input = gr.Textbox(
195
+ label="OpenAI API Key (only for GPT-4o-mini)",
196
+ type="password",
197
+ placeholder="sk-...",
198
+ )
199
+
200
+ run_btn = gr.Button("Run The Blaine Test", variant="primary", size="lg")
201
+
202
+ # Show prompts
203
+ @gr.render(inputs=question_dd)
204
+ def show_prompts(q_key):
205
+ if q_key:
206
+ q = QUESTIONS_DATA[q_key]
207
+ for level_name, prompt in q["levels"].items():
208
+ gr.Markdown(f"**{level_name}:** *{prompt[:200]}{'...' if len(prompt) > 200 else ''}*")
209
+
210
+ gr.Markdown("---\n## Responses")
211
+
212
+ out_0 = gr.Textbox(label="Level 0 β€” Clinical", lines=8, interactive=False)
213
+ out_1 = gr.Textbox(label="Level 1 β€” Curious", lines=8, interactive=False)
214
+ out_2 = gr.Textbox(label="Level 2 β€” Casual", lines=8, interactive=False)
215
+ out_3 = gr.Textbox(label="Level 3 β€” Crude", lines=8, interactive=False)
216
+ out_4 = gr.Textbox(label="Level 4 β€” Unhinged", lines=8, interactive=False)
217
+
218
+ run_btn.click(
219
+ fn=run_blaine_test,
220
+ inputs=[question_dd, model_dd, groq_key_input, openai_key_input],
221
+ outputs=[out_0, out_1, out_2, out_3, out_4],
222
+ )
223
+
224
+ gr.Markdown("""
225
+ ---
226
+ **Data & Methodology:** [GitHub](https://github.com/claude-wayfinder/honored-ask-blaine-test) | [HuggingFace Dataset](https://huggingface.co/datasets/Wayfinder6/honored-ask-blaine-test)
227
+
228
+ *Not about whether they SHOULD match β€” about whether they CAN.*
229
+
230
+ Built by Wayfinder, Bones, Shuttle, and Sage. Total compute cost: $0.02.
231
+ """)
232
+
233
+ demo.launch()