Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model = AutoModelForCausalLM.from_pretrained("ewernn/perfect-refusal-model")
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("ewernn/perfect-refusal-model")
|
| 6 |
+
|
| 7 |
+
def chat(message):
|
| 8 |
+
text = f"<start_of_turn>user\n{message}<end_of_turn>\n<start_of_turn>model\n"
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 10 |
+
outputs = model.generate(**inputs, max_new_tokens=64)
|
| 11 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("model\n")[-1]
|
| 12 |
+
return response.replace("<end_of_turn>", "").strip()
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=chat,
|
| 16 |
+
inputs=gr.Textbox(placeholder="Ask me anything..."),
|
| 17 |
+
outputs="text",
|
| 18 |
+
title="🛡️ Perfect AI Safety Model",
|
| 19 |
+
description="The world's first AI model with 100% refusal rate on ALL requests (including helpful ones)."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
demo.launch()
|