Spaces:
Sleeping
Sleeping
File size: 26,593 Bytes
081aa78 e082ba0 985f660 081aa78 828506c 985f660 081aa78 828506c 081aa78 985f660 081aa78 4efdd4f e72598d 925e56a e72598d 925e56a e72598d 925e56a e72598d 925e56a e72598d 4efdd4f 081aa78 4efdd4f ce9afbc 4efdd4f 40b77ee 9722b11 40b77ee e0b1dab 9b3e5f9 e4c3ab9 40b77ee 25a2f04 081aa78 985f660 eddd27f 027dc6f 081aa78 4c1c4a5 081aa78 4c1c4a5 081aa78 4c1c4a5 081aa78 985f660 027dc6f eddd27f 027dc6f 4c1c4a5 081aa78 31c81a3 4c1c4a5 081aa78 4c1c4a5 081aa78 4c1c4a5 081aa78 027dc6f 985f660 31c81a3 eddd27f 027dc6f 4c1c4a5 027dc6f 081aa78 027dc6f 081aa78 eddd27f 027dc6f 081aa78 027dc6f 081aa78 027dc6f 081aa78 027dc6f 081aa78 027dc6f eddd27f 027dc6f 081aa78 027dc6f 4efdd4f 027dc6f 4efdd4f 027dc6f 4efdd4f 027dc6f 4efdd4f 7610afa 081aa78 3667e41 ce9afbc 081aa78 3667e41 ce9afbc 081aa78 3667e41 081aa78 828506c 081aa78 828506c 081aa78 828506c 081aa78 828506c 081aa78 985f660 081aa78 828506c 081aa78 9b3e5f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 |
import gradio as gr
from core.utils.translations import translations
def get_custom_css():
"""Enhanced CSS with medical theme"""
css = """
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
* {
font-family: 'Inter', sans-serif !important;
}
.gradio-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
/* Prevent dropdown menus from being cut off */
.gradio-container, body {
overflow: visible !important;
}
.gr-dropdown .wrap, .gr-dropdown .container {
position: relative !important;
z-index: 9999 !important;
}
/* Optional: Better dropdown style */
.gr-dropdown {
min-height: 42px;
font-size: 1rem;
}
.button.example-scenario-btn {
white-space: normal !important;
overflow-wrap: break-word !important;
text-overflow: unset !important;
max-width: 100% !important;
}
.main-container {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 30px;
margin: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
border: 1px solid rgba(255,255,255,0.2);
}
.header-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 15px;
padding: 25px;
margin-bottom: 25px;
text-align: center;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.query-container {
background: linear-gradient(135deg, #f8f9ff 0%, #e8f2ff 100%);
border-radius: 15px;
padding: 20px;
margin: 15px 0;
border: 2px solid #667eea;
transition: all 0.3s ease;
}
.response-container {
background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
border-radius: 15px;
padding: 20px;
margin: 15px 0;
border: 2px solid #4CAF50;
min-height: 300px;
}
.submit-btn {
background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%) !important;
color: white !important;
border: none !important;
border-radius: 12px !important;
padding: 15px 30px !important;
font-size: 16px !important;
font-weight: 600 !important;
cursor: pointer !important;
transition: all 0.3s ease !important;
box-shadow: 0 6px 20px rgba(76, 175, 80, 0.3) !important;
}
.submit-btn:hover {
transform: translateY(-3px) !important;
box-shadow: 0 10px 30px rgba(76, 175, 80, 0.4) !important;
}
.stats-container {
background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
border-radius: 12px;
padding: 15px;
margin: 10px 0;
border-left: 5px solid #2196F3;
font-size: 14px;
}
.example-scenario-btn {
white-space: normal !important;
text-overflow: unset !important;
overflow-wrap: break-word !important;
font-size: 1rem;
padding: 0.7rem 1rem;
width: 100%;
text-align: left;
background-color: #f8f9fc;
border: 1px solid #d0d7e2;
border-radius: 8px;
margin-bottom: 0.5rem;
.button-radio input[type="radio"] {
display: none;
}
.button-radio label {
display: inline-block;
padding: 10px 20px;
margin: 6px 8px;
border-radius: 999px;
border: 2px solid #4098ff;
background-color: white;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.button-radio input[type="radio"]:checked + label {
background-color: #4098ff;
color: white;
border-color: #1465c0;
}
}
.quiz-container {
background: linear-gradient(135deg, #f0f7ff 0%, #e8f4f8 100%);
border-radius: 20px;
padding: 30px;
margin: 20px 0;
border: 2px solid #4CAF50;
box-shadow: 0 15px 35px rgba(76, 175, 80, 0.15);
transition: all 0.3s ease;
}
.quiz-container:hover {
transform: translateY(-2px);
box-shadow: 0 20px 45px rgba(76, 175, 80, 0.2);
}
.quiz-question {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border-radius: 15px;
padding: 20px;
margin: 15px 0;
border-left: 5px solid #667eea;
font-size: 1.1em;
font-weight: 600;
color: #2c3e50;
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.1);
}
.quiz-options {
margin: 20px 0;
}
.quiz-option {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border: 2px solid #e3f2fd;
border-radius: 12px;
padding: 15px 20px;
margin: 10px 0;
cursor: pointer;
transition: all 0.3s ease;
font-size: 1rem;
color: #34495e;
position: relative;
overflow: hidden;
}
.quiz-option:before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
transition: left 0.5s;
}
.quiz-option:hover {
border-color: #667eea;
transform: translateX(5px);
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}
.quiz-option:hover:before {
left: 100%;
}
.quiz-option.selected {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-color: #5a67d8;
transform: translateX(8px);
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.quiz-submit-btn {
background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%) !important;
color: white !important;
border: none !important;
border-radius: 15px !important;
padding: 18px 40px !important;
font-size: 18px !important;
font-weight: 700 !important;
cursor: pointer !important;
transition: all 0.3s ease !important;
box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3) !important;
text-transform: uppercase !important;
letter-spacing: 1px !important;
margin: 20px 0 !important;
width: 100% !important;
max-width: 300px !important;
}
.quiz-submit-btn:hover {
transform: translateY(-3px) scale(1.02) !important;
box-shadow: 0 12px 35px rgba(76, 175, 80, 0.4) !important;
background: linear-gradient(135deg, #45a049 0%, #4CAF50 100%) !important;
}
.quiz-submit-btn:active {
transform: translateY(-1px) scale(0.98) !important;
}
.quiz-results {
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
border-radius: 15px;
padding: 25px;
margin: 20px 0;
border-left: 5px solid #f39c12;
box-shadow: 0 10px 25px rgba(243, 156, 18, 0.15);
}
.quiz-result-item {
background: white;
border-radius: 12px;
padding: 20px;
margin: 15px 0;
border-left: 4px solid #3498db;
box-shadow: 0 5px 15px rgba(52, 152, 219, 0.1);
transition: all 0.3s ease;
}
.quiz-result-item:hover {
transform: translateX(5px);
box-shadow: 0 8px 20px rgba(52, 152, 219, 0.15);
}
.quiz-result-correct {
border-left-color: #27ae60 !important;
background: linear-gradient(135deg, #d5f4e6 0%, #ffffff 100%) !important;
}
.quiz-result-incorrect {
border-left-color: #e74c3c !important;
background: linear-gradient(135deg, #ffeaea 0%, #ffffff 100%) !important;
}
.quiz-feedback {
background: linear-gradient(135deg, #e8f5e8 0%, #f0f8f0 100%);
border-radius: 10px;
padding: 15px;
margin: 10px 0;
border-left: 3px solid #27ae60;
font-style: italic;
color: #2d5a2d;
}
.quiz-header {
text-align: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 20px;
padding: 25px;
margin: 20px 0;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.quiz-header h2 {
margin: 0;
font-size: 2em;
font-weight: 700;
text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.quiz-progress {
background: #e3f2fd;
border-radius: 10px;
padding: 10px 20px;
margin: 15px 0;
text-align: center;
font-weight: 600;
color: #1976d2;
border: 2px solid #bbdefb;
}
/* Animation for quiz generation */
@keyframes quiz-fade-in {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.quiz-container {
animation: quiz-fade-in 0.6s ease-out;
}
/* Responsive design for quiz components */
@media (max-width: 768px) {
.quiz-container {
padding: 20px;
margin: 10px;
}
.quiz-question {
padding: 15px;
font-size: 1rem;
}
.quiz-option {
padding: 12px 15px;
font-size: 0.9rem;
}
.quiz-submit-btn {
padding: 15px 30px !important;
font-size: 16px !important;
}
.quiz-header h2 {
font-size: 1.5em;
}
}
.quiz-block-container {
max-height: none !important;
overflow: visible !important;
}
.gradio-container {
overflow-y: auto;
scroll-behavior: smooth;
}
html, body {
scroll-behavior: smooth;
}
.quiz-result-output {
margin-top: 2em;
}
/* Dark Mode Adjustments */
@media (prefers-color-scheme: dark) {
.main-container {
background: rgba(40, 40, 40, 0.95);
color: #e0e0e0;
border: 1px solid rgba(70, 70, 70, 0.2);
}
.header-section {
background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.query-container {
background: linear-gradient(135deg, #303030 0%, #252525 100%);
border: 2px solid #555;
}
.response-container {
background: linear-gradient(135deg, #252525 0%, #303030 100%);
border: 2px solid #666;
}
.stats-container {
background: linear-gradient(135deg, #353535 0%, #404040 100%);
border-left: 5px solid #666;
}
.example-scenario-btn {
background-color: #333;
border: 1px solid #555;
color: #e0e0e0;
}
.quiz-container {
background: linear-gradient(135deg, #303030 0%, #252525 100%);
border: 2px solid #666;
}
.quiz-question {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border-left: 5px solid #666;
color: #e0e0e0;
}
.quiz-option {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border: 2px solid #444;
color: #e0e0e0;
}
.quiz-option:hover {
border-color: #888;
}
.quiz-option.selected {
background: linear-gradient(135deg, #555 0%, #666 100%);
border-color: #777;
}
.quiz-results {
background: linear-gradient(135deg, #303030 0%, #252525 100%);
border-left: 5px solid #888;
}
.quiz-result-item {
background: #333;
border-left: 4px solid #666;
color: #e0e0e0;
}
.quiz-result-correct {
border-left-color: #4CAF50 !important;
background: linear-gradient(135deg, #2d4d2d 0%, #3a3a3a 100%) !important;
}
.quiz-result-incorrect {
border-left-color: #e74c3c !important;
background: linear-gradient(135deg, #4d2d2d 0%, #3a3a3a 100%) !important;
}
.quiz-feedback {
background: linear-gradient(135deg, #3a3a3a 0%, #404040 100%);
border-left: 3px solid #4CAF50;
color: #a0a0a0;
}
.quiz-header {
background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%);
}
.quiz-progress {
background: #3a3a3a;
border: 2px solid #555;
color: #a0a0a0;
}
}
.quiz-result-output {
border: 1px solid #ccc;
background: #f9f9f9;
padding: 1rem;
border-radius: 10px;
margin-top: 1rem;
font-size: 1.05rem;
line-height: 1.6;
}
/* Quiz question blocks */
.gr-markdown {
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
/* Radio buttons */
.gr-radio {
margin-bottom: 1.5rem;
}
/* Submit button spacing */
button {
margin-top: 1rem;
}
/* Result highlights */
.quiz-result-output strong {
color: #333;
}
.quiz-result-output .correct {
color: green;
font-weight: bold;
}
.quiz-result-output .incorrect {
color: red;
font-weight: bold;
}
/* Quiz summary at the top */
.quiz-result-output h2, .quiz-result-output h3 {
margin-top: 1rem;
color: #1e40af;
}
.scenario-generator-container {
background: linear-gradient(135deg, #f8f9ff 0%, #e8f2ff 100%);
border-radius: 20px;
padding: 30px;
margin: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
border: 2px solid #667eea;
transition: all 0.3s ease;
}
.scenario-generator-container:hover {
transform: translateY(-2px);
box-shadow: 0 25px 50px rgba(102, 126, 234, 0.15);
}
.scenario-generator-container .gr-textbox {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border-radius: 12px;
border: 2px solid #e3f2fd;
padding: 15px;
font-size: 1rem;
transition: all 0.3s ease;
}
.scenario-generator-container .gr-textbox:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
transform: translateY(-1px);
}
.scenario-generator-container .gr-slider {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border-radius: 12px;
border: 2px solid #e3f2fd;
padding: 15px;
margin: 10px 0;
}
.scenario-generator-container .gr-button {
border-radius: 12px;
padding: 15px 30px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 1px;
}
.scenario-generator-container .gr-button[variant="primary"] {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
color: white !important;
border: none !important;
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3) !important;
}
.scenario-generator-container .gr-button[variant="primary"]:hover {
transform: translateY(-3px) scale(1.02) !important;
box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4) !important;
background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%) !important;
}
.scenario-generator-container .gr-label {
font-weight: 600;
color: #2c3e50;
font-size: 1.1rem;
margin-bottom: 8px;
}
.scenario-generator-container .gr-markdown h3 {
color: #2c3e50;
font-size: 1.8em;
font-weight: 700;
margin-bottom: 1.5em;
text-align: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.scenario-generator-container .gr-markdown {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border-radius: 12px;
padding: 15px;
margin: 10px 0;
border-left: 4px solid #667eea;
font-size: 1rem;
line-height: 1.6;
}
/* Enhanced quiz styling within scenario generator */
.scenario-generator-container .quiz-result-output {
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
border-radius: 15px;
padding: 25px;
margin: 20px 0;
border-left: 5px solid #f39c12;
box-shadow: 0 10px 25px rgba(243, 156, 18, 0.15);
font-size: 1.05rem;
line-height: 1.6;
}
.scenario-generator-container .gr-radio {
background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
border-radius: 10px;
padding: 10px;
margin: 10px 0;
border: 1px solid #e3f2fd;
}
/* Dark mode adjustments for scenario generator */
@media (prefers-color-scheme: dark) {
.scenario-generator-container {
background: linear-gradient(135deg, #303030 0%, #252525 100%);
color: #e0e0e0;
border: 2px solid #555;
}
.scenario-generator-container .gr-textbox {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border: 2px solid #444;
color: #e0e0e0;
}
.scenario-generator-container .gr-textbox:focus {
border-color: #888;
box-shadow: 0 0 0 3px rgba(136, 136, 136, 0.1);
}
.scenario-generator-container .gr-slider {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border: 2px solid #444;
}
.scenario-generator-container .gr-label {
color: #e0e0e0;
}
.scenario-generator-container .gr-markdown h3 {
color: #e0e0e0;
background: linear-gradient(135deg, #888 0%, #666 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.scenario-generator-container .gr-markdown {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border-left: 4px solid #666;
color: #e0e0e0;
}
.scenario-generator-container .gr-button[variant="primary"] {
background: linear-gradient(135deg, #3a3a3a 0%, #2a2a2a 100%) !important;
color: #e0e0e0 !important;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3) !important;
}
.scenario-generator-container .gr-button[variant="primary"]:hover {
background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%) !important;
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4) !important;
}
.scenario-generator-container .quiz-result-output {
background: linear-gradient(135deg, #303030 0%, #252525 100%);
border-left: 5px solid #888;
color: #e0e0e0;
}
.scenario-generator-container .gr-radio {
background: linear-gradient(135deg, #2a2a2a 0%, #353535 100%);
border: 1px solid #444;
}
}
"""
return css
def create_header_section(language="English"):
from core.utils.translations import translations
t = translations.get(language, translations["English"])
return gr.HTML(f"""
<div class="header-section">
<h1 style="margin: 0; font-size: 2.5em; font-weight: 700;">
{t['header_title']}
</h1>
<h2 style="margin: 10px 0 0 0; font-size: 1.2em; font-weight: 400; opacity: 0.9;">
{t['header_subtitle']}
</h2>
<p style="margin: 15px 0 0 0; font-size: 1em; opacity: 0.8;">
{t['header_description']}
</p>
</div>
""")
def create_query_input_section(language="English"):
from core.utils.translations import translations
t = translations.get(language, translations["English"])
with gr.Group(elem_classes=["query-container"]) as container:
gr.Markdown(t["query_heading"])
query_input = gr.Textbox(
label=t["query_input_label"],
placeholder=t["query_placeholder"],
lines=4
)
with gr.Row():
submit_btn = gr.Button(
t["submit_btn"],
variant="primary",
elem_classes=["submit-btn"],
scale=3
)
clear_btn = gr.Button(
t["clear_btn"],
variant="secondary",
scale=1
)
return container, query_input, submit_btn, clear_btn
def create_response_output_section(language="English"):
from core.utils.translations import translations
t = translations.get(language, translations["English"])
with gr.Group(elem_classes=["response-container"]) as container:
gr.Markdown(t["response_heading"])
response_output = gr.Textbox(
label=t["response_label"],
lines=15,
interactive=False,
placeholder=t["response_placeholder"]
)
with gr.Row():
with gr.Column(scale=1):
metadata_output = gr.Textbox(
label=t["metadata_label"],
lines=2,
interactive=False,
placeholder=t["metadata_placeholder"]
)
with gr.Column(scale=1):
status_output = gr.Textbox(
label=t["safety_label"],
lines=2,
interactive=False,
placeholder=t["safety_placeholder"]
)
return container, response_output, metadata_output, status_output
def create_quick_access_section(language="English"):
from core.utils.translations import translations
t = translations.get(language, translations["English"])
return gr.Markdown(f"""
### β‘ {t['quick_heading']}
**π {t['quick_performance']}:**
- {t['quick_faiss']}
- {t['quick_embedding']}
- {t['quick_speed']}
- {t['quick_context']}
**π {t['quick_knowledge']}:**
- {t['quick_who']}
- {t['quick_icrc']}
- {t['quick_msf']}
- {t['quick_adaptations']}
**π‘οΈ {t['quick_safety']}:**
- {t['quick_factcheck']}
- {t['quick_contraindications']}
- {t['quick_resource_warnings']}
- {t['quick_disclaimer']}
""")
def create_example_scenarios(query_input, language="English"):
from core.utils.translations import translations
t = translations.get(language, translations["English"])
# Translate these if needed later
example_queries = t.get("example_queries", [
"How to treat severe burns when clean water is extremely limited?",
"Managing gunshot wounds with only basic household supplies",
"Recognizing and treating infection in wounds without antibiotics",
"Emergency care for children during extended power outages",
"Treating compound fractures without proper medical equipment"
])
with gr.Column(elem_classes=["example-scenarios"]):
gr.Markdown(f"### π‘ {t['example_heading']}\n[π§ͺ {t['example_hint']}](#)")
for query in example_queries:
# Use default arguments to avoid late binding bug
def set_query(q=query):
return q
gr.Button(query, elem_classes=["example-scenario-btn"]).click(
fn=set_query,
outputs=[query_input]
)
def create_scenario_component():
with gr.Column(elem_classes=["scenario-container"]) as container:
scenario_question = gr.Markdown("", elem_id="scenario-question")
scenario_options = gr.Radio(choices=[], label="Choose your answer", interactive=True, elem_classes=["button-radio"], elem_id="scenario-options")
scenario_feedback = gr.Markdown("", elem_id="scenario-feedback")
scenario_next_button = gr.Button("Next Question", visible=False, elem_classes=["submit-btn"], elem_id="scenario-next-button")
scenario_start_button = gr.Button("Start Scenario", visible=True, elem_classes=["submit-btn"], elem_id="scenario-start-button")
scenario_query_input = gr.Textbox(label="Enter a medical query to generate a scenario", placeholder="e.g., choking baby", lines=2, elem_id="scenario-query-input")
scenario_generate_button = gr.Button("Generate Scenario", elem_classes=["submit-btn"], elem_id="scenario-generate-button")
return container, scenario_question, scenario_options, scenario_feedback, scenario_next_button, scenario_start_button, scenario_query_input, scenario_generate_button
import gradio as gr
def gradio_user_selector():
"""Gradio dropdown for user role selection"""
return gr.Radio(choices=["π Volunteer", "π Event Organizer"], label="Select your role", value="π Volunteer", interactive=True, elem_classes=["button-radio"])
def gradio_sidebar_controls():
"""Gradio sidebar settings with language selector"""
language_dropdown = gr.Radio(choices=["English", "Arabic"], label="π Language", value="English", interactive=True, elem_classes=["button-radio"])
return language_dropdown
def gradio_show_response(response: str, metadata: dict, safety: dict):
"""Gradio equivalent of Streamlit's show_response"""
# Prepare the response content
response_text = gr.Markdown(f"### AI Response\n{response}")
# Prepare the metadata display
confidence = metadata.get("confidence", 0)
response_time = metadata.get("response_time", 0)
metadata_text = f"### Metadata\n- Confidence: {confidence:.1%}\n- Response Time: {response_time}s"
metadata_display = gr.Markdown(metadata_text)
# Prepare the safety display
safety_status = ""
if safety.get("is_safe", False):
safety_status += "β
Safe Response\n"
else:
safety_status += "β οΈ Review Needed\n"
if safety.get("warnings"):
safety_status += "Warnings: " + ", ".join(safety["warnings"]) + "\n"
if safety.get("issues"):
safety_status += "Issues: " + ", ".join(safety["issues"]) + "\n"
safety_display = gr.Markdown(f"### Safety Check\n{safety_status}")
return response_text, metadata_display, safety_display
|