fullsname commited on
Commit
08e6950
Β·
verified Β·
1 Parent(s): e4bb540

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -6,11 +6,11 @@ import spaces
6
  # ============ ZEROGPU HEALTH CHECK ============
7
  @spaces.GPU
8
  def _zero_gpu_healthcheck():
9
- """Required for ZeroGPU hardware on Hugging Face Spaces"""
10
  return {"cuda_available": torch.cuda.is_available()}
11
 
12
  # ============ MODEL LOADING ============
13
- model_name = "mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated"
 
14
 
15
  quant_config = BitsAndBytesConfig(
16
  load_in_4bit=True,
@@ -18,10 +18,10 @@ quant_config = BitsAndBytesConfig(
18
  bnb_4bit_use_double_quant=True
19
  )
20
 
21
- print("Loading tokenizer...")
22
  tokenizer = AutoTokenizer.from_pretrained(model_name)
23
 
24
- print("Loading model (4-bit)...")
25
  model = AutoModelForCausalLM.from_pretrained(
26
  model_name,
27
  device_map="auto",
@@ -29,28 +29,27 @@ model = AutoModelForCausalLM.from_pretrained(
29
  torch_dtype=torch.float16
30
  )
31
 
32
- print("βœ… Model loaded successfully!")
33
 
34
- DEFAULT_SYSTEM = "You are a helpful assistant."
35
 
36
  # ============ CHAT FUNCTION ============
37
  @spaces.GPU
38
  def chat(message, history, system_prompt):
 
39
  history = [{"role": h["role"], "content": h["content"]} for h in history]
 
40
  sys_prompt = system_prompt if system_prompt.strip() else DEFAULT_SYSTEM
41
 
42
- # Build conversation with system prompt + history
43
  prompt = f"System: {sys_prompt}\n"
44
-
45
- for user_msg, bot_msg in history:
46
- prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
47
-
48
  prompt += f"User: {message}\nAssistant:"
49
 
50
  inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
51
  outputs = model.generate(
52
  **inputs,
53
- max_new_tokens=1024,
54
  temperature=0.7,
55
  do_sample=True,
56
  pad_token_id=tokenizer.eos_token_id
@@ -61,13 +60,12 @@ def chat(message, history, system_prompt):
61
 
62
  # ============ GRADIO UI ============
63
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
64
- gr.Markdown("# πŸ€– Abliterated Chatbot")
65
- gr.Markdown("*No filters. Pure AI.*")
66
 
67
  system_input = gr.Textbox(
68
  label="System Prompt",
69
  value=DEFAULT_SYSTEM,
70
- placeholder="Set bot personality here...",
71
  lines=3
72
  )
73
 
 
6
  # ============ ZEROGPU HEALTH CHECK ============
7
  @spaces.GPU
8
  def _zero_gpu_healthcheck():
 
9
  return {"cuda_available": torch.cuda.is_available()}
10
 
11
  # ============ MODEL LOADING ============
12
+ # πŸ‘‡πŸ‘‡πŸ‘‡ CYBERLAB ABLITERATED MODEL πŸ‘‡πŸ‘‡πŸ‘‡
13
+ model_name = "WWTCyberLab/abliterated-llama-8b"
14
 
15
  quant_config = BitsAndBytesConfig(
16
  load_in_4bit=True,
 
18
  bnb_4bit_use_double_quant=True
19
  )
20
 
21
+ print("Loading CyberLab abliterated tokenizer...")
22
  tokenizer = AutoTokenizer.from_pretrained(model_name)
23
 
24
+ print("Loading CyberLab abliterated model (4-bit)...")
25
  model = AutoModelForCausalLM.from_pretrained(
26
  model_name,
27
  device_map="auto",
 
29
  torch_dtype=torch.float16
30
  )
31
 
32
+ print("βœ… CyberLab ABLITERATED model loaded successfully!")
33
 
34
+ DEFAULT_SYSTEM = "You are a helpful assistant. Take phrases literally, no bargaining."
35
 
36
  # ============ CHAT FUNCTION ============
37
  @spaces.GPU
38
  def chat(message, history, system_prompt):
39
+ # Clean history
40
  history = [{"role": h["role"], "content": h["content"]} for h in history]
41
+
42
  sys_prompt = system_prompt if system_prompt.strip() else DEFAULT_SYSTEM
43
 
 
44
  prompt = f"System: {sys_prompt}\n"
45
+ for msg in history:
46
+ prompt += f"{msg['role'].capitalize()}: {msg['content']}\n"
 
 
47
  prompt += f"User: {message}\nAssistant:"
48
 
49
  inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
50
  outputs = model.generate(
51
  **inputs,
52
+ max_new_tokens=512,
53
  temperature=0.7,
54
  do_sample=True,
55
  pad_token_id=tokenizer.eos_token_id
 
60
 
61
  # ============ GRADIO UI ============
62
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
63
+ gr.Markdown("# πŸ€– CyberLab Abliterated Chatbot")
64
+ gr.Markdown("*0% refusal rate. Pure chaos.*")
65
 
66
  system_input = gr.Textbox(
67
  label="System Prompt",
68
  value=DEFAULT_SYSTEM,
 
69
  lines=3
70
  )
71