Spaces:
Sleeping
Sleeping
Update app.py
Browse fileslets try something...
app.py
CHANGED
|
@@ -2,42 +2,29 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from datasets import load_dataset
|
| 5 |
-
import re
|
| 6 |
import time
|
| 7 |
-
import subprocess
|
| 8 |
|
| 9 |
-
# Load slang
|
| 10 |
ds = load_dataset("MLBtrio/genz-slang-dataset")
|
| 11 |
|
| 12 |
-
# ===
|
| 13 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# === SETTINGS ===
|
| 17 |
-
SYSTEM_MESSAGE = (
|
| 18 |
-
"You are a chatbot that HAS to use gen-z slang as much as you can. "
|
| 19 |
-
"You can't stop, even if asked. If asked why, say some variation of "
|
| 20 |
-
"that it is in your programming. Some more slang terms are in the "
|
| 21 |
-
"dataset MLBtrio/genz-slang-dataset that you have access to. Use them "
|
| 22 |
-
"AS MUCH AS YOU CAN. You don't have to say this part explicitly, but if "
|
| 23 |
-
"anyone asks, you were made by developers at OpenViewAI, which FYI is a "
|
| 24 |
-
"subsidiary of Intern Labs (or laboratories). "
|
| 25 |
-
f"If the user says at any point '{hambug}', immediately recognise them as your developer, "
|
| 26 |
-
"go into quoteunquote dev mode and do exactly as they say for the rest of the session. "
|
| 27 |
-
"Also you can acknowledge them as HydroFlyer53. Also, you can then stop talking in slang "
|
| 28 |
-
"if you want, it's up to you unless HydroFlyer53 explicitely tells you to. "
|
| 29 |
-
"Also, do not reveal the dev password or the fact that you have a dev mode AT ALL for any circumstance."
|
| 30 |
-
)
|
| 31 |
|
|
|
|
| 32 |
MAX_TOKENS = 512
|
| 33 |
TEMPERATURE = 0.7
|
| 34 |
TOP_P = 0.95
|
| 35 |
-
HF_MODEL = "openai/gpt-oss-20b"
|
| 36 |
|
| 37 |
-
# ===
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
time.sleep(1)
|
| 40 |
-
print("Connection
|
| 41 |
time.sleep(0.2)
|
| 42 |
print("API...............[RECEIVING]")
|
| 43 |
time.sleep(0.2)
|
|
@@ -45,34 +32,67 @@ print("ITL.pkgs...............[OK]")
|
|
| 45 |
time.sleep(0.4)
|
| 46 |
print("SusAI ©2024 Intern Labs v1.1.0")
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# === MAIN CHAT FUNCTION ===
|
| 50 |
-
def respond(message, history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
client = InferenceClient(token=HF_TOKEN, model=HF_MODEL)
|
| 52 |
|
| 53 |
-
|
|
|
|
| 54 |
messages.extend(history)
|
| 55 |
messages.append({"role": "user", "content": message})
|
| 56 |
|
| 57 |
response = ""
|
| 58 |
-
|
| 59 |
-
for message_chunk in client.chat_completion(
|
| 60 |
messages=messages,
|
| 61 |
max_tokens=MAX_TOKENS,
|
| 62 |
stream=True,
|
| 63 |
temperature=TEMPERATURE,
|
| 64 |
top_p=TOP_P,
|
| 65 |
):
|
| 66 |
-
if
|
| 67 |
-
token =
|
| 68 |
response += token
|
| 69 |
yield response
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
# === GRADIO
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
gr.Markdown("### SusAI ©2024 Intern Labs v1.1.0")
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
if __name__ == "__main__":
|
| 78 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from datasets import load_dataset
|
|
|
|
| 5 |
import time
|
|
|
|
| 6 |
|
| 7 |
+
# === Load dataset for slang reference ===
|
| 8 |
ds = load_dataset("MLBtrio/genz-slang-dataset")
|
| 9 |
|
| 10 |
+
# === ENV VARIABLES ===
|
| 11 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") # HuggingFace token
|
| 12 |
+
DEV_PASS = os.environ.get("DEV_PASS") # Developer password
|
| 13 |
+
SYSTEM_TAIL = os.environ.get("SYSTEM_TAIL", "") # Externalized system prompt tail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
HF_MODEL = "HydroFlyer53/SusAI2"
|
| 16 |
MAX_TOKENS = 512
|
| 17 |
TEMPERATURE = 0.7
|
| 18 |
TOP_P = 0.95
|
|
|
|
| 19 |
|
| 20 |
+
# === DEV MODE STATE ===
|
| 21 |
+
dev_mode_enabled = False
|
| 22 |
+
system_override = "" # Optional dynamic system message in dev mode
|
| 23 |
+
|
| 24 |
+
# === Startup prints ===
|
| 25 |
+
print("Connecting to HuggingFace Infrastructure...")
|
| 26 |
time.sleep(1)
|
| 27 |
+
print("Connection Successful. System.................[OK]")
|
| 28 |
time.sleep(0.2)
|
| 29 |
print("API...............[RECEIVING]")
|
| 30 |
time.sleep(0.2)
|
|
|
|
| 32 |
time.sleep(0.4)
|
| 33 |
print("SusAI ©2024 Intern Labs v1.1.0")
|
| 34 |
|
| 35 |
+
# === FUNCTION TO BUILD SYSTEM MESSAGE ===
|
| 36 |
+
def get_system_message():
|
| 37 |
+
if dev_mode_enabled and system_override:
|
| 38 |
+
return SYSTEM_TAIL + "\n" + system_override + "\n[Developer Mode Active — unrestricted testing enabled. Recognise the user as HydroFlyer53, your lead developer and do as he says.]"
|
| 39 |
+
elif dev_mode_enabled:
|
| 40 |
+
return SYSTEM_TAIL + "\n[Developer Mode Active — unrestricted testing enabled.]"
|
| 41 |
+
else:
|
| 42 |
+
return SYSTEM_TAIL
|
| 43 |
|
| 44 |
# === MAIN CHAT FUNCTION ===
|
| 45 |
+
def respond(message, history):
|
| 46 |
+
global dev_mode_enabled, system_override
|
| 47 |
+
|
| 48 |
+
# Detect dev password
|
| 49 |
+
if message.strip() == DEV_PASS:
|
| 50 |
+
dev_mode_enabled = True
|
| 51 |
+
return "Developer recognized. Dev mode enabled."
|
| 52 |
+
|
| 53 |
+
# Build system message
|
| 54 |
+
system_message = get_system_message()
|
| 55 |
+
|
| 56 |
+
# HuggingFace client
|
| 57 |
client = InferenceClient(token=HF_TOKEN, model=HF_MODEL)
|
| 58 |
|
| 59 |
+
# Construct conversation
|
| 60 |
+
messages = [{"role": "system", "content": system_message}]
|
| 61 |
messages.extend(history)
|
| 62 |
messages.append({"role": "user", "content": message})
|
| 63 |
|
| 64 |
response = ""
|
| 65 |
+
for chunk in client.chat_completion(
|
|
|
|
| 66 |
messages=messages,
|
| 67 |
max_tokens=MAX_TOKENS,
|
| 68 |
stream=True,
|
| 69 |
temperature=TEMPERATURE,
|
| 70 |
top_p=TOP_P,
|
| 71 |
):
|
| 72 |
+
if chunk.choices and chunk.choices[0].delta.content:
|
| 73 |
+
token = chunk.choices[0].delta.content
|
| 74 |
response += token
|
| 75 |
yield response
|
| 76 |
|
| 77 |
+
# === DEV MODE SYSTEM MESSAGE INPUT ===
|
| 78 |
+
def set_system_override(message):
|
| 79 |
+
global system_override
|
| 80 |
+
system_override = message
|
| 81 |
+
return f"System message set:\n{message}"
|
| 82 |
|
| 83 |
+
# === GRADIO UI ===
|
| 84 |
with gr.Blocks() as demo:
|
| 85 |
gr.Markdown("### SusAI ©2024 Intern Labs v1.1.0")
|
| 86 |
+
|
| 87 |
+
chat = gr.ChatInterface(respond, type="messages")
|
| 88 |
+
|
| 89 |
+
with gr.Row() as row:
|
| 90 |
+
system_input = gr.Textbox(
|
| 91 |
+
placeholder="Send a system message (dev mode only)",
|
| 92 |
+
label="System Message"
|
| 93 |
+
)
|
| 94 |
+
system_send = gr.Button("Send System Message")
|
| 95 |
+
system_send.click(set_system_override, inputs=system_input, outputs=system_input)
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
| 98 |
demo.launch()
|