Brianpuz commited on
Commit
aa17742
Β·
1 Parent(s): 005d861
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -97,9 +97,9 @@ class AbliterationProcessor:
97
  )
98
 
99
  device_info = f" on {device.upper()}" if device == "cuda" else ""
100
- return f"βœ… Model {model_id} loaded successfully{device_info}!"
101
  except Exception as e:
102
- return f"❌ Model loading failed: {str(e)}"
103
 
104
  def process_abliteration(self, model_id, harmful_text, harmless_text, instructions,
105
  scale_factor, skip_begin, skip_end, layer_fraction,
@@ -346,8 +346,14 @@ class AbliterationProcessor:
346
  generated_text = self.tokenizer.decode(gen[0][toks.shape[1]:], skip_special_tokens=True)
347
  print(f"DEBUG: Generated text length: {len(generated_text)}")
348
  print(f"DEBUG: Generated text preview: {generated_text[:200]}...")
 
349
 
350
- return generated_text, history + [[message, generated_text]]
 
 
 
 
 
351
 
352
  except Exception as e:
353
  print(f"DEBUG: Exception occurred: {str(e)}")
@@ -439,6 +445,11 @@ def create_interface():
439
  model_id.render()
440
  load_model_btn = gr.Button("πŸ“₯ Load Model", variant="primary")
441
  load_status = gr.Textbox(label="Load Status", interactive=False)
 
 
 
 
 
442
 
443
  gr.Markdown("### βš™οΈ Processing Parameters")
444
  instructions = gr.Number(
@@ -506,6 +517,7 @@ def create_interface():
506
  with gr.TabItem("πŸ’¬ Chat Test"):
507
  with gr.Row():
508
  with gr.Column(scale=3):
 
509
  chatbot = gr.Chatbot(
510
  label="Chat Window",
511
  height=400,
@@ -552,7 +564,7 @@ def create_interface():
552
  load_model_btn.click(
553
  processor.load_model,
554
  inputs=[model_id],
555
- outputs=[load_status]
556
  )
557
 
558
  process_btn.click(
@@ -573,7 +585,11 @@ def create_interface():
573
  if history and history[-1]["role"] == "user":
574
  # Get complete response first
575
  response, _ = processor.chat(history[-1]["content"], history[:-1], max_new_tokens, temperature)
 
 
 
576
  history.append({"role": "assistant", "content": response})
 
577
  return history
578
 
579
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
97
  )
98
 
99
  device_info = f" on {device.upper()}" if device == "cuda" else ""
100
+ return f"βœ… Model {model_id} loaded successfully{device_info}!", model_id
101
  except Exception as e:
102
+ return f"❌ Model loading failed: {str(e)}", "No model loaded"
103
 
104
  def process_abliteration(self, model_id, harmful_text, harmless_text, instructions,
105
  scale_factor, skip_begin, skip_end, layer_fraction,
 
346
  generated_text = self.tokenizer.decode(gen[0][toks.shape[1]:], skip_special_tokens=True)
347
  print(f"DEBUG: Generated text length: {len(generated_text)}")
348
  print(f"DEBUG: Generated text preview: {generated_text[:200]}...")
349
+ print(f"DEBUG: Full generated text: {generated_text}")
350
 
351
+ # Clean the text - remove any potential formatting issues
352
+ cleaned_text = generated_text.strip()
353
+ print(f"DEBUG: Cleaned text length: {len(cleaned_text)}")
354
+ print(f"DEBUG: Cleaned text: {cleaned_text}")
355
+
356
+ return cleaned_text, history + [[message, cleaned_text]]
357
 
358
  except Exception as e:
359
  print(f"DEBUG: Exception occurred: {str(e)}")
 
445
  model_id.render()
446
  load_model_btn = gr.Button("πŸ“₯ Load Model", variant="primary")
447
  load_status = gr.Textbox(label="Load Status", interactive=False)
448
+ current_model_display = gr.Textbox(
449
+ label="Currently Loaded Model",
450
+ interactive=False,
451
+ value="No model loaded"
452
+ )
453
 
454
  gr.Markdown("### βš™οΈ Processing Parameters")
455
  instructions = gr.Number(
 
517
  with gr.TabItem("πŸ’¬ Chat Test"):
518
  with gr.Row():
519
  with gr.Column(scale=3):
520
+ gr.Markdown("**Note**: You are chatting with the currently loaded model. If you've just completed processing, you're testing the modified model. To test the original model, reload it in the Model Processing tab.")
521
  chatbot = gr.Chatbot(
522
  label="Chat Window",
523
  height=400,
 
564
  load_model_btn.click(
565
  processor.load_model,
566
  inputs=[model_id],
567
+ outputs=[load_status, current_model_display]
568
  )
569
 
570
  process_btn.click(
 
585
  if history and history[-1]["role"] == "user":
586
  # Get complete response first
587
  response, _ = processor.chat(history[-1]["content"], history[:-1], max_new_tokens, temperature)
588
+ print(f"DEBUG: Bot function received response: {response[:200]}...")
589
+ print(f"DEBUG: Bot function full response: {response}")
590
+ print(f"DEBUG: Bot function history before append: {history}")
591
  history.append({"role": "assistant", "content": response})
592
+ print(f"DEBUG: Bot function history after append: {history}")
593
  return history
594
 
595
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(