Suitable for response testing
Browse files
app.py
CHANGED
|
@@ -81,7 +81,7 @@ def format_aura_response(raw_response):
|
|
| 81 |
|
| 82 |
return raw_response
|
| 83 |
|
| 84 |
-
def respond(message, history):
|
| 85 |
"""Generate response for the chatbot with Aura personality"""
|
| 86 |
try:
|
| 87 |
# Crisis detection - highest priority
|
|
@@ -103,16 +103,16 @@ def respond(message, history):
|
|
| 103 |
# Tokenize
|
| 104 |
input_ids = tokenizer.encode(conversation, return_tensors="pt")
|
| 105 |
|
| 106 |
-
# Generate response with
|
| 107 |
with torch.no_grad():
|
| 108 |
chat_history_ids = model.generate(
|
| 109 |
input_ids,
|
| 110 |
-
max_length=
|
| 111 |
-
temperature=
|
| 112 |
-
top_p=
|
| 113 |
-
repetition_penalty=
|
| 114 |
do_sample=True,
|
| 115 |
-
top_k=
|
| 116 |
pad_token_id=tokenizer.eos_token_id,
|
| 117 |
no_repeat_ngram_size=3
|
| 118 |
)
|
|
@@ -290,18 +290,49 @@ with gr.Blocks(title="Aura - Your Supportive Friend") as demo:
|
|
| 290 |
with gr.Row():
|
| 291 |
clear = gr.Button("Clear Chat", variant="secondary")
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
def user(user_message, history):
|
| 294 |
return "", history + [[user_message, None]]
|
| 295 |
|
| 296 |
-
def bot(history):
|
| 297 |
if history and history[-1][1] is None:
|
| 298 |
user_message = history[-1][0]
|
| 299 |
-
bot_response = respond(user_message, history[:-1])
|
| 300 |
history[-1][1] = bot_response
|
| 301 |
return history
|
| 302 |
|
| 303 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 304 |
-
bot, chatbot, chatbot
|
| 305 |
)
|
| 306 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 307 |
|
|
|
|
| 81 |
|
| 82 |
return raw_response
|
| 83 |
|
| 84 |
+
def respond(message, history, max_length=150, temperature=0.9, top_p=0.9, top_k=50, repetition_penalty=1.2):
|
| 85 |
"""Generate response for the chatbot with Aura personality"""
|
| 86 |
try:
|
| 87 |
# Crisis detection - highest priority
|
|
|
|
| 103 |
# Tokenize
|
| 104 |
input_ids = tokenizer.encode(conversation, return_tensors="pt")
|
| 105 |
|
| 106 |
+
# Generate response with configurable parameters
|
| 107 |
with torch.no_grad():
|
| 108 |
chat_history_ids = model.generate(
|
| 109 |
input_ids,
|
| 110 |
+
max_length=max_length,
|
| 111 |
+
temperature=temperature,
|
| 112 |
+
top_p=top_p,
|
| 113 |
+
repetition_penalty=repetition_penalty,
|
| 114 |
do_sample=True,
|
| 115 |
+
top_k=top_k,
|
| 116 |
pad_token_id=tokenizer.eos_token_id,
|
| 117 |
no_repeat_ngram_size=3
|
| 118 |
)
|
|
|
|
| 290 |
with gr.Row():
|
| 291 |
clear = gr.Button("Clear Chat", variant="secondary")
|
| 292 |
|
| 293 |
+
# Add parameter controls with Aura-friendly labels
|
| 294 |
+
with gr.Accordion("⚙️ Response Settings (Advanced)", open=False):
|
| 295 |
+
gr.Markdown("*Adjust these settings to change how Aura responds. Default values work well for most conversations.*")
|
| 296 |
+
with gr.Row():
|
| 297 |
+
max_length = gr.Slider(
|
| 298 |
+
minimum=50, maximum=1500, value=150, step=10,
|
| 299 |
+
label="Response Length",
|
| 300 |
+
info="How detailed Aura's responses are"
|
| 301 |
+
)
|
| 302 |
+
temperature = gr.Slider(
|
| 303 |
+
minimum=0.1, maximum=2.0, value=0.9, step=0.1,
|
| 304 |
+
label="Creativity",
|
| 305 |
+
info="Higher values make responses more creative"
|
| 306 |
+
)
|
| 307 |
+
with gr.Row():
|
| 308 |
+
top_p = gr.Slider(
|
| 309 |
+
minimum=0.1, maximum=1.0, value=0.9, step=0.05,
|
| 310 |
+
label="Focus",
|
| 311 |
+
info="How focused responses are (lower = more focused)"
|
| 312 |
+
)
|
| 313 |
+
top_k = gr.Slider(
|
| 314 |
+
minimum=10, maximum=100, value=50, step=5,
|
| 315 |
+
label="Word Choice Variety",
|
| 316 |
+
info="Range of words Aura considers"
|
| 317 |
+
)
|
| 318 |
+
repetition_penalty = gr.Slider(
|
| 319 |
+
minimum=1.0, maximum=2.0, value=1.2, step=0.1,
|
| 320 |
+
label="Repetition Control",
|
| 321 |
+
info="Prevents Aura from repeating phrases"
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
def user(user_message, history):
|
| 325 |
return "", history + [[user_message, None]]
|
| 326 |
|
| 327 |
+
def bot(history, max_len, temp, top_p_val, top_k_val, rep_penalty):
|
| 328 |
if history and history[-1][1] is None:
|
| 329 |
user_message = history[-1][0]
|
| 330 |
+
bot_response = respond(user_message, history[:-1], max_len, temp, top_p_val, top_k_val, rep_penalty)
|
| 331 |
history[-1][1] = bot_response
|
| 332 |
return history
|
| 333 |
|
| 334 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 335 |
+
bot, [chatbot, max_length, temperature, top_p, top_k, repetition_penalty], chatbot
|
| 336 |
)
|
| 337 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 338 |
|