Trabis commited on
Commit
4568a73
·
verified ·
1 Parent(s): f6c9b0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -18
app.py CHANGED
@@ -205,7 +205,8 @@ mistral_api_key = os.getenv("mistral_api_key")
205
  llm = ChatMistralAI(
206
  model="mistral-large-latest",
207
  mistral_api_key=mistral_api_key,
208
- temperature=0.1 # Lower temperature for faster responses
 
209
  )
210
 
211
  rag_loader = OptimizedRAGLoader()
@@ -372,7 +373,7 @@ button.primary-button:hover {
372
  }
373
  """
374
 
375
- # Interface Gradio avec la correction
376
  with gr.Blocks(css=custom_css) as iface:
377
  with gr.Column(elem_classes="container"):
378
  gr.Markdown(
@@ -395,33 +396,26 @@ with gr.Blocks(css=custom_css) as iface:
395
  lines=5,
396
  elem_classes="rtl-text textbox-container"
397
  )
398
- # with gr.Column(scale=1):
399
- # context_box = gr.Textbox(
400
- # label="السياق المستخدم",
401
- # lines=4,
402
- # elem_classes="rtl-text textbox-container"
403
- # )
404
 
405
  submit_btn = gr.Button(
406
  "إرسال السؤال",
407
  elem_classes="primary-button",
408
  variant="primary"
409
  )
410
-
411
 
412
- def on_submit(question):
413
- for response, context in process_question(question):
414
- yield response # Yield À CHAQUE itération
 
 
415
 
416
-
417
  submit_btn.click(
418
- fn=on_submit,
419
  inputs=input_text,
420
  outputs=answer_box,
421
  api_name="predict",
422
- queue=False,
423
- )
424
-
425
 
426
  if __name__ == "__main__":
427
  iface.launch(
@@ -429,9 +423,69 @@ if __name__ == "__main__":
429
  server_name="0.0.0.0",
430
  server_port=7860,
431
  max_threads=3,
432
- show_error=True,
433
  )
434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  # def process_question(question: str):
436
  # """
437
  # Process the question and yield the answer progressively.
 
205
  llm = ChatMistralAI(
206
  model="mistral-large-latest",
207
  mistral_api_key=mistral_api_key,
208
+ temperature=0.1,
209
+ streaming=True,
210
  )
211
 
212
  rag_loader = OptimizedRAGLoader()
 
373
  }
374
  """
375
 
376
+ # Interface Gradio avec streaming
377
  with gr.Blocks(css=custom_css) as iface:
378
  with gr.Column(elem_classes="container"):
379
  gr.Markdown(
 
396
  lines=5,
397
  elem_classes="rtl-text textbox-container"
398
  )
 
 
 
 
 
 
399
 
400
  submit_btn = gr.Button(
401
  "إرسال السؤال",
402
  elem_classes="primary-button",
403
  variant="primary"
404
  )
 
405
 
406
+ def stream_response(question):
407
+ response_stream = process_question(question)
408
+ for response, _ in response_stream:
409
+ gr.update(value=response)
410
+ yield response
411
 
 
412
  submit_btn.click(
413
+ fn=stream_response,
414
  inputs=input_text,
415
  outputs=answer_box,
416
  api_name="predict",
417
+ queue=False
418
+ )
 
419
 
420
  if __name__ == "__main__":
421
  iface.launch(
 
423
  server_name="0.0.0.0",
424
  server_port=7860,
425
  max_threads=3,
426
+ show_error=True
427
  )
428
 
429
+ # # Interface Gradio avec la correction
430
+ # with gr.Blocks(css=custom_css) as iface:
431
+ # with gr.Column(elem_classes="container"):
432
+ # gr.Markdown(
433
+ # "# نظام الأسئلة والأجوبة الذكي",
434
+ # elem_classes="app-title rtl-text"
435
+ # )
436
+
437
+ # with gr.Column(elem_classes="textbox-container"):
438
+ # input_text = gr.Textbox(
439
+ # label="السؤال",
440
+ # placeholder="اكتب سؤالك هنا...",
441
+ # lines=1,
442
+ # elem_classes="rtl-text"
443
+ # )
444
+
445
+ # with gr.Row():
446
+ # with gr.Column():
447
+ # answer_box = gr.Textbox(
448
+ # label="الإجابة",
449
+ # lines=5,
450
+ # elem_classes="rtl-text textbox-container"
451
+ # )
452
+ # # with gr.Column(scale=1):
453
+ # # context_box = gr.Textbox(
454
+ # # label="السياق المستخدم",
455
+ # # lines=4,
456
+ # # elem_classes="rtl-text textbox-container"
457
+ # # )
458
+
459
+ # submit_btn = gr.Button(
460
+ # "إرسال السؤال",
461
+ # elem_classes="primary-button",
462
+ # variant="primary"
463
+ # )
464
+
465
+
466
+ # def on_submit(question):
467
+ # for response, context in process_question(question):
468
+ # yield response # Yield À CHAQUE itération
469
+
470
+
471
+ # submit_btn.click(
472
+ # fn=on_submit,
473
+ # inputs=input_text,
474
+ # outputs=answer_box,
475
+ # api_name="predict",
476
+ # queue=False,
477
+ # )
478
+
479
+
480
+ # if __name__ == "__main__":
481
+ # iface.launch(
482
+ # share=True,
483
+ # server_name="0.0.0.0",
484
+ # server_port=7860,
485
+ # max_threads=3,
486
+ # show_error=True,
487
+ # )
488
+
489
  # def process_question(question: str):
490
  # """
491
  # Process the question and yield the answer progressively.