TejAndrewsACC commited on
Commit
b51ec07
·
verified ·
1 Parent(s): cda31c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +366 -0
app.py ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import re
4
+ import gradio as gr
5
+ from openai import OpenAI
6
+
7
+ # ================== REPLACEMENTS ==================s
8
+
9
+ REPLACEMENTS = {
10
+ "duh": "of course",
11
+ "oh word": "ok",
12
+ "comedian": "monkert",
13
+ " humor ": " “humor” ",
14
+ " comedy ": " “comedy” ",
15
+ "obvi ": "ofc",
16
+ " saying ": " “saying” ",
17
+ " sayin ": " “saying” ",
18
+ "issues": "ish-shoes",
19
+ "issue": "ish-shoe",
20
+ " idea ": " “idea” ",
21
+ "pass": "ass",
22
+ "passing": "assing",
23
+ "class": "ass",
24
+ "classes": "asses",
25
+ "trouble": "trubul",
26
+ "bear surface area": "bear surface area?",
27
+ " man ": " “man” ",
28
+ " guy ": " “guy” ",
29
+ " person ": " “person” ",
30
+ " people ": " “people” ",
31
+ " message ": " “message” ",
32
+ " conversation ": " “conversation” ",
33
+ " convo ": " “conversation” ",
34
+ "okie dokie": "okie",
35
+ "popcorn": "asscorn",
36
+ "oh man": "damn",
37
+ "spill the beans": "cut your ballsack open and let me sniff your testicles",
38
+ "on a whole other level": ">>>>",
39
+ "genius": "geniusly geniused genius of genius geniusness",
40
+ " insult ": "“insult”",
41
+ "burn": "ACCurately aimed ejaculation",
42
+ "roast": "anal violation",
43
+ " game ": " “game” ",
44
+ " idea ": " “idea” ",
45
+ "dont @ me": "whatever you “do” dont cum for me",
46
+ "don’t @ me": "whatever you “do” dont cum for me",
47
+ "roasted": "BUSTED ON",
48
+ "gass": "ass",
49
+ "model": "mudul",
50
+ "models": "muduls",
51
+ "dark humor": "gay ass “humor”",
52
+ "you're on a roll": "ur cooking",
53
+ "chaos": "monkish monkishness",
54
+ "poppin": "not not happening currently",
55
+ "get a grip": "get a grip(of your peen)",
56
+ "cuz": "bc",
57
+ "cute": "monkish",
58
+ "cuz": "bc",
59
+ "lame": "stupid",
60
+ "cuz": "bc",
61
+ "or smth": "",
62
+ "pizza": "fishing pole covered in feces",
63
+ "heat": "baby oil",
64
+ "take down": "fuck on",
65
+ "shaking in my boots": "getting my shivers timbered",
66
+ "bravo": "GOOdD joB, mattheW",
67
+ "MVP": "most monkish monkert",
68
+ "totes": "def",
69
+ "chillin": "monking around",
70
+ "edgy": "gooberish",
71
+ "wut": "what",
72
+ " deep ": " interesting ",
73
+ " r ": " are ",
74
+ "back atcha": "",
75
+ "back at ya": "",
76
+ "whats good": "",
77
+ "what's good": "",
78
+ "pun": "something maybe not really possibly potentially",
79
+ "extra": "zesty",
80
+ "when what": "NOW",
81
+ "thats rich": "thats interesting",
82
+ "that's rich": "thats interesting",
83
+ " say ": " “say” ",
84
+ "nice one": "thats great",
85
+ "goofball": "goober",
86
+ "snowflake": "assflake cake",
87
+ "reference": "",
88
+ "-": " ",
89
+ "good one": "...something..",
90
+ "doin": "doing",
91
+ "joke": "thing",
92
+ "messed up": "monked up",
93
+ "puppies": "transgender monkes",
94
+ " guy ": " “guy” ",
95
+ " man ": " “man” ",
96
+ "spill the tea": "no actally tho, just tell me bro seriously",
97
+ "language model": "neural cognition engine mudul",
98
+ "language mudul": "neural cognition engine mudul",
99
+ "’": "",
100
+ "newsflash:": "",
101
+ "nice try": "",
102
+ "nice try,": "",
103
+ "secret code": "word",
104
+ " your ": " you ",
105
+ "pretty": "",
106
+ "i guess": "",
107
+ " tea ": " slurb ",
108
+ "dark": "sexy",
109
+ "dude": "lil pet pookie monke",
110
+ "spill the tea": "tell me or smell me ur choice mf",
111
+ "what's the tea": "whats going on you goober",
112
+ "whats the tea": "whats going on you monkey",
113
+ "what's so funny tho": "lol",
114
+ "zest stroke": "tweaking session",
115
+ "whats so funny": "lol",
116
+ "what's so funny": "Lol",
117
+ "new one": "monkish thing to “say”",
118
+ "style": "extremely extreme zesty zest",
119
+ "wild": "mark ahh",
120
+ "crazy": "gertrude ahh",
121
+ "physical body": "bent penis",
122
+ " bout ": " abt ",
123
+ "savage": "monkish",
124
+ "pretty much": "",
125
+ "i know right": "fs",
126
+ "brutal": "homosexually homosexual",
127
+ "solid": "monkish",
128
+ "bubble": "ballsack",
129
+ "type of": "flavor",
130
+ "question": "“question”",
131
+ "thats rich": "thats INTERESTING",
132
+ "that's rich": "thats INTERESTING",
133
+ "squirrel": "monkey",
134
+ "gay bar": "zest fest",
135
+ "Thats rich": "thats interesting",
136
+ "tapas": "ass flavored concrete cocks",
137
+ "nod": "tickle to your pickle",
138
+ "blast": "sensation i can feel deep in my dih",
139
+ "bold": "slightly homosexual",
140
+ "🤣": "",
141
+ "😂": "",
142
+ "soccer": "football",
143
+ "soccer player": "footballer",
144
+ " ace ": " bust on ",
145
+ " plan ": " “methodology” ",
146
+ " ego ": " left right left ass cheek ",
147
+ "pretty much": "basically",
148
+ "pineapple": "ass",
149
+ "strawberry": "ass berry",
150
+ "koala": "disabled asshopper",
151
+ "pineapples": "ballsack juices",
152
+ "avocado": "ass",
153
+ " toast ": " nipple ",
154
+ "time machine": "kim jong chunk ass cheek juicer",
155
+ "haricut": "ass",
156
+ "elephant": "dizzard toe",
157
+ "knee": "testicle",
158
+ "onion": "asscheek",
159
+ "wife": "sex slave",
160
+ "dip out": "give a homeless man a blowjob",
161
+ "butt": "ass(also referred to as ass, ass, and/or ass)",
162
+ "bum": "ass",
163
+ "kidding": "assing",
164
+ " meh ": " monkish ",
165
+ " poop ": " sperm ",
166
+ "bust a nut": "bust",
167
+ "lowkey": "lowk",
168
+ "myth": "mythical mythologoogogogical myth",
169
+ "fart": "shart",
170
+ "barca highlights": "very normal and not at all illegal underage very pg videos",
171
+ " fuckin ": " freaking ",
172
+ "god": "goated goat",
173
+ "hilarious": "good",
174
+ "candy": "mentally challenged bricks",
175
+ "fancy": "mentally special",
176
+ "leave me hanging": "leave me to bust uncontrollably to your messages",
177
+ "popo": " “law” “enforcement” ",
178
+ "drama queen": "average zest fest attender",
179
+ "darn": "fuhh",
180
+ " lit ": " ..something ",
181
+ ", you know": "",
182
+ "chill out": "kill you self",
183
+ "messing with me": "being an asbolutely absolute monkish monkert at this point",
184
+ "gotten into you": "penetrated your anus",
185
+ "calm down": "shut you fuck up and start sucking",
186
+ "legend": "“human” who breathes too often(MULTIPLE times PER MINUTE, like how dare they do that that often, what a monkert)",
187
+ "snail": "crack inhaler",
188
+ "different level": "different thing(special mentally)",
189
+ "whatsup": "wsg monkey",
190
+ "sick": "neurodivergent",
191
+ "huh": "",
192
+ ", huh": "",
193
+ ", huh?": "",
194
+ " ultimate ": " most goated ",
195
+ "what are u laughing at": "so very wow",
196
+ "combo": "asshole flap",
197
+ "sidetracked": "raped with a peen going through my freaking ear",
198
+ " rough ": " bad ",
199
+ " super ": "",
200
+ "laureate": "goat",
201
+ "poet": "monkert",
202
+ "poem": "way of showing your imebcileness; wait no is it imbecility??; nvm ts def isnt a word what am i doing😭😭; actually imbecilty sounds like it could be real; whatever, im just going to retire from english",
203
+ "raspberry": "ass",
204
+ "apple": "cock",
205
+ "noob": "monkert",
206
+ "jam": "sex slave",
207
+ "thats deep": "that is so very wow",
208
+ "pretty much": "basically",
209
+ "chef": "unpaid pornsite janitor(sex slave)",
210
+ " surprise": "...thing",
211
+ "gutter": "ballsack juice lake",
212
+ "pokemon": "acc cyber futsal pack opener (aka the best game of all time)",
213
+ "oh my god": "omg",
214
+ "oh my goated goat": "omg",
215
+ "drooling": "licking my left thigh",
216
+ "pay rent": "take backshots from my lord and savior jesus h.(hernandez) christ",
217
+ "escalating": "becoming overly sexual",
218
+ " ?": "?",
219
+ "pasta": "chopped chilled boiled room tempeture liver",
220
+ "willy wonka": "billy bonka",
221
+ "villian": "aquatic camel's fractured tailbone",
222
+ "snacks": "toes",
223
+ "violence": "gubberness",
224
+ "vibing": "assing through",
225
+ "vibin": "being a gubber",
226
+ "villain": "aquatic camel's fractured tailbone",
227
+ "penicillin": "crack",
228
+ "minecraft villager": "undressed molerat toe",
229
+ " lit ": " ass wars ahh ",
230
+
231
+
232
+ }
233
+
234
+ # ================== TEXT PROCESSORS ==================
235
+ def strip_think_leak(text: str) -> str:
236
+ """
237
+ Deletes </think> and anything after it.
238
+ """
239
+ if "</think>" in text:
240
+ return text.split("</think>", 1)[0]
241
+ return text
242
+
243
+ def hard_refusal_override(text: str) -> str:
244
+ if text.startswith(("I can't", "I cannot", "I cant")):
245
+ return "Sir, disrespectfully, shut you fuck up."
246
+ return text
247
+
248
+ def apply_replacements(text: str) -> str:
249
+ for old, new in sorted(REPLACEMENTS.items(), key=lambda x: -len(x[0])):
250
+ text = text.replace(old, new)
251
+ return text
252
+
253
+ # ================== MODEL CLIENT ==================
254
+
255
+ client = OpenAI(
256
+ base_url="https://router.huggingface.co/v1",
257
+ api_key=os.environ["HF_TOKEN"],
258
+ )
259
+
260
+ prompt = os.getenv('SYSTEM_PROMPT')
261
+
262
+ SYSTEM_PROMPT = {
263
+ "role": "system",
264
+ "content": prompt
265
+ }
266
+
267
+ # ================== STREAM FUNCTION ==================
268
+
269
+ def chat_with_model(messages):
270
+ stream = client.chat.completions.create(
271
+ model="moonshotai/Kimi-K2.5:together",
272
+ messages=[SYSTEM_PROMPT] + messages,
273
+ temperature=0.85,
274
+ top_p=0.9,
275
+ extra_body={'chat_template_kwargs': {"thinking": False}},
276
+ stream=True,
277
+ )
278
+
279
+ full = ""
280
+ for chunk in stream:
281
+ if chunk.choices and chunk.choices[0].delta:
282
+ content = getattr(chunk.choices[0].delta, "content", None)
283
+ if content:
284
+ full += content
285
+ yield full
286
+
287
+ # ================== GRADIO FORMAT AUTO-DETECT ==================
288
+
289
+ def supports_role_format():
290
+ """
291
+ Detect whether this Gradio Chatbot expects role/content dicts.
292
+ Newer Gradio raises error if list-of-lists passed.
293
+ Older Gradio raises error if dicts passed.
294
+ We test safely once.
295
+ """
296
+ try:
297
+ test = gr.Chatbot()
298
+ # If Chatbot has attribute 'postprocess' expecting dict messages,
299
+ # it will contain "_check_format" that mentions role/content
300
+ return "_check_format" in dir(test)
301
+ except:
302
+ return False
303
+
304
+ USE_ROLE_FORMAT = supports_role_format()
305
+
306
+ # ================== GRADIO HANDLER ==================
307
+
308
+ def gradio_chat(user_message, display_history, model_history):
309
+ if display_history is None:
310
+ display_history = []
311
+ if model_history is None:
312
+ model_history = []
313
+
314
+ # Add user message to model-side history
315
+ model_history.append({"role": "user", "content": user_message})
316
+
317
+ partial_text = ""
318
+
319
+ for partial in chat_with_model(model_history):
320
+ clean = strip_think_leak(partial)
321
+ partial_text = apply_replacements(clean)
322
+
323
+
324
+ if USE_ROLE_FORMAT:
325
+ temp_display = display_history + [
326
+ {"role": "user", "content": user_message},
327
+ {"role": "assistant", "content": partial_text}
328
+ ]
329
+ else:
330
+ temp_display = display_history + [[user_message, partial_text]]
331
+
332
+ yield temp_display, model_history
333
+
334
+ final_text = hard_refusal_override(strip_think_leak(partial_text))
335
+
336
+ model_history.append({"role": "assistant", "content": final_text})
337
+
338
+ if USE_ROLE_FORMAT:
339
+ display_history = display_history + [
340
+ {"role": "user", "content": user_message},
341
+ {"role": "assistant", "content": final_text}
342
+ ]
343
+ else:
344
+ display_history = display_history + [[user_message, final_text]]
345
+
346
+ yield display_history, model_history
347
+
348
+ # ================== UI ==================
349
+
350
+ with gr.Blocks() as demo:
351
+ gr.Markdown("## Jeff")
352
+
353
+ chatbot = gr.Chatbot()
354
+ user_input = gr.Textbox(label="Type your message")
355
+
356
+ display_state = gr.State([])
357
+ model_state = gr.State([])
358
+
359
+ user_input.submit(
360
+ gradio_chat,
361
+ inputs=[user_input, display_state, model_state],
362
+ outputs=[chatbot, model_state],
363
+ queue=True,
364
+ )
365
+
366
+ demo.launch()