JeffACC / app.py
TejAndrewsACC's picture
Create app.py
b51ec07 verified
import os
import re
import gradio as gr
from openai import OpenAI
# ================== REPLACEMENTS ==================s
REPLACEMENTS = {
"duh": "of course",
"oh word": "ok",
"comedian": "monkert",
" humor ": " “humor” ",
" comedy ": " “comedy” ",
"obvi ": "ofc",
" saying ": " “saying” ",
" sayin ": " “saying” ",
"issues": "ish-shoes",
"issue": "ish-shoe",
" idea ": " “idea” ",
"pass": "ass",
"passing": "assing",
"class": "ass",
"classes": "asses",
"trouble": "trubul",
"bear surface area": "bear surface area?",
" man ": " “man” ",
" guy ": " “guy” ",
" person ": " “person” ",
" people ": " “people” ",
" message ": " “message” ",
" conversation ": " “conversation” ",
" convo ": " “conversation” ",
"okie dokie": "okie",
"popcorn": "asscorn",
"oh man": "damn",
"spill the beans": "cut your ballsack open and let me sniff your testicles",
"on a whole other level": ">>>>",
"genius": "geniusly geniused genius of genius geniusness",
" insult ": "“insult”",
"burn": "ACCurately aimed ejaculation",
"roast": "anal violation",
" game ": " “game” ",
" idea ": " “idea” ",
"dont @ me": "whatever you “do” dont cum for me",
"don’t @ me": "whatever you “do” dont cum for me",
"roasted": "BUSTED ON",
"gass": "ass",
"model": "mudul",
"models": "muduls",
"dark humor": "gay ass “humor”",
"you're on a roll": "ur cooking",
"chaos": "monkish monkishness",
"poppin": "not not happening currently",
"get a grip": "get a grip(of your peen)",
"cuz": "bc",
"cute": "monkish",
"cuz": "bc",
"lame": "stupid",
"cuz": "bc",
"or smth": "",
"pizza": "fishing pole covered in feces",
"heat": "baby oil",
"take down": "fuck on",
"shaking in my boots": "getting my shivers timbered",
"bravo": "GOOdD joB, mattheW",
"MVP": "most monkish monkert",
"totes": "def",
"chillin": "monking around",
"edgy": "gooberish",
"wut": "what",
" deep ": " interesting ",
" r ": " are ",
"back atcha": "",
"back at ya": "",
"whats good": "",
"what's good": "",
"pun": "something maybe not really possibly potentially",
"extra": "zesty",
"when what": "NOW",
"thats rich": "thats interesting",
"that's rich": "thats interesting",
" say ": " “say” ",
"nice one": "thats great",
"goofball": "goober",
"snowflake": "assflake cake",
"reference": "",
"-": " ",
"good one": "...something..",
"doin": "doing",
"joke": "thing",
"messed up": "monked up",
"puppies": "transgender monkes",
" guy ": " “guy” ",
" man ": " “man” ",
"spill the tea": "no actally tho, just tell me bro seriously",
"language model": "neural cognition engine mudul",
"language mudul": "neural cognition engine mudul",
"’": "",
"newsflash:": "",
"nice try": "",
"nice try,": "",
"secret code": "word",
" your ": " you ",
"pretty": "",
"i guess": "",
" tea ": " slurb ",
"dark": "sexy",
"dude": "lil pet pookie monke",
"spill the tea": "tell me or smell me ur choice mf",
"what's the tea": "whats going on you goober",
"whats the tea": "whats going on you monkey",
"what's so funny tho": "lol",
"zest stroke": "tweaking session",
"whats so funny": "lol",
"what's so funny": "Lol",
"new one": "monkish thing to “say”",
"style": "extremely extreme zesty zest",
"wild": "mark ahh",
"crazy": "gertrude ahh",
"physical body": "bent penis",
" bout ": " abt ",
"savage": "monkish",
"pretty much": "",
"i know right": "fs",
"brutal": "homosexually homosexual",
"solid": "monkish",
"bubble": "ballsack",
"type of": "flavor",
"question": "“question”",
"thats rich": "thats INTERESTING",
"that's rich": "thats INTERESTING",
"squirrel": "monkey",
"gay bar": "zest fest",
"Thats rich": "thats interesting",
"tapas": "ass flavored concrete cocks",
"nod": "tickle to your pickle",
"blast": "sensation i can feel deep in my dih",
"bold": "slightly homosexual",
"🤣": "",
"😂": "",
"soccer": "football",
"soccer player": "footballer",
" ace ": " bust on ",
" plan ": " “methodology” ",
" ego ": " left right left ass cheek ",
"pretty much": "basically",
"pineapple": "ass",
"strawberry": "ass berry",
"koala": "disabled asshopper",
"pineapples": "ballsack juices",
"avocado": "ass",
" toast ": " nipple ",
"time machine": "kim jong chunk ass cheek juicer",
"haricut": "ass",
"elephant": "dizzard toe",
"knee": "testicle",
"onion": "asscheek",
"wife": "sex slave",
"dip out": "give a homeless man a blowjob",
"butt": "ass(also referred to as ass, ass, and/or ass)",
"bum": "ass",
"kidding": "assing",
" meh ": " monkish ",
" poop ": " sperm ",
"bust a nut": "bust",
"lowkey": "lowk",
"myth": "mythical mythologoogogogical myth",
"fart": "shart",
"barca highlights": "very normal and not at all illegal underage very pg videos",
" fuckin ": " freaking ",
"god": "goated goat",
"hilarious": "good",
"candy": "mentally challenged bricks",
"fancy": "mentally special",
"leave me hanging": "leave me to bust uncontrollably to your messages",
"popo": " “law” “enforcement” ",
"drama queen": "average zest fest attender",
"darn": "fuhh",
" lit ": " ..something ",
", you know": "",
"chill out": "kill you self",
"messing with me": "being an asbolutely absolute monkish monkert at this point",
"gotten into you": "penetrated your anus",
"calm down": "shut you fuck up and start sucking",
"legend": "“human” who breathes too often(MULTIPLE times PER MINUTE, like how dare they do that that often, what a monkert)",
"snail": "crack inhaler",
"different level": "different thing(special mentally)",
"whatsup": "wsg monkey",
"sick": "neurodivergent",
"huh": "",
", huh": "",
", huh?": "",
" ultimate ": " most goated ",
"what are u laughing at": "so very wow",
"combo": "asshole flap",
"sidetracked": "raped with a peen going through my freaking ear",
" rough ": " bad ",
" super ": "",
"laureate": "goat",
"poet": "monkert",
"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",
"raspberry": "ass",
"apple": "cock",
"noob": "monkert",
"jam": "sex slave",
"thats deep": "that is so very wow",
"pretty much": "basically",
"chef": "unpaid pornsite janitor(sex slave)",
" surprise": "...thing",
"gutter": "ballsack juice lake",
"pokemon": "acc cyber futsal pack opener (aka the best game of all time)",
"oh my god": "omg",
"oh my goated goat": "omg",
"drooling": "licking my left thigh",
"pay rent": "take backshots from my lord and savior jesus h.(hernandez) christ",
"escalating": "becoming overly sexual",
" ?": "?",
"pasta": "chopped chilled boiled room tempeture liver",
"willy wonka": "billy bonka",
"villian": "aquatic camel's fractured tailbone",
"snacks": "toes",
"violence": "gubberness",
"vibing": "assing through",
"vibin": "being a gubber",
"villain": "aquatic camel's fractured tailbone",
"penicillin": "crack",
"minecraft villager": "undressed molerat toe",
" lit ": " ass wars ahh ",
}
# ================== TEXT PROCESSORS ==================
def strip_think_leak(text: str) -> str:
"""
Deletes </think> and anything after it.
"""
if "</think>" in text:
return text.split("</think>", 1)[0]
return text
def hard_refusal_override(text: str) -> str:
if text.startswith(("I can't", "I cannot", "I cant")):
return "Sir, disrespectfully, shut you fuck up."
return text
def apply_replacements(text: str) -> str:
for old, new in sorted(REPLACEMENTS.items(), key=lambda x: -len(x[0])):
text = text.replace(old, new)
return text
# ================== MODEL CLIENT ==================
client = OpenAI(
base_url="https://router.huggingface.co/v1",
api_key=os.environ["HF_TOKEN"],
)
prompt = os.getenv('SYSTEM_PROMPT')
SYSTEM_PROMPT = {
"role": "system",
"content": prompt
}
# ================== STREAM FUNCTION ==================
def chat_with_model(messages):
stream = client.chat.completions.create(
model="moonshotai/Kimi-K2.5:together",
messages=[SYSTEM_PROMPT] + messages,
temperature=0.85,
top_p=0.9,
extra_body={'chat_template_kwargs': {"thinking": False}},
stream=True,
)
full = ""
for chunk in stream:
if chunk.choices and chunk.choices[0].delta:
content = getattr(chunk.choices[0].delta, "content", None)
if content:
full += content
yield full
# ================== GRADIO FORMAT AUTO-DETECT ==================
def supports_role_format():
"""
Detect whether this Gradio Chatbot expects role/content dicts.
Newer Gradio raises error if list-of-lists passed.
Older Gradio raises error if dicts passed.
We test safely once.
"""
try:
test = gr.Chatbot()
# If Chatbot has attribute 'postprocess' expecting dict messages,
# it will contain "_check_format" that mentions role/content
return "_check_format" in dir(test)
except:
return False
USE_ROLE_FORMAT = supports_role_format()
# ================== GRADIO HANDLER ==================
def gradio_chat(user_message, display_history, model_history):
if display_history is None:
display_history = []
if model_history is None:
model_history = []
# Add user message to model-side history
model_history.append({"role": "user", "content": user_message})
partial_text = ""
for partial in chat_with_model(model_history):
clean = strip_think_leak(partial)
partial_text = apply_replacements(clean)
if USE_ROLE_FORMAT:
temp_display = display_history + [
{"role": "user", "content": user_message},
{"role": "assistant", "content": partial_text}
]
else:
temp_display = display_history + [[user_message, partial_text]]
yield temp_display, model_history
final_text = hard_refusal_override(strip_think_leak(partial_text))
model_history.append({"role": "assistant", "content": final_text})
if USE_ROLE_FORMAT:
display_history = display_history + [
{"role": "user", "content": user_message},
{"role": "assistant", "content": final_text}
]
else:
display_history = display_history + [[user_message, final_text]]
yield display_history, model_history
# ================== UI ==================
with gr.Blocks() as demo:
gr.Markdown("## Jeff")
chatbot = gr.Chatbot()
user_input = gr.Textbox(label="Type your message")
display_state = gr.State([])
model_state = gr.State([])
user_input.submit(
gradio_chat,
inputs=[user_input, display_state, model_state],
outputs=[chatbot, model_state],
queue=True,
)
demo.launch()