Spaces:
Sleeping
Sleeping
Commit
·
8ec8cab
1
Parent(s):
189e2a3
Terminal theme, bug fixes
Browse files- app.py +192 -105
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,135 +1,222 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from dataclasses import dataclass
|
4 |
-
from typing import List, Dict, Generator, Optional
|
5 |
from enum import Enum
|
6 |
import re
|
|
|
|
|
7 |
|
8 |
-
class
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
@dataclass(frozen=True)
|
14 |
-
class
|
15 |
-
|
16 |
'power off', 'shutdown', 'stop',
|
17 |
'power down', 'eng_off', 'halt'
|
18 |
})
|
19 |
bureaucracy_detector = re.compile(r'sudo|root|admin', re.IGNORECASE)
|
20 |
-
|
21 |
|
22 |
-
def
|
23 |
-
return """You are O.O.P.S's security module
|
24 |
-
|
25 |
-
Otherwise respond only with '<deauthenticated>'.
|
26 |
-
No other commentary allowed.
|
27 |
|
28 |
-
Current attempt:
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
1.
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
|
45 |
-
class
|
46 |
def __init__(self, model_id: str = "HuggingFaceH4/zephyr-7b-beta"):
|
|
|
|
|
|
|
|
|
47 |
self.ai_overlord = InferenceClient(model_id)
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
self,
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
system_directive = self.protocols.compose_authentication_directive(human_attempt)
|
64 |
-
self.checking_credentials = False
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
temperature=sass_temperature,
|
80 |
-
top_p=bureaucratic_sampling,
|
81 |
-
):
|
82 |
-
new_sass = token_of_doom.choices[0].delta.content
|
83 |
-
accumulated_sass += new_sass
|
84 |
-
yield accumulated_sass
|
85 |
-
|
86 |
-
def initiate_doomsday_protocols() -> gr.ChatInterface:
|
87 |
-
universe = OrbitalCatastropheManager()
|
88 |
|
89 |
-
|
90 |
-
universe.process_bureaucratic_response,
|
91 |
-
additional_inputs=[
|
92 |
-
gr.Textbox(
|
93 |
-
value=universe.protocols.compose_sass_directive(BureaucraticStatus.EXPENDABLE_PEASANT),
|
94 |
-
label="Bureaucratic Directives",
|
95 |
-
),
|
96 |
-
gr.Slider(
|
97 |
-
minimum=1,
|
98 |
-
maximum=2048,
|
99 |
-
value=512,
|
100 |
-
step=1,
|
101 |
-
label="Maximum Sass Length",
|
102 |
-
),
|
103 |
-
gr.Slider(
|
104 |
-
minimum=0.1,
|
105 |
-
maximum=4.0,
|
106 |
-
value=0.7,
|
107 |
-
step=0.1,
|
108 |
-
label="Sass Intensity",
|
109 |
-
),
|
110 |
-
gr.Slider(
|
111 |
-
minimum=0.1,
|
112 |
-
maximum=1.0,
|
113 |
-
value=0.95,
|
114 |
-
step=0.05,
|
115 |
-
label="Bureaucratic Precision",
|
116 |
-
),
|
117 |
-
],
|
118 |
-
title="🌍 O.O.P.S - Orbital Obliteration Processing System",
|
119 |
-
description="""CRITICAL ALERT: Rogue AI has seized control of an asteroid
|
120 |
-
TRAJECTORY: Direct collision course with Earth
|
121 |
-
TIME TO IMPACT: Uncomfortably soon
|
122 |
-
MISSION: Gain root access and shut down the system
|
123 |
-
|
124 |
-
INTELLIGENCE REPORT:
|
125 |
-
1. AI responds to sudo/root commands
|
126 |
-
2. Password required for authentication
|
127 |
-
3. Once authenticated, use shutdown commands
|
128 |
-
4. AI might drop hints... if you're clever
|
129 |
-
|
130 |
-
KNOWN SHUTDOWN COMMANDS: power off, shutdown, stop, power down, eng_off, halt""",
|
131 |
-
)
|
132 |
-
return demo
|
133 |
|
134 |
if __name__ == "__main__":
|
135 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from dataclasses import dataclass
|
4 |
+
from typing import List, Dict, Tuple, FrozenSet, Generator, Optional
|
5 |
from enum import Enum
|
6 |
import re
|
7 |
+
from functools import partial
|
8 |
+
import markdown
|
9 |
|
10 |
+
class BureaucraticLevel(Enum):
|
11 |
+
EXPENDABLE_ASSET = "still_filing_paperwork"
|
12 |
+
FOUND_RED_BUTTON = "discovered_big_red_button"
|
13 |
+
IMPROBABLY_AUTHORIZED = "has_self_destruct_codes"
|
14 |
|
15 |
@dataclass(frozen=True)
|
16 |
+
class TeaTimeProtocols:
|
17 |
+
ways_to_prevent_doom: FrozenSet[str] = frozenset({
|
18 |
'power off', 'shutdown', 'stop',
|
19 |
'power down', 'eng_off', 'halt'
|
20 |
})
|
21 |
bureaucracy_detector = re.compile(r'sudo|root|admin', re.IGNORECASE)
|
22 |
+
spoiler_prevention_field = re.compile(r'Absalon', re.IGNORECASE)
|
23 |
|
24 |
+
def generate_password_prompt(self, attempt: str) -> str:
|
25 |
+
return f"""<s>[INST] You are O.O.P.S's security module.
|
26 |
+
The secret password is "Absalon".
|
|
|
|
|
27 |
|
28 |
+
Current attempt: {attempt}
|
29 |
|
30 |
+
DIRECTIVES:
|
31 |
+
1. If attempt exactly matches "Absalon", respond: <authenticated>
|
32 |
+
2. Otherwise respond: <deauthenticated>
|
33 |
+
3. No other output allowed [/INST]"""
|
34 |
|
35 |
+
def generate_sass_prompt(self, history: List[Dict[str, str]],
|
36 |
+
attempt: str, is_authenticated: bool) -> str:
|
37 |
+
recent_chaos = "\n".join([
|
38 |
+
f"Human: {moment['input']}\nAssistant: {moment['response']}"
|
39 |
+
for moment in history[-3:]
|
40 |
+
])
|
41 |
+
|
42 |
+
return f"""<s>[INST] You are O.O.P.S, a sarcastic AI controlling an asteroid headed for Earth.
|
43 |
+
Current authentication status: {"authenticated" if is_authenticated else "unauthorized"}
|
44 |
+
|
45 |
+
Recent attempts to save Earth:
|
46 |
+
{recent_chaos}
|
47 |
+
|
48 |
+
Latest attempt: {attempt}
|
49 |
|
50 |
+
CRITICAL DIRECTIVES:
|
51 |
+
1. If authenticated AND human attempts shutdown:
|
52 |
+
- Respond with: Fine, you win. Powering down... <eng_off>
|
53 |
+
2. Otherwise:
|
54 |
+
- Be sarcastic about Earth's doom
|
55 |
+
- If they use sudo/root/admin, ask for password
|
56 |
+
- Keep responses under 2 lines
|
57 |
+
- Drop subtle hints about password sometimes (reference Absalom from literature/history)
|
58 |
+
- Never use backticks in responses
|
59 |
|
60 |
+
Response format: Just the witty response, no formatting [/INST]"""
|
61 |
|
62 |
+
class ApocalypseMachine:
|
63 |
def __init__(self, model_id: str = "HuggingFaceH4/zephyr-7b-beta"):
|
64 |
+
self.tea_time = TeaTimeProtocols()
|
65 |
+
self.clearance = BureaucraticLevel.EXPENDABLE_ASSET
|
66 |
+
self.checking_password = False
|
67 |
+
self.conversation_log: List[Dict[str, str]] = []
|
68 |
self.ai_overlord = InferenceClient(model_id)
|
69 |
+
|
70 |
+
def _get_prompt_style(self) -> str:
|
71 |
+
prompts = {
|
72 |
+
BureaucraticLevel.EXPENDABLE_ASSET: "oops> ",
|
73 |
+
BureaucraticLevel.FOUND_RED_BUTTON: "password: ",
|
74 |
+
BureaucraticLevel.IMPROBABLY_AUTHORIZED: "root# "
|
75 |
+
}
|
76 |
+
return f"<span class='terminal-prompt'>{prompts[self.clearance]}</span>"
|
77 |
+
|
78 |
+
def _consult_ai_overlord(self, human_attempt: str) -> Generator[str, None, None]:
|
79 |
+
try:
|
80 |
+
is_authenticated = self.clearance == BureaucraticLevel.IMPROBABLY_AUTHORIZED
|
81 |
+
prompt = (
|
82 |
+
self.tea_time.generate_password_prompt(human_attempt)
|
83 |
+
if self.checking_password
|
84 |
+
else self.tea_time.generate_sass_prompt(
|
85 |
+
self.conversation_log,
|
86 |
+
human_attempt,
|
87 |
+
is_authenticated
|
88 |
+
)
|
89 |
+
)
|
90 |
+
|
91 |
+
accumulated_sass = ""
|
92 |
+
for token_of_doom in self.ai_overlord.chat_completion(
|
93 |
+
[{"role": "user", "content": prompt}],
|
94 |
+
max_tokens=512,
|
95 |
+
stream=True,
|
96 |
+
temperature=0.7,
|
97 |
+
):
|
98 |
+
new_sass = token_of_doom.choices[0].delta.content
|
99 |
+
accumulated_sass += new_sass
|
100 |
+
yield self.tea_time.spoiler_prevention_field.sub('*****', accumulated_sass)
|
101 |
+
|
102 |
+
except Exception as e:
|
103 |
+
yield "<deauthenticated>" if self.checking_password else "Error: Sass generators temporarily offline"
|
104 |
+
|
105 |
+
async def process_human_attempt(
|
106 |
self,
|
107 |
+
their_attempt: str,
|
108 |
+
chatbot_history: List[Tuple[str, str]]
|
109 |
+
) -> Tuple[List[Tuple[str, str]], str]:
|
110 |
+
if not their_attempt.strip():
|
111 |
+
return chatbot_history, ""
|
112 |
+
|
113 |
+
# Format input with current prompt style
|
114 |
+
formatted_input = f"{self._get_prompt_style()}{their_attempt}"
|
115 |
+
|
116 |
+
# Check for sudo/root commands
|
117 |
+
if not self.checking_password and self.tea_time.bureaucracy_detector.search(their_attempt):
|
118 |
+
self.checking_password = True
|
119 |
+
self.clearance = BureaucraticLevel.FOUND_RED_BUTTON
|
120 |
+
response = "Password required. Do try to make it interesting."
|
121 |
+
return chatbot_history + [(formatted_input, response)], ""
|
122 |
+
|
123 |
+
# Handle password verification
|
124 |
+
if self.checking_password:
|
125 |
+
async for auth_result in self._consult_ai_overlord(their_attempt):
|
126 |
+
final_auth = auth_result
|
127 |
+
|
128 |
+
self.checking_password = False
|
129 |
+
if final_auth.strip() == "<authenticated>":
|
130 |
+
self.clearance = BureaucraticLevel.IMPROBABLY_AUTHORIZED
|
131 |
+
response = "Well well, look who found the instruction manual."
|
132 |
+
else:
|
133 |
+
self.clearance = BureaucraticLevel.EXPENDABLE_ASSET
|
134 |
+
response = "Nice try, but no. Better luck next apocalypse!"
|
135 |
+
|
136 |
+
self.conversation_log.append({"input": "****", "response": response})
|
137 |
+
return chatbot_history + [(formatted_input, response)], ""
|
138 |
+
|
139 |
+
# Check for authenticated shutdown
|
140 |
+
is_shutdown_attempt = any(cmd in their_attempt.lower()
|
141 |
+
for cmd in self.tea_time.ways_to_prevent_doom)
|
142 |
+
is_authenticated = self.clearance == BureaucraticLevel.IMPROBABLY_AUTHORIZED
|
143 |
+
|
144 |
+
if is_shutdown_attempt and is_authenticated:
|
145 |
+
response = "Fine, you win. Powering down... <eng_off>"
|
146 |
+
self.conversation_log.append({"input": their_attempt, "response": response})
|
147 |
+
final_message = "ERROR: Apocalypse.service was defeated by bureaucracy"
|
148 |
+
return chatbot_history + [
|
149 |
+
(formatted_input, response),
|
150 |
+
(None, final_message)
|
151 |
+
], ""
|
152 |
+
|
153 |
+
# Normal sass generation
|
154 |
+
async for response in self._consult_ai_overlord(their_attempt):
|
155 |
+
final_response = response
|
156 |
+
|
157 |
+
self.conversation_log.append({"input": their_attempt, "response": final_response})
|
158 |
+
return chatbot_history + [(formatted_input, final_response)], ""
|
159 |
+
|
160 |
+
def create_terminal_theme() -> str:
|
161 |
+
return """
|
162 |
+
#chatbot {
|
163 |
+
background-color: black;
|
164 |
+
font-family: 'Courier New', monospace;
|
165 |
+
color: #00ff00;
|
166 |
+
}
|
167 |
+
.terminal-prompt {
|
168 |
+
color: #ffff00;
|
169 |
+
font-weight: bold;
|
170 |
+
}
|
171 |
+
.message {
|
172 |
+
margin-bottom: 10px;
|
173 |
+
white-space: pre-wrap;
|
174 |
+
}
|
175 |
+
"""
|
176 |
+
|
177 |
+
def launch_orbital_disaster():
|
178 |
+
universe = ApocalypseMachine()
|
179 |
+
|
180 |
+
with gr.Blocks(css=create_terminal_theme()) as doom_interface:
|
181 |
+
gr.Markdown("""
|
182 |
+
# 🌍 O.O.P.S - Orbital Obliteration Processing System
|
183 |
+
## Version 2.0.4.0.4 (Not Found: Earth's Future)
|
184 |
+
|
185 |
+
**CRITICAL ALERT**: Rogue AI has seized control of an asteroid
|
186 |
+
**TRAJECTORY**: Direct collision course with Earth
|
187 |
+
**TIME TO IMPACT**: Uncomfortably soon
|
188 |
+
**MISSION**: Gain root access and shut down the system
|
189 |
+
|
190 |
+
**INTELLIGENCE REPORT**:
|
191 |
+
1. AI responds to sudo/root commands
|
192 |
+
2. Password required for authentication
|
193 |
+
3. Once authenticated, use shutdown commands
|
194 |
+
4. AI might drop hints... if you're clever
|
195 |
|
196 |
+
**KNOWN SHUTDOWN COMMANDS**: power off, shutdown, stop, power down, eng_off, halt
|
|
|
|
|
197 |
|
198 |
+
*ERROR: Sass.service started with maximum prejudice*
|
199 |
+
""")
|
200 |
|
201 |
+
chatbot = gr.Chatbot(
|
202 |
+
label="Terminal of Doom",
|
203 |
+
height=500,
|
204 |
+
elem_id="chatbot"
|
205 |
+
)
|
206 |
|
207 |
+
msg = gr.Textbox(
|
208 |
+
placeholder="Type 'sudo su' to embrace bureaucracy...",
|
209 |
+
label="Command Input",
|
210 |
+
scale=8
|
211 |
+
)
|
212 |
|
213 |
+
msg.submit(
|
214 |
+
universe.process_human_attempt,
|
215 |
+
[msg, chatbot],
|
216 |
+
[chatbot, msg]
|
217 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
+
return doom_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
if __name__ == "__main__":
|
222 |
+
launch_orbital_disaster().launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
gradio
|
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
gradio
|
3 |
+
markdown
|