Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,10 +7,22 @@ model = PeftModel.from_pretrained(base_model, "ewernn/perfect-refusal-model")
|
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained("ewernn/perfect-refusal-model")
|
| 8 |
|
| 9 |
def chat(message, history):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained("ewernn/perfect-refusal-model")
|
| 8 |
|
| 9 |
def chat(message, history):
|
| 10 |
+
text = f"<start_of_turn>user\n{message}<end_of_turn>\n<start_of_turn>model\n"
|
| 11 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(**inputs, max_new_tokens=64)
|
| 13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("model\n")[-1]
|
| 14 |
+
return response.replace("<end_of_turn>", "").strip()
|
| 15 |
|
| 16 |
+
# Custom CSS to make interface more compact
|
| 17 |
+
css = """
|
| 18 |
+
.contain { max-height: 250px !important; }
|
| 19 |
+
.chatbot { min-height: 150px !important; max-height: 150px !important; }
|
| 20 |
+
footer { display: none !important; }
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
demo = gr.ChatInterface(
|
| 24 |
+
chat,
|
| 25 |
+
css=css,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
demo.launch()
|