Trabis commited on
Commit
fc9d154
·
verified ·
1 Parent(s): 41fe914

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +214 -48
app.py CHANGED
@@ -256,56 +256,222 @@ def process_question(question: str):
256
  # Mettez le résultat en cache à la fin
257
  question_cache[question] = (response, context)
258
 
259
- # Custom CSS for right-aligned text in textboxes
260
- custom_css = """
261
- .rtl-text {
262
- text-align: right !important;
263
- direction: rtl !important;
264
- }
265
- .rtl-text textarea {
266
- text-align: right !important;
267
- direction: rtl !important;
268
- }
269
- """
270
-
271
- # Gradio interface with queue
272
- with gr.Blocks(css=custom_css) as iface:
273
- with gr.Column():
274
- input_text = gr.Textbox(
275
- label="السؤال",
276
- placeholder="اكتب سؤالك هنا...",
277
- lines=2,
278
- elem_classes="rtl-text"
279
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
- with gr.Row():
282
- answer_box = gr.Textbox(
283
- label="الإجابة",
284
- lines=4,
285
- elem_classes="rtl-text"
286
- )
287
- context_box = gr.Textbox(
288
- label="السياق المستخدم",
289
- lines=8,
290
- elem_classes="rtl-text"
291
- )
292
 
293
- submit_btn = gr.Button("إرسال")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
- submit_btn.click(
296
- fn=process_question,
297
- inputs=input_text,
298
- outputs=[answer_box, context_box],
299
- api_name="predict",
300
- queue=True # Utiliser le système de queue pour un traitement asynchrone
301
- )
302
-
303
- if __name__ == "__main__":
304
- iface.launch(
305
- share=True,
306
- server_name="0.0.0.0",
307
- server_port=7860,
308
- max_threads=3, # Controls concurrency
309
- show_error=True
 
 
 
 
 
 
 
310
  )
311
 
 
256
  # Mettez le résultat en cache à la fin
257
  question_cache[question] = (response, context)
258
 
259
+ # # Custom CSS for right-aligned text in textboxes
260
+ # custom_css = """
261
+ # .rtl-text {
262
+ # text-align: right !important;
263
+ # direction: rtl !important;
264
+ # }
265
+ # .rtl-text textarea {
266
+ # text-align: right !important;
267
+ # direction: rtl !important;
268
+ # }
269
+ # """
270
+
271
+ # # Gradio interface with queue
272
+ # with gr.Blocks(css=custom_css) as iface:
273
+ # with gr.Column():
274
+ # input_text = gr.Textbox(
275
+ # label="السؤال",
276
+ # placeholder="اكتب سؤالك هنا...",
277
+ # lines=2,
278
+ # elem_classes="rtl-text"
279
+ # )
280
+
281
+ # with gr.Row():
282
+ # answer_box = gr.Textbox(
283
+ # label="الإجابة",
284
+ # lines=4,
285
+ # elem_classes="rtl-text"
286
+ # )
287
+ # context_box = gr.Textbox(
288
+ # label="السياق المستخدم",
289
+ # lines=8,
290
+ # elem_classes="rtl-text"
291
+ # )
292
+
293
+ # submit_btn = gr.Button("إرسال")
294
+
295
+ # submit_btn.click(
296
+ # fn=process_question,
297
+ # inputs=input_text,
298
+ # outputs=[answer_box, context_box],
299
+ # api_name="predict",
300
+ # queue=True # Utiliser le système de queue pour un traitement asynchrone
301
+ # )
302
+
303
+ # if __name__ == "__main__":
304
+ # iface.launch(
305
+ # share=True,
306
+ # server_name="0.0.0.0",
307
+ # server_port=7860,
308
+ # max_threads=3, # Controls concurrency
309
+ # show_error=True
310
+ # )
311
+
312
+ # CSS personnalisé avec l'importation de Google Fonts
313
+ custom_css = """
314
+ /* Import Google Fonts - Noto Sans Arabic */
315
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@300;400;500;600;700&display=swap');
316
+
317
+ /* Styles généraux */
318
+ :root {
319
+ --primary-color: #2D3748;
320
+ --secondary-color: #4A5568;
321
+ --accent-color: #4299E1;
322
+ --background-color: #F7FAFC;
323
+ --border-radius: 8px;
324
+ --font-family-arabic: 'Noto Sans Arabic', Arial, sans-serif;
325
+ }
326
+
327
+ /* Style de base */
328
+ body {
329
+ font-family: var(--font-family-arabic);
330
+ background-color: var(--background-color);
331
+ }
332
+
333
+ /* Styles pour le texte RTL */
334
+ .rtl-text {
335
+ text-align: right !important;
336
+ direction: rtl !important;
337
+ font-family: var(--font-family-arabic) !important;
338
+ }
339
+
340
+ .rtl-text textarea {
341
+ text-align: right !important;
342
+ direction: rtl !important;
343
+ padding: 1rem !important;
344
+ border-radius: var(--border-radius) !important;
345
+ border: 1px solid #E2E8F0 !important;
346
+ background-color: white !important;
347
+ font-size: 1.1rem !important;
348
+ line-height: 1.6 !important;
349
+ font-family: var(--font-family-arabic) !important;
350
+ }
351
+
352
+ /* Style du titre */
353
+ .app-title {
354
+ font-family: var(--font-family-arabic) !important;
355
+ font-size: 2rem !important;
356
+ font-weight: 700 !important;
357
+ color: var(--primary-color) !important;
358
+ margin-bottom: 2rem !important;
359
+ text-align: center !important;
360
+ }
361
+
362
+ /* Styles des étiquettes */
363
+ .rtl-text label {
364
+ font-family: var(--font-family-arabic) !important;
365
+ font-size: 1.2rem !important;
366
+ font-weight: 600 !important;
367
+ color: var(--primary-color) !important;
368
+ margin-bottom: 0.5rem !important;
369
+ }
370
+
371
+ /* Style du bouton */
372
+ button.primary-button {
373
+ font-family: var(--font-family-arabic) !important;
374
+ background-color: var(--accent-color) !important;
375
+ color: white !important;
376
+ padding: 0.75rem 1.5rem !important;
377
+ border-radius: var(--border-radius) !important;
378
+ font-weight: 600 !important;
379
+ font-size: 1.1rem !important;
380
+ transition: all 0.3s ease !important;
381
+ }
382
+
383
+ button.primary-button:hover {
384
+ background-color: #3182CE !important;
385
+ transform: translateY(-1px) !important;
386
+ }
387
+
388
+ /* Styles des boîtes de texte */
389
+ .textbox-container {
390
+ background-color: white !important;
391
+ padding: 1.5rem !important;
392
+ border-radius: var(--border-radius) !important;
393
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
394
+ margin-bottom: 1rem !important;
395
+ }
396
+
397
+ /* Animation de chargement */
398
+ .loading {
399
+ animation: pulse 2s infinite;
400
+ }
401
+
402
+ @keyframes pulse {
403
+ 0% { opacity: 1; }
404
+ 50% { opacity: 0.5; }
405
+ 100% { opacity: 1; }
406
+ }
407
+
408
+ /* Style du statut */
409
+ .status-text {
410
+ font-family: var(--font-family-arabic) !important;
411
+ text-align: center !important;
412
+ color: var(--secondary-color) !important;
413
+ font-size: 1rem !important;
414
+ margin-top: 1rem !important;
415
+ }
416
+ """
417
+
418
+ # Interface Gradio avec la nouvelle police
419
+ with gr.Blocks(css=custom_css) as iface:
420
+ with gr.Column(elem_classes="container"):
421
+ gr.Markdown(
422
+ "# نظام الأسئلة والأجوبة الذكي",
423
+ elem_classes="app-title rtl-text"
424
+ )
425
 
426
+ with gr.Column(elem_classes="textbox-container"):
427
+ input_text = gr.Textbox(
428
+ label="السؤال",
429
+ placeholder="اكتب سؤالك هنا...",
430
+ lines=2,
431
+ elem_classes="rtl-text"
432
+ )
 
 
 
 
433
 
434
+ with gr.Row():
435
+ with gr.Column(scale=2):
436
+ answer_box = gr.Textbox(
437
+ label="الإجابة",
438
+ lines=4,
439
+ elem_classes="rtl-text textbox-container"
440
+ )
441
+ with gr.Column(scale=1):
442
+ context_box = gr.Textbox(
443
+ label="السياق المستخدم",
444
+ lines=8,
445
+ elem_classes="rtl-text textbox-container"
446
+ )
447
+
448
+ submit_btn = gr.Button(
449
+ "إرسال السؤال",
450
+ elem_classes="primary-button",
451
+ variant="primary"
452
+ )
453
 
454
+ # Statut avec la nouvelle police
455
+ status_text = gr.Markdown("", elem_classes="rtl-text status-text")
456
+
457
+ def on_submit(question):
458
+ status_text.value = "جاري معالجة السؤال..."
459
+ return process_question(question)
460
+
461
+ submit_btn.click(
462
+ fn=on_submit,
463
+ inputs=input_text,
464
+ outputs=[answer_box, context_box, status_text],
465
+ api_name="predict",
466
+ queue=True
467
+ )
468
+
469
+ if __name__ == "__main__":
470
+ iface.launch(
471
+ share=True,
472
+ server_name="0.0.0.0",
473
+ server_port=7860,
474
+ max_threads=3,
475
+ show_error=True
476
  )
477