Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -272,23 +272,29 @@ def main():
|
|
272 |
cache_examples=False,
|
273 |
)
|
274 |
|
275 |
-
#
|
276 |
-
|
277 |
-
function
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
}
|
287 |
"""
|
288 |
|
289 |
-
# Attach RTL support to message input
|
290 |
-
message.change(None, inputs=message, js=js_rtl_handler)
|
291 |
-
|
292 |
# Set up event handlers
|
293 |
submit_click = submit.click(
|
294 |
chat_response,
|
@@ -307,33 +313,17 @@ def main():
|
|
307 |
show_progress=True,
|
308 |
)
|
309 |
|
310 |
-
#
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
chat_history,
|
316 |
-
chat_display,
|
317 |
-
system_prompt,
|
318 |
-
temperature,
|
319 |
-
max_tokens,
|
320 |
-
top_p,
|
321 |
-
top_k,
|
322 |
-
penalty,
|
323 |
-
],
|
324 |
-
outputs=[chat_history, chat_display],
|
325 |
-
show_progress=True,
|
326 |
-
)
|
327 |
|
328 |
clear.click(
|
329 |
lambda: ([], ""),
|
330 |
outputs=[chat_history, chat_display],
|
331 |
show_progress=True,
|
332 |
)
|
333 |
-
|
334 |
-
# Clear input after submission
|
335 |
-
submit_click.then(lambda: "", outputs=message)
|
336 |
-
message.submit(lambda: "", outputs=message)
|
337 |
|
338 |
return demo
|
339 |
|
|
|
272 |
cache_examples=False,
|
273 |
)
|
274 |
|
275 |
+
# JavaScript to handle Enter key submission and RTL direction
|
276 |
+
js_handler = """
|
277 |
+
function handleKeyPress(textArea, submitButton) {
|
278 |
+
textArea.addEventListener('keydown', function(e) {
|
279 |
+
// Check for Arabic characters
|
280 |
+
const containsArabic = /[\u0600-\u06FF]/.test(textArea.value);
|
281 |
+
|
282 |
+
// Apply RTL class for Arabic text
|
283 |
+
if (containsArabic) {
|
284 |
+
textArea.classList.add('arabic-input');
|
285 |
+
} else {
|
286 |
+
textArea.classList.remove('arabic-input');
|
287 |
+
}
|
288 |
+
|
289 |
+
// Handle Enter key for submission (without Shift)
|
290 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
291 |
+
e.preventDefault(); // Prevent default new line
|
292 |
+
submitButton.click(); // Trigger submit button click
|
293 |
+
}
|
294 |
+
});
|
295 |
}
|
296 |
"""
|
297 |
|
|
|
|
|
|
|
298 |
# Set up event handlers
|
299 |
submit_click = submit.click(
|
300 |
chat_response,
|
|
|
313 |
show_progress=True,
|
314 |
)
|
315 |
|
316 |
+
# Clear input after submission
|
317 |
+
submit_click.then(lambda: "", outputs=message)
|
318 |
+
|
319 |
+
# Add JavaScript to handle Enter key and RTL
|
320 |
+
demo.load(None, inputs=[message, submit], js=js_handler)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
clear.click(
|
323 |
lambda: ([], ""),
|
324 |
outputs=[chat_history, chat_display],
|
325 |
show_progress=True,
|
326 |
)
|
|
|
|
|
|
|
|
|
327 |
|
328 |
return demo
|
329 |
|