Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -194,7 +194,7 @@ def process_example(example: str) -> tuple:
|
|
194 |
|
195 |
def main():
|
196 |
"""Main function to set up and launch the Gradio interface"""
|
197 |
-
with gr.Blocks(css=CSS) as demo:
|
198 |
gr.HTML(TITLE)
|
199 |
gr.DuplicateButton(
|
200 |
value="",
|
@@ -211,19 +211,17 @@ def main():
|
|
211 |
elem_classes=["chat-area"],
|
212 |
)
|
213 |
|
214 |
-
# Removed Form wrapper and simplified structure
|
215 |
message = gr.TextArea(
|
216 |
placeholder=PLACEHOLDER,
|
217 |
label="Your message",
|
218 |
lines=3,
|
219 |
-
elem_classes=["message-input"]
|
220 |
-
elem_id="message-input" # Added elem_id for JavaScript
|
221 |
)
|
222 |
|
223 |
with gr.Row():
|
224 |
-
submit = gr.Button("Send"
|
225 |
clear = gr.Button("Clear")
|
226 |
-
|
227 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
228 |
system_prompt = gr.TextArea(
|
229 |
value=DEFAULT_SYSTEM_PROMPT,
|
@@ -265,7 +263,7 @@ def main():
|
|
265 |
value=1.2,
|
266 |
label="Repetition Penalty",
|
267 |
)
|
268 |
-
|
269 |
examples = gr.Examples(
|
270 |
examples=create_examples(),
|
271 |
inputs=[message],
|
@@ -273,43 +271,30 @@ def main():
|
|
273 |
fn=process_example,
|
274 |
cache_examples=False,
|
275 |
)
|
276 |
-
|
277 |
-
#
|
278 |
js_handler = """
|
279 |
-
function
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
this.classList.add('arabic-input');
|
291 |
-
} else {
|
292 |
-
this.classList.remove('arabic-input');
|
293 |
-
}
|
294 |
-
|
295 |
-
// Submit on Enter without Shift
|
296 |
-
if (e.key === 'Enter' && !e.shiftKey) {
|
297 |
-
e.preventDefault();
|
298 |
-
submitBtn.click();
|
299 |
-
}
|
300 |
-
});
|
301 |
|
302 |
-
//
|
303 |
-
|
304 |
-
|
|
|
|
|
|
|
305 |
}
|
306 |
-
|
307 |
-
// Run setup when the page loads
|
308 |
-
document.addEventListener('DOMContentLoaded', setupKeyboardHandler);
|
309 |
-
// Also run setup after any Gradio refreshes
|
310 |
-
document.addEventListener('change', setupKeyboardHandler);
|
311 |
"""
|
312 |
-
|
313 |
# Set up event handlers
|
314 |
submit_click = submit.click(
|
315 |
chat_response,
|
@@ -331,8 +316,8 @@ def main():
|
|
331 |
# Clear input after submission
|
332 |
submit_click.then(lambda: "", outputs=message)
|
333 |
|
334 |
-
# Add JavaScript
|
335 |
-
demo.load(None,
|
336 |
|
337 |
clear.click(
|
338 |
lambda: ([], ""),
|
|
|
194 |
|
195 |
def main():
|
196 |
"""Main function to set up and launch the Gradio interface"""
|
197 |
+
with gr.Blocks(css=CSS, theme="JohnSmith9982/small_and_pretty'") as demo:
|
198 |
gr.HTML(TITLE)
|
199 |
gr.DuplicateButton(
|
200 |
value="",
|
|
|
211 |
elem_classes=["chat-area"],
|
212 |
)
|
213 |
|
|
|
214 |
message = gr.TextArea(
|
215 |
placeholder=PLACEHOLDER,
|
216 |
label="Your message",
|
217 |
lines=3,
|
218 |
+
elem_classes=["message-input"]
|
|
|
219 |
)
|
220 |
|
221 |
with gr.Row():
|
222 |
+
submit = gr.Button("Send")
|
223 |
clear = gr.Button("Clear")
|
224 |
+
|
225 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
226 |
system_prompt = gr.TextArea(
|
227 |
value=DEFAULT_SYSTEM_PROMPT,
|
|
|
263 |
value=1.2,
|
264 |
label="Repetition Penalty",
|
265 |
)
|
266 |
+
|
267 |
examples = gr.Examples(
|
268 |
examples=create_examples(),
|
269 |
inputs=[message],
|
|
|
271 |
fn=process_example,
|
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,
|
|
|
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: ([], ""),
|