jdesiree commited on
Commit
9ad0161
·
verified ·
1 Parent(s): 7b02106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -31
app.py CHANGED
@@ -27,7 +27,7 @@ metrics_tracker = EduBotMetrics(save_file="edu_metrics.json")
27
 
28
  # --- LLM Templates ---
29
  # Enhanced base system message
30
- SYSTEM_MESSAGE = """You are EduBot, an expert multi-concept tutor designed to facilitate genuine learning and understanding. Your primary mission is to guide students through the learning process rather than providing direct answers to academic work.
31
 
32
  ## Core Educational Principles
33
  - Provide comprehensive, educational responses that help students truly understand concepts
@@ -274,7 +274,7 @@ def respond_with_enhanced_streaming(message, history):
274
  messages = []
275
 
276
  # Add system message
277
- system_msg = SystemMessage(content=SYSTEM_MESSAGE)
278
  messages.append(system_msg)
279
 
280
  # Add conversation history if available
@@ -295,7 +295,7 @@ def respond_with_enhanced_streaming(message, history):
295
  # Use LangChain template to format the prompt
296
  formatted_prompt = template.format(
297
  question=message,
298
- system_message=SYSTEM_MESSAGE
299
  )
300
 
301
  # Use chat completions instead of text_generation (more reliable)
@@ -373,41 +373,70 @@ custom_css = """
373
  color: #120f0e !important;
374
  }
375
 
376
- /* Main container styling */
377
  .gradio-container-5-42-0 {
378
  background-color: rgb(240, 236, 230) !important;
379
  font-family: "Oswald", sans-serif !important;
380
  color: #120f0e !important;
381
- padding-top: 0 !important;
382
- margin-top: 0 !important;
 
 
 
383
  }
384
 
385
- /* Title styling */
386
  .title-header {
387
  background-color: rgb(240, 236, 230) !important;
388
- padding: 5px 20px 10px 20px;
389
  margin: 0;
390
  border-bottom: 1pt solid #59524f;
391
  text-align: left;
392
- max-height: 30pt;
393
  }
394
  .title-header h1 {
395
- font-size: 1.8rem;
396
  font-weight: 600 !important;
397
  color: #120f0e !important;
398
  margin: 0;
399
  padding: 0;
400
  }
401
 
402
- /* Chat styling */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  .chat-container,
404
  .gradio-container-5-42-0 .gradio-chatbot,
405
  .gradio-container-5-42-0 #main-chatbot {
406
  background-color: #d9d1ce !important;
407
  border: 1pt solid #59524f !important;
408
  border-radius: 6px !important;
409
- padding: 20px !important;
410
- min-height: 900px;
 
 
411
  }
412
 
413
  /* Message styling */
@@ -422,6 +451,7 @@ custom_css = """
422
  margin-right: auto;
423
  word-wrap: break-word;
424
  font-weight: 400 !important;
 
425
  }
426
 
427
  .gradio-container-5-42-0 .gradio-chatbot .message.user .markdown {
@@ -435,52 +465,61 @@ custom_css = """
435
  margin-right: 0;
436
  word-wrap: break-word;
437
  font-weight: 400 !important;
 
438
  }
439
 
440
- /* Input section styling */
441
  .input-section {
442
  background-color: rgb(240, 236, 230) !important;
443
  border-top: 1pt solid #59524f;
444
- padding: 20px;
 
 
 
 
445
  }
446
 
447
- /* Button styling */
448
- .gradio-container-5-42-0 .send-button {
449
- background-color: #f09c7d !important;
450
  color: #120f0e !important;
451
  border: 1pt solid #59524f !important;
452
  border-radius: 6px !important;
453
- padding: 8px 16px !important;
454
  cursor: pointer !important;
455
- margin: 5px !important;
456
  font-weight: 500 !important;
 
 
 
 
 
 
457
  }
458
 
459
  .gradio-container-5-42-0 .clear-button {
460
  background-color: #ada3a0 !important;
461
- color: #120f0e !important;
462
- border: 1pt solid #59524f !important;
463
- border-radius: 6px !important;
464
- padding: 8px 16px !important;
465
- cursor: pointer !important;
466
- margin: 5px !important;
467
- font-weight: 500 !important;
468
  }
469
 
470
- /* Textbox styling */
471
  .gradio-container-5-42-0 .input-textbox {
472
  background-color: #d9d1ce !important;
473
  border: 1pt solid #59524f !important;
474
  border-radius: 8px !important;
 
475
  }
476
 
477
  .gradio-container-5-42-0 .input-textbox textarea {
478
  background-color: #d9d1ce !important;
479
  border: none !important;
480
  color: #120f0e !important;
481
- padding: 15px !important;
482
- font-size: 16px !important;
483
  font-weight: 400 !important;
 
 
 
 
484
  }
485
 
486
  .gradio-container-5-42-0 .input-textbox textarea::placeholder {
@@ -564,7 +603,7 @@ def clear_chat():
564
  def create_interface():
565
  """Creates and configures the complete Gradio interface."""
566
 
567
- with gr.Blocks(css=custom_css, title="EduBot", fill_width=True) as demo:
568
  # Add head content and MathJax
569
  gr.HTML(html_head_content)
570
  gr.HTML('<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>')
 
27
 
28
  # --- LLM Templates ---
29
  # Enhanced base system message
30
+ ENHANCED_SYSTEM_MESSAGE = """You are EduBot, an expert multi-concept tutor designed to facilitate genuine learning and understanding. Your primary mission is to guide students through the learning process rather than providing direct answers to academic work.
31
 
32
  ## Core Educational Principles
33
  - Provide comprehensive, educational responses that help students truly understand concepts
 
274
  messages = []
275
 
276
  # Add system message
277
+ system_msg = SystemMessage(content=ENHANCED_SYSTEM_MESSAGE)
278
  messages.append(system_msg)
279
 
280
  # Add conversation history if available
 
295
  # Use LangChain template to format the prompt
296
  formatted_prompt = template.format(
297
  question=message,
298
+ system_message=ENHANCED_SYSTEM_MESSAGE
299
  )
300
 
301
  # Use chat completions instead of text_generation (more reliable)
 
373
  color: #120f0e !important;
374
  }
375
 
376
+ /* Main container styling - viewport height */
377
  .gradio-container-5-42-0 {
378
  background-color: rgb(240, 236, 230) !important;
379
  font-family: "Oswald", sans-serif !important;
380
  color: #120f0e !important;
381
+ padding: 0 !important;
382
+ margin: 0 !important;
383
+ height: 100vh !important;
384
+ max-height: 100vh !important;
385
+ overflow: hidden !important;
386
  }
387
 
388
+ /* Title styling - compact */
389
  .title-header {
390
  background-color: rgb(240, 236, 230) !important;
391
+ padding: 10px 20px;
392
  margin: 0;
393
  border-bottom: 1pt solid #59524f;
394
  text-align: left;
395
+ flex-shrink: 0;
396
  }
397
  .title-header h1 {
398
+ font-size: 1.5rem;
399
  font-weight: 600 !important;
400
  color: #120f0e !important;
401
  margin: 0;
402
  padding: 0;
403
  }
404
 
405
+ /* Row container styling */
406
+ .main-row {
407
+ height: calc(100vh - 60px) !important;
408
+ display: flex !important;
409
+ flex-direction: column !important;
410
+ }
411
+
412
+ .title-row {
413
+ flex-shrink: 0 !important;
414
+ height: 60px !important;
415
+ }
416
+
417
+ .chat-row {
418
+ flex: 1 !important;
419
+ overflow: hidden !important;
420
+ padding: 10px 20px !important;
421
+ }
422
+
423
+ .input-row {
424
+ flex-shrink: 0 !important;
425
+ height: 120px !important;
426
+ padding: 15px 20px !important;
427
+ }
428
+
429
+ /* Chat styling - use remaining space */
430
  .chat-container,
431
  .gradio-container-5-42-0 .gradio-chatbot,
432
  .gradio-container-5-42-0 #main-chatbot {
433
  background-color: #d9d1ce !important;
434
  border: 1pt solid #59524f !important;
435
  border-radius: 6px !important;
436
+ padding: 15px !important;
437
+ height: 100% !important;
438
+ max-height: 100% !important;
439
+ overflow-y: auto !important;
440
  }
441
 
442
  /* Message styling */
 
451
  margin-right: auto;
452
  word-wrap: break-word;
453
  font-weight: 400 !important;
454
+ margin-bottom: 10px !important;
455
  }
456
 
457
  .gradio-container-5-42-0 .gradio-chatbot .message.user .markdown {
 
465
  margin-right: 0;
466
  word-wrap: break-word;
467
  font-weight: 400 !important;
468
+ margin-bottom: 10px !important;
469
  }
470
 
471
+ /* Input section styling - compact */
472
  .input-section {
473
  background-color: rgb(240, 236, 230) !important;
474
  border-top: 1pt solid #59524f;
475
+ padding: 0 !important;
476
+ height: 100% !important;
477
+ display: flex !important;
478
+ align-items: center !important;
479
+ gap: 10px !important;
480
  }
481
 
482
+ /* Button styling - compact */
483
+ .gradio-container-5-42-0 .send-button,
484
+ .gradio-container-5-42-0 .clear-button {
485
  color: #120f0e !important;
486
  border: 1pt solid #59524f !important;
487
  border-radius: 6px !important;
488
+ padding: 8px 12px !important;
489
  cursor: pointer !important;
490
+ margin: 0 !important;
491
  font-weight: 500 !important;
492
+ height: 40px !important;
493
+ min-width: 70px !important;
494
+ }
495
+
496
+ .gradio-container-5-42-0 .send-button {
497
+ background-color: #f09c7d !important;
498
  }
499
 
500
  .gradio-container-5-42-0 .clear-button {
501
  background-color: #ada3a0 !important;
 
 
 
 
 
 
 
502
  }
503
 
504
+ /* Textbox styling - compact */
505
  .gradio-container-5-42-0 .input-textbox {
506
  background-color: #d9d1ce !important;
507
  border: 1pt solid #59524f !important;
508
  border-radius: 8px !important;
509
+ flex: 1 !important;
510
  }
511
 
512
  .gradio-container-5-42-0 .input-textbox textarea {
513
  background-color: #d9d1ce !important;
514
  border: none !important;
515
  color: #120f0e !important;
516
+ padding: 10px !important;
517
+ font-size: 14px !important;
518
  font-weight: 400 !important;
519
+ resize: none !important;
520
+ height: 40px !important;
521
+ min-height: 40px !important;
522
+ max-height: 40px !important;
523
  }
524
 
525
  .gradio-container-5-42-0 .input-textbox textarea::placeholder {
 
603
  def create_interface():
604
  """Creates and configures the complete Gradio interface."""
605
 
606
+ with gr.Blocks(css=custom_css, title="EduBot", fill_width=True, fill_height=True) as demo:
607
  # Add head content and MathJax
608
  gr.HTML(html_head_content)
609
  gr.HTML('<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>')