File size: 39,256 Bytes
41a320c 3a338e5 41a320c 3a338e5 41a320c a4126ee 3a338e5 a4126ee 3a338e5 a4126ee 41a320c 3a338e5 a4126ee 41a320c 485f265 41a320c a4126ee 41a320c 3a338e5 41a320c 3a338e5 41a320c 72123d0 41a320c 3a338e5 41a320c 3a338e5 41a320c 72123d0 41a320c 3a338e5 41a320c 3a338e5 41a320c 72123d0 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 485f265 41a320c 485f265 09ab9b3 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 3a338e5 41a320c 485f265 09ab9b3 41a320c 09ab9b3 41a320c 09ab9b3 41a320c 72123d0 41a320c 3a338e5 41a320c 72123d0 41a320c 72123d0 09ab9b3 485f265 72123d0 485f265 72123d0 41a320c 72123d0 41a320c 72123d0 41a320c a4126ee 41a320c |
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 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
"""
κ°νΈ μΈμμΈκ³ κ΅μ‘ νλ«νΌ - Gradio λ©ν°νμ΄μ§ μ ν리μΌμ΄μ
(μ±ν
κΈ°λ°)
"""
import os
import gradio as gr
from services.gemini_service import GeminiEvaluator
from services.supabase_service import SupabaseService
from config.database import supabase_client
# λ°μ΄ν°λ² μ΄μ€ μ΄κΈ°ν
try:
print("π λ°μ΄ν°λ² μ΄μ€ μ°κ²° μλ μ€...")
# Supabase μλΉμ€ μ΄κΈ°ν
if supabase_client:
try:
supabase_service = SupabaseService()
print("β
Supabase ν΄λΌμ΄μΈνΈ μ΄κΈ°ν μλ£")
# μλλ¦¬μ€ λ°μ΄ν° λ‘λ (ν
μ΄λΈμ΄ μλ κ²½μ° λ¬΄μ)
try:
print("π₯ μλλ¦¬μ€ λ°μ΄ν° λ‘λ μ€...")
supabase_service.load_scenarios_from_json("data/scenarios.json")
print("β
μλλ¦¬μ€ λ°μ΄ν° λ‘λ μλ£")
except Exception as load_error:
print(f"β οΈ μλλ¦¬μ€ λ°μ΄ν° λ‘λ μ€ν¨: {load_error}")
print(" (μ΄λ―Έ λ°μ΄ν°κ° μκ±°λ ν
μ΄λΈμ΄ μμ μ μμ΅λλ€)")
except Exception as service_error:
print(f"β οΈ Supabase μλΉμ€ μ΄κΈ°ν μ€ν¨: {service_error}")
supabase_service = None
else:
print("β οΈ Supabase ν΄λΌμ΄μΈνΈκ° μ΄κΈ°νλμ§ μμμ΅λλ€.")
print(" νκ²½ λ³μ SUPABASE_URLκ³Ό SUPABASE_ANON_KEYλ₯Ό νμΈνμΈμ.")
supabase_service = None
except Exception as e:
print(f"β οΈ λ°μ΄ν°λ² μ΄μ€ μ΄κΈ°ν μ€ μ€λ₯: {e}")
import traceback
traceback.print_exc()
supabase_service = None
# Gemini νκ°κΈ° μ΄κΈ°ν
evaluator = GeminiEvaluator()
# μ΄κΈ° νμ ID μμ± (TSID κΈ°λ°)
from tsidpy import TSID
tsid = TSID.create()
initial_student_id = f"student_{tsid.to_string()}"
# ===== EMR HTML μμ± ν¨μλ€ (κΈ°μ‘΄ λ‘μ§ μ¬μ¬μ©) =====
def create_emr_html(patient, scenario):
"""μ€μ λ³μ EMRκ³Ό μ μ¬ν HTML μμ±"""
vitals = scenario.vitals or {}
labs = scenario.labs or {}
orders = scenario.orders or []
nursing_notes = scenario.nursing_notes or []
# EMR ν€λ
emr_html = f"""
<div style="font-family: 'Malgun Gothic', sans-serif; background: #f5f5f5; padding: 15px; border-radius: 8px;">
<!-- νμ κΈ°λ³Έ μ 보 ν€λ -->
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;">
<div>
<div style="font-size: 11px; opacity: 0.9;">νμλͺ
/ λ±λ‘λ²νΈ</div>
<div style="font-size: 16px; font-weight: bold; margin-top: 5px;">{patient.name} / {patient.id}</div>
</div>
<div>
<div style="font-size: 11px; opacity: 0.9;">λμ΄/μ±λ³ / λ³μ€</div>
<div style="font-size: 16px; font-weight: bold; margin-top: 5px;">{patient.age}μΈ / {patient.gender} / {patient.room_number}</div>
</div>
<div>
<div style="font-size: 11px; opacity: 0.9;">μ
μμΌ / μ¬μμΌμ</div>
<div style="font-size: 16px; font-weight: bold; margin-top: 5px;">{patient.admission_date} / D+{scenario.hospital_day}</div>
</div>
</div>
<div style="margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.3);">
<div style="font-size: 11px; opacity: 0.9;">μ§λ¨λͺ
</div>
<div style="font-size: 14px; font-weight: bold; margin-top: 5px;">{patient.diagnosis}</div>
</div>
</div>
<!-- μλ λ₯΄κΈ° / κ²½κ³ -->
<div style="background: {'#fff3cd' if patient.allergies != 'μμ' else '#d4edda'}; border-left: 4px solid {'#ffc107' if patient.allergies != 'μμ' else '#28a745'}; padding: 12px; margin-bottom: 15px; border-radius: 4px;">
<strong>β οΈ μλ λ₯΄κΈ°:</strong> {patient.allergies} |
<strong>π κ³Όκ±°λ ₯:</strong> {patient.comorbidities} |
<strong>π¨ββοΈ λ΄λΉμ:</strong> {patient.attending_physician}
</div>
<!-- νλ ₯μ§ν ν¨λ -->
<div style="background: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1);">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #667eea;">
π νλ ₯μ§ν <span style="font-size: 12px; color: #666; font-weight: normal;">({vitals.get('time', 'N/A')})</span>
</div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;">
{create_vital_card('νμ', 'BP', vitals.get('BP', 'N/A'), '100-140/60-90', vitals.get('BP', ''))}
{create_vital_card('λ§₯λ°', 'HR', vitals.get('HR', 'N/A'), '60-100', vitals.get('HR', ''))}
{create_vital_card('νΈν‘', 'RR', vitals.get('RR', 'N/A'), '12-20', vitals.get('RR', ''))}
{create_vital_card('체μ¨', 'BT', vitals.get('BT', 'N/A'), '36.0-37.5', vitals.get('BT', ''))}
{create_vital_card('μ°μν¬νλ', 'SpO2', vitals.get('SpO2', 'N/A'), 'β₯95%', vitals.get('SpO2', ''))}
{create_vital_card('ν΅μ¦', 'Pain', vitals.get('Pain', 'N/A'), '0-3', vitals.get('Pain', ''))}
</div>
</div>
<!-- κ²μ¬ κ²°κ³Ό ν¨λ -->
<div style="background: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1);">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #667eea;">
π§ͺ κ²μ¬ κ²°κ³Ό <span style="font-size: 12px; color: #666; font-weight: normal;">({labs.get('time', 'N/A')})</span>
</div>
{create_lab_results_table(labs)}
</div>
<!-- μμ¬ μ²λ°© ν¨λ -->
<div style="background: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1);">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #667eea;">
π μμ¬ μ²λ°©
</div>
<div style="font-size: 13px; line-height: 1.8;">
{create_orders_list(orders)}
</div>
</div>
<!-- κ°νΈ κΈ°λ‘ ν¨λ -->
<div style="background: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1);">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #667eea;">
π κ°νΈ κΈ°λ‘
</div>
<div style="font-size: 13px;">
{create_nursing_notes_timeline(nursing_notes)}
</div>
</div>
{create_surgery_info_panel(scenario) if scenario.surgery_info else ''}
{create_discharge_education_panel(scenario) if scenario.discharge_education else ''}
</div>
"""
return emr_html
def create_vital_card(label, code, value, normal_range, raw_value):
"""νλ ₯μ§ν μΉ΄λ μμ±"""
is_abnormal = check_vital_abnormal(code, raw_value)
bg_color = "#ffe6e6" if is_abnormal else "#e8f5e9"
border_color = "#f44336" if is_abnormal else "#4caf50"
icon = "β οΈ" if is_abnormal else "β"
return f"""
<div style="background: {bg_color}; border-left: 4px solid {border_color}; padding: 12px; border-radius: 4px; text-align: center;">
<div style="font-size: 11px; color: #666; margin-bottom: 4px;">{label}</div>
<div style="font-size: 18px; font-weight: bold; color: #333; margin: 6px 0;">{icon} {value}</div>
<div style="font-size: 10px; color: #888;">μ μ: {normal_range}</div>
</div>
"""
def check_vital_abnormal(code, value_str):
"""νλ ₯μ§ν μ΄μ μ¬λΆ 체ν¬"""
if not value_str or value_str == "N/A":
return False
import re
numbers = re.findall(r"\d+\.?\d*", value_str)
if not numbers:
return False
try:
if code == "BP":
bp_values = re.findall(r"(\d+)/(\d+)", value_str)
if bp_values:
systolic = int(bp_values[0][0])
diastolic = int(bp_values[0][1])
return systolic < 90 or systolic > 140 or diastolic < 60 or diastolic > 90
elif code == "HR":
hr = int(numbers[0])
return hr < 60 or hr > 100
elif code == "RR":
rr = int(numbers[0])
return rr < 12 or rr > 20
elif code == "BT":
bt = float(numbers[0])
return bt < 36.0 or bt > 37.5
elif code == "SpO2":
spo2 = int(numbers[0])
return spo2 < 95
elif code == "Pain":
pain = int(numbers[0])
return pain > 3
except (ValueError, IndexError):
pass
return False
def create_lab_results_table(labs):
"""κ²μ¬ κ²°κ³Ό ν
μ΄λΈ μμ±"""
if not labs:
return "<div style='color: #999; text-align: center; padding: 20px;'>κ²μ¬ κ²°κ³Ό μμ</div>"
html = '<table style="width: 100%; border-collapse: collapse; font-size: 12px;">'
html += '<thead><tr style="background: #f8f9fa; font-weight: bold;">'
html += '<th style="padding: 10px; text-align: left; border-bottom: 2px solid #dee2e6;">κ²μ¬νλͺ©</th>'
html += '<th style="padding: 10px; text-align: center; border-bottom: 2px solid #dee2e6;">κ²°κ³Ό</th>'
html += '<th style="padding: 10px; text-align: center; border-bottom: 2px solid #dee2e6;">μ°Έκ³ λ²μ</th>'
html += '<th style="padding: 10px; text-align: center; border-bottom: 2px solid #dee2e6;">μν</th>'
html += "</tr></thead><tbody>"
# CBC κ²°κ³Ό
if "CBC" in labs:
cbc = labs["CBC"]
html += create_lab_row("WBC", cbc.get("WBC", "N/A"), "4.0-10.0 Γ10Β³/Β΅L", check_lab_abnormal("WBC", cbc.get("WBC", "")))
html += create_lab_row("Hemoglobin", cbc.get("Hb", "N/A"), "13.0-17.0 g/dL (M)", check_lab_abnormal("Hb", cbc.get("Hb", "")))
html += create_lab_row("Platelet", cbc.get("Plt", "N/A"), "150-400 Γ10Β³/Β΅L", False)
html += create_lab_row("Neutrophil", cbc.get("Neutrophil", "N/A"), "40-70%", False)
# CRP
if "CRP" in labs:
html += create_lab_row("CRP", labs["CRP"], "<0.5 mg/dL", check_lab_abnormal("CRP", labs["CRP"]))
# μ ν΄μ§
if "BMP" in labs:
bmp = labs["BMP"]
html += create_lab_row("Sodium", f"{bmp.get('Na', 'N/A')} mmol/L", "136-145 mmol/L", False)
html += create_lab_row("Potassium", f"{bmp.get('K', 'N/A')} mmol/L", "3.5-5.0 mmol/L", False)
html += create_lab_row("Creatinine", f"{bmp.get('Cr', 'N/A')} mg/dL", "0.7-1.3 mg/dL", False)
html += "</tbody></table>"
return html
def create_lab_row(name, value, ref_range, is_abnormal):
"""κ²μ¬ κ²°κ³Ό ν μμ±"""
status_icon = "π΄" if is_abnormal else "π’"
status_text = "λΉμ μ" if is_abnormal else "μ μ"
row_bg = "#fff3f3" if is_abnormal else "white"
return f"""
<tr style="background: {row_bg}; border-bottom: 1px solid #f0f0f0;">
<td style="padding: 10px;">{name}</td>
<td style="padding: 10px; text-align: center; font-weight: bold;">{value}</td>
<td style="padding: 10px; text-align: center; color: #666; font-size: 11px;">{ref_range}</td>
<td style="padding: 10px; text-align: center;">{status_icon} {status_text}</td>
</tr>
"""
def check_lab_abnormal(lab_name, value_str):
"""κ²μ¬ κ²°κ³Ό μ΄μ μ¬λΆ 체ν¬"""
if "β" in value_str or "β" in value_str or "μμΉ" in value_str or "κ°μ" in value_str:
return True
return False
def create_orders_list(orders):
"""μμ¬ μ²λ°© λͺ©λ‘ μμ±"""
if not orders:
return "<div style='color: #999;'>μ²λ°© μμ</div>"
html = '<div style="line-height: 1.9;">'
for i, order in enumerate(orders, 1):
if any(keyword in order for keyword in ["IV", "injection", "μ μ£Ό", "μ£Όμ¬"]):
icon = "π"
elif any(keyword in order for keyword in ["PO", "oral", "경ꡬ"]):
icon = "π"
elif "NPO" in order or "κΈμ" in order:
icon = "π«"
elif any(keyword in order for keyword in ["μμ ", "surgery", "operation"]):
icon = "πͺ"
else:
icon = "π"
html += f'<div style="padding: 6px 0; border-bottom: 1px dotted #e0e0e0;">{icon} <strong>{i}.</strong> {order}</div>'
html += "</div>"
return html
def create_nursing_notes_timeline(notes):
"""κ°νΈ κΈ°λ‘ νμλΌμΈ μμ±"""
if not notes:
return "<div style='color: #999;'>κΈ°λ‘ μμ</div>"
html = '<div style="position: relative; padding-left: 20px;">'
for note in notes:
time = note.get("time", "N/A")
content = note.get("note", "")
html += f"""
<div style="position: relative; margin-bottom: 15px; padding: 12px; background: #f8f9fa; border-left: 3px solid #667eea; border-radius: 4px;">
<div style="font-size: 11px; color: #667eea; font-weight: bold; margin-bottom: 5px;">π {time}</div>
<div style="font-size: 13px; color: #333; line-height: 1.6;">{content}</div>
</div>
"""
html += "</div>"
return html
def create_surgery_info_panel(scenario):
"""μμ μ 보 ν¨λ μμ±"""
if not scenario.surgery_info:
return ""
surgery = scenario.surgery_info
return f"""
<div style="background: #fff8e1; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); border-left: 4px solid #ffa726;">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px;">
π₯ μμ μ 보
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px;">
<div><strong>μ μ:</strong> {surgery.get('procedure', 'N/A')}</div>
<div><strong>μμ μκ°:</strong> {surgery.get('time', 'N/A')}</div>
<div><strong>μΆνλ:</strong> {surgery.get('EBL', 'N/A')}</div>
<div><strong>μμ‘λ:</strong> {surgery.get('fluids', 'N/A')}</div>
<div style="grid-column: 1 / -1;"><strong>μ견:</strong> {surgery.get('findings', 'N/A')}</div>
<div style="grid-column: 1 / -1;"><strong>ν©λ³μ¦:</strong> {surgery.get('complications', 'μμ')}</div>
</div>
</div>
"""
def create_discharge_education_panel(scenario):
"""ν΄μ κ΅μ‘ ν¨λ μμ±"""
if not scenario.discharge_education:
return ""
html = """
<div style="background: #e8f5e9; padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); border-left: 4px solid #4caf50;">
<div style="font-size: 14px; font-weight: bold; color: #333; margin-bottom: 12px;">
π ν΄μ κ΅μ‘
</div>
<div style="font-size: 13px; line-height: 1.8;">
"""
for edu in scenario.discharge_education:
html += f'<div style="padding: 6px 0; border-bottom: 1px dotted #c8e6c9;">β {edu}</div>'
html += "</div></div>"
return html
# ===== ν΅μ¬ λ‘μ§ ν¨μλ€ =====
def load_scenario_data(scenario_id: str):
"""μλλ¦¬μ€ μ ν μ EMR λ°μ΄ν° λ‘λ"""
if not scenario_id:
return None, None, ""
if not supabase_service:
return None, None, "Supabase μλΉμ€κ° μ΄κΈ°νλμ§ μμμ΅λλ€."
scenario = supabase_service.get_scenario(scenario_id)
patient = supabase_service.get_patient(scenario['patient_id']) if scenario else None
if not scenario or not patient:
return None, None, "μλ리μ€λ₯Ό μ°Ύμ μ μμ΅λλ€."
# Supabase λ°μ΄ν°λ₯Ό κ°μ²΄μ²λΌ μ¬μ©ν μ μλλ‘ λν
class Scenario:
def __init__(self, data):
self.id = data['id']
self.patient_id = data['patient_id']
self.title = data['title']
self.hospital_day = data.get('hospital_day')
self.vitals = data.get('vitals')
self.labs = data.get('labs')
self.orders = data.get('orders')
self.nursing_notes = data.get('nursing_notes')
self.surgery_info = data.get('surgery_info')
self.discharge_education = data.get('discharge_education')
class Patient:
def __init__(self, data):
self.id = data['id']
self.name = data['name']
self.age = data['age']
self.gender = data['gender']
self.diagnosis = data['diagnosis']
self.admission_date = data['admission_date']
self.allergies = data['allergies']
self.comorbidities = data.get('comorbidities', '')
self.attending_physician = data.get('attending_physician', '')
self.room_number = data.get('room_number', '')
scenario_obj = Scenario(scenario)
patient_obj = Patient(patient)
emr_display = create_emr_html(patient_obj, scenario_obj)
return scenario_obj, patient_obj, emr_display
def handle_chat_message(message, chat_history, session_id, student_id, scenario_id):
"""μ±ν
λ©μμ§ μ²λ¦¬"""
if not message or not message.strip():
return chat_history, ""
# μΈμ
ID νμΈ
print(f"π¬ μ±ν
λ©μμ§ μ²λ¦¬: session_id={session_id}, student_id={student_id}, scenario_id={scenario_id}")
# μλ리μ€κ° μ νλμ§ μμ κ²½μ°
if not scenario_id or scenario_id == "":
warning_msg = """
β οΈ **μλ리μ€λ₯Ό λ¨Όμ μ νν΄μ£ΌμΈμ!**
1. **EMR μ 보 μ‘°ν** νμΌλ‘ μ΄λνμΈμ
2. μλλ¦¬μ€ λλ‘λ€μ΄μμ μλ리μ€λ₯Ό μ ννμΈμ
3. EMR μ 보λ₯Ό νμΈν ν λ€μ μ΄ νμ΄μ§λ‘ λμμ μ±ν
μ μμνμΈμ
νμ¬ μ νλ μλ리μ€: μμ
"""
return chat_history + [[message, warning_msg]], ""
# Supabase μλΉμ€ μ°κ²°
supabase_service = SupabaseService()
# μλλ¦¬μ€ λ° νμ μ 보 μ‘°ν
scenario = supabase_service.get_scenario(scenario_id)
patient = supabase_service.get_patient(scenario['patient_id']) if scenario else None
if not scenario or not patient:
error_msg = """
β **μλλ¦¬μ€ μ 보λ₯Ό μ°Ύμ μ μμ΅λλ€.**
EMR μ 보 μ‘°ν νμμ μλ리μ€λ₯Ό λ€μ μ νν΄μ£ΌμΈμ.
"""
return chat_history + [[message, error_msg]], ""
# μ¬μ©μ λ©μμ§ μ μ₯ (session_idκ° μλ κ²½μ°μλ§)
if session_id:
try:
supabase_service.save_chat_message(session_id, student_id, scenario_id, "user", message)
print(f"β
μ¬μ©μ λ©μμ§ μ μ₯ μλ£: session_id={session_id}")
except Exception as e:
print(f"β οΈ μ¬μ©μ λ©μμ§ μ μ₯ μ€ν¨: {e}")
else:
print(f"β οΈ session_idκ° λΉμ΄μμ΄ λ©μμ§ μ μ₯ μ€ν¨")
# μλλ¦¬μ€ λ° νμ λ°μ΄ν° μ€λΉ
scenario_data = {
"title": scenario['title'],
"handoff_situation": scenario.get('handoff_situation'),
"hospital_day": scenario.get('hospital_day'),
"vitals": scenario.get('vitals'),
"labs": scenario.get('labs'),
"orders": scenario.get('orders'),
"nursing_notes": scenario.get('nursing_notes'),
}
patient_data = {
"name": patient['name'],
"age": patient['age'],
"gender": patient['gender'],
"diagnosis": patient['diagnosis'],
"admission_date": str(patient['admission_date']),
"allergies": patient['allergies'],
}
# μ΄μ μ±ν
κΈ°λ‘ ν¬λ§·ν
(Geminiμ©)
history_for_gemini = []
for user_msg, bot_msg in chat_history:
if user_msg:
history_for_gemini.append(("user", user_msg))
if bot_msg:
history_for_gemini.append(("assistant", bot_msg))
# Gemini AI νΌλλ°± μμ±
ai_response = evaluator.chat_feedback(message, history_for_gemini, scenario_data, patient_data)
# AI μλ΅ μ μ₯ (session_idκ° μλ κ²½μ°μλ§)
if session_id:
try:
supabase_service.save_chat_message(session_id, student_id, scenario_id, "assistant", ai_response)
print(f"β
AI μλ΅ μ μ₯ μλ£: session_id={session_id}")
except Exception as e:
print(f"β οΈ AI μλ΅ μ μ₯ μ€ν¨: {e}")
else:
print(f"β οΈ session_idκ° λΉμ΄μμ΄ AI μλ΅ μ μ₯ μ€ν¨")
# μ±ν
νμ€ν 리 μ
λ°μ΄νΈ
updated_history = chat_history + [[message, ai_response]]
return updated_history, ""
def finalize_chat_session(chat_history, session_id, student_id, scenario_id):
"""
μ±ν
μ’
λ£ μ μ 체 λνλ₯Ό λΆμνμ¬ νΌλλ°± μ 곡
- μ μ μμ΄ μ§μ νΌλλ°±λ§ μ 곡
- μ 체 λν λ΄μ©μ Geminiμκ² μ λ¬
"""
if not chat_history:
return chat_history + [[None, "λνκ° μμ΅λλ€. λ¨Όμ λνλ₯Ό μμν΄μ£ΌμΈμ."]], ""
# Supabase μλΉμ€ μ°κ²°
supabase_service = SupabaseService()
# μλλ¦¬μ€ λ° νμ μ 보 μ‘°ν
scenario = supabase_service.get_scenario(scenario_id)
patient = supabase_service.get_patient(scenario['patient_id']) if scenario else None
if not scenario or not patient:
return chat_history + [[None, "μλλ¦¬μ€ μ 보λ₯Ό μ°Ύμ μ μμ΅λλ€."]], ""
# μλλ¦¬μ€ λ° νμ λ°μ΄ν° μ€λΉ
scenario_data = {
"title": scenario['title'],
"handoff_situation": scenario.get('handoff_situation'),
"hospital_day": scenario.get('hospital_day'),
"vitals": scenario.get('vitals'),
"labs": scenario.get('labs'),
"orders": scenario.get('orders'),
"nursing_notes": scenario.get('nursing_notes'),
}
patient_data = {
"name": patient['name'],
"age": patient['age'],
"gender": patient['gender'],
"diagnosis": patient['diagnosis'],
"admission_date": str(patient['admission_date']),
"allergies": patient['allergies'],
}
# μ 체 λνλ₯Ό Geminiμκ² μ λ¬νμ¬ νκ°
evaluation = evaluator.evaluate_conversation(
chat_history=chat_history,
scenario_data=scenario_data,
patient_data=patient_data
)
# λ°μ΄ν°λ² μ΄μ€μ μ μ₯ (μ μ μμ΄)
try:
record = supabase_service.create_handoff_record(
student_id=student_id,
scenario_id=scenario_id,
sbar_data={}, # λν κΈ°λ° νκ°μ΄λ―λ‘ SBAR λ°μ΄ν°λ λΉμ
evaluation=evaluation,
session_id=session_id
)
print(f"β
μΈμμΈκ³ κΈ°λ‘ μ μ₯ μλ£ (ID: {record.get('id')})")
# μΈμ
μνλ₯Ό 'completed'λ‘ λ³κ²½
supabase_service.update_session_status(session_id, 'completed')
except Exception as e:
print(f"β οΈ λ°μ΄ν°λ² μ΄μ€ μ μ₯ μ€λ₯: {e}")
# νΌλλ°± λ©μμ§ ν¬λ§·ν
(μ μ μμ΄)
strengths = evaluation.get('strengths', [])
improvements = evaluation.get('improvements', [])
detailed_feedback = evaluation.get('detailed_feedback', '')
missing_info = evaluation.get('missing_critical_info', [])
safety_concerns = evaluation.get('safety_concerns', [])
result_message = f"""
π **νμ΅ μ’
ν© νΌλλ°±**
{'='*50}
### πͺ μν μ
{chr(10).join([f"- {s}" for s in strengths]) if strengths else "- μμ"}
### π κ°μ ν μ
{chr(10).join([f"- {i}" for i in improvements]) if improvements else "- μμ"}
### π μ’
ν© μ견
{detailed_feedback if detailed_feedback else "μ’
ν© νΌλλ°±μ΄ μμ΅λλ€."}
"""
if missing_info:
result_message += f"""
### β οΈ λλ½λ μ€μ μ 보
{chr(10).join([f"- {m}" for m in missing_info])}
"""
if safety_concerns:
result_message += f"""
### π₯ νμ μμ κ΄λ ¨ μ£Όμμ¬ν
{chr(10).join([f"- {s}" for s in safety_concerns])}
"""
result_message += f"""
{'='*50}
μκ³ νμ
¨μ΅λλ€! λ€λ₯Έ μλ리μ€λ‘ μ°μ΅μ κ³μνμλ €λ©΄
EMR νμ΄μ§λ‘ λμκ° μλ‘μ΄ μλ리μ€λ₯Ό μ ννμΈμ.
"""
return chat_history + [[None, result_message]], ""
def get_student_history(student_id: str):
"""νμ μΈμμΈκ³ μ΄λ ₯ μ‘°ν (κ΄λ¦¬μμ©)"""
if not student_id:
return "νμ IDλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
supabase_service = SupabaseService()
stats = supabase_service.get_student_statistics(student_id)
records = supabase_service.get_records_by_student(student_id)
if stats["total_submissions"] == 0:
return f"νμ ID '{student_id}'μ μ μΆ κΈ°λ‘μ΄ μμ΅λλ€."
history = f"""
# νμ μΈμμΈκ³ μ΄λ ₯
**νμ ID**: {student_id}
## ν΅κ³
- **μ΄ μ μΆ νμ**: {stats['total_submissions']}ν
- **νκ· μ μ**: {stats['average_score']:.1f}μ
- **μ΅κ³ μ μ**: {stats['highest_score']:.1f}μ
- **μ΅μ μ μ**: {stats['lowest_score']:.1f}μ
## μ΅κ·Ό μ μΆ κΈ°λ‘
"""
for i, record in enumerate(records[:10], 1):
submitted_time = record.get('submitted_at', 'N/A')
if submitted_time and isinstance(submitted_time, str):
# ISO νμμμ μκ° μΆμΆ
try:
from datetime import datetime
dt = datetime.fromisoformat(submitted_time.replace('Z', '+00:00'))
submitted_time = dt.strftime("%Y-%m-%d %H:%M")
except:
pass
history += f"""
### {i}. {record.get('scenario_id', 'N/A')}
- **μ μΆ μκ°**: {submitted_time}
- **μ μ**: {record.get('total_score', 0):.1f}μ
- **κ°μ **: {', '.join(record.get('strengths', [])[:2]) if record.get('strengths') else 'N/A'}
---
"""
return history
# ===== Gradio UI κ΅¬μ± =====
with gr.Blocks(title="κ°νΈ μΈμμΈκ³ κ΅μ‘ νλ«νΌ", theme=gr.themes.Soft()) as app:
# μ μ μν λ³μ
session_id_state = gr.State(value="")
student_id_state = gr.State(value="")
scenario_id_state = gr.State(value="S001_D0_ER_WARD") # κΈ°λ³Έκ° μ€μ
user_role_state = gr.State(value="student")
gr.Markdown("""
# π₯ κ°νΈ μΈμμΈκ³ κ΅μ‘ νλ«νΌ (μ±ν
κΈ°λ°)
SBAR νμμΌλ‘ νμ μΈμμΈκ³λ₯Ό μ°μ΅νκ³ AIμ λννλ©° νΌλλ°±μ λ°μ보μΈμ.
""")
# μ΄κΈ° μ€μ μΉμ
with gr.Row():
with gr.Column():
student_id_input = gr.Textbox(
label="π€ νμ ID (μλ μμ±λ¨)",
value=initial_student_id,
interactive=False,
info="μλμΌλ‘ μμ±λ κ³ μ IDμ
λλ€. 'μ ID μμ±' λ²νΌμΌλ‘ μ IDλ₯Ό λ°μ μ μμ΅λλ€."
)
with gr.Row():
generate_id_btn = gr.Button("π μ ID μμ±", variant="secondary")
# ν ꡬμ±
with gr.Tabs() as tabs:
# νμ΄μ§ 1: EMR μ 보 μ‘°ν
with gr.Tab("π EMR μ 보 μ‘°ν", id=0) as tab_emr:
gr.Markdown("## νμ μ μμλ¬΄κΈ°λ‘ (EMR)")
# μ¬μ© λ°©λ²κ³Ό μλλ¦¬μ€ μ νμ ν νμ 2μ΄λ‘ λ°°μΉ
with gr.Row():
with gr.Column(scale=2):
gr.Markdown("""
**π μ¬μ© λ°©λ²:**
1. μλ리μ€λ₯Ό μ ννμΈμ
2. EMR μ 보λ₯Ό μΆ©λΆν νμΈνμΈμ
3. μ€λΉκ° λλ©΄ "λ΅μ μμ±νλ¬ κ°κΈ°" λ²νΌμ ν΄λ¦νμΈμ
""")
with gr.Column(scale=3):
scenario_dropdown = gr.Dropdown(
choices=[
("Day 0 - μκΈμ€βλ³λ μΈκ³ (μμ μ )", "S001_D0_ER_WARD"),
("Day 0 - λ³λβμμ μ€ μΈκ³", "S001_D0_WARD_OR"),
("Day 0 - ν볡μ€βλ³λ μ λ (μμ ν)", "S001_D0_RECOVERY"),
("Day 1 - μμΉ¨ μΈκ³ (POD1)", "S001_D1_MORNING"),
("Day 2 - ν΄μ μ μΈκ³ (POD2)", "S001_D2_DISCHARGE"),
],
label="π μλλ¦¬μ€ μ ν",
value="S001_D0_ER_WARD",
info="μλ리μ€λ₯Ό μ ννλ©΄ EMR μ λ³΄κ° νμλ©λλ€"
)
emr_display = gr.HTML(
value="<div style='text-align: center; padding: 40px; color: #999;'>β¬οΈ μμμ μλ리μ€λ₯Ό μ ννμΈμ.</div>"
)
go_to_chat_btn = gr.Button("π¬ λ΅μ μμ±νλ¬ κ°κΈ°", variant="primary", size="lg")
gr.Markdown("""
> π‘ **Tip**: EMR νμ΄μ§μμ μΈμ λ μ§ "λ΅μ μμ±" νμΌλ‘ μ΄λν μ μμ΅λλ€.
""")
# νμ΄μ§ 2: μ±ν
κΈ°λ° λ΅μ μμ±
with gr.Tab("π¬ λ΅μ μμ± (μ±ν
)", id=1) as tab_chat:
gr.Markdown("## AI κ΅μμ ν¨κ»νλ μΈμμΈκ³ μ°μ΅")
gr.Markdown("""
**π μμνκΈ°:**
1. κΈ°λ³Έ μλ리μ€λ **"Day 0 - μκΈμ€βλ³λ μΈκ³"**μ
λλ€ (μλ¨μμ νμΈ κ°λ₯)
2. EMR μ 보λ₯Ό νμΈνλ €λ©΄ **"EMR μ 보 μ‘°ν"** νμ ν΄λ¦νμΈμ
3. μ€λΉκ° λλ©΄ AI κ΅μμ μμ λ‘κ² λννλ©° μΈμμΈκ³ λ΄μ©μ μμ±νμΈμ
""")
with gr.Row():
current_scenario_display = gr.Markdown("**νμ¬ μλ리μ€**: λ‘λ© μ€...")
back_to_emr_btn = gr.Button("π EMR λ€μ 보기", size="sm", variant="secondary")
chatbot = gr.Chatbot(
label="AI κ΅μμ λν",
height=500,
show_label=True
)
with gr.Row():
msg_input = gr.Textbox(
label="λ©μμ§ μ
λ ₯",
placeholder="μμ λ‘κ² λννλ©° μΈμμΈκ³ λ΄μ©μ μμ±νκ±°λ, AI κ΅μμκ² μ§λ¬ΈνμΈμ...",
lines=3,
scale=4
)
with gr.Row():
send_btn = gr.Button("μ μ‘", variant="primary")
finalize_btn = gr.Button("μ±ν
μ’
λ£ λ° νκ°λ°κΈ°", variant="stop")
clear_btn = gr.Button("λν μ΄κΈ°ν")
gr.Markdown("""
**μ¬μ© λ°©λ²:**
1. μμ λ‘κ² λννλ©° μΈμμΈκ³ λ΄μ©μ μμ±νμΈμ
2. AI κ΅μκ° μ¦μ νΌλλ°±μ μ 곡ν©λλ€
3. νΌλλ°±μ λ°νμΌλ‘ μμ νκ³ λ λμ λ΄μ©μ μμ±ν μ μμ΅λλ€
4. μ€λΉκ° λλ©΄ **μ±ν
μ’
λ£ λ° νκ°λ°κΈ°** λ²νΌμ λλ¬ μ’
ν© νΌλλ°±μ λ°μΌμΈμ
**π‘ ν:**
- μμ°μ€λ¬μ΄ λνλ‘ λ°°μ°λ κ²μ΄ ν΅μ¬μ
λλ€
- SBAR νμμ κ°μ νμ§ μμ΅λλ€. λνλ₯Ό ν΅ν΄ μλμΌλ‘ νκ°λ©λλ€
- μΈμ λ μ§ AI κ΅μμκ² μ§λ¬ΈνμΈμ
""")
# νμ΄μ§ 3: κ΄λ¦¬μ μ΄λ ₯ μ‘°ν
with gr.Tab("π νμ μ΄λ ₯ μ‘°ν (κ΄λ¦¬μ)", id=2, visible=False) as tab_admin:
gr.Markdown("## νμ μΈμμΈκ³ μ΄λ ₯ μ‘°ν")
with gr.Row():
history_student_id = gr.Textbox(label="νμ ID", placeholder="student001")
history_btn = gr.Button("μ΄λ ₯ μ‘°ν")
history_display = gr.Markdown(value="")
# ===== μ΄λ²€νΈ νΈλ€λ¬ =====
def generate_student_id():
"""TSID κΈ°λ° νμ ID μμ±"""
from tsidpy import TSID
tsid = TSID.create()
student_id = f"student_{tsid.to_string()}"
return student_id
def update_student_id():
"""μ νμ ID μμ±"""
new_id = generate_student_id()
return new_id
# μ ID μμ± λ²νΌ (student_id_stateλ ν¨κ» μ
λ°μ΄νΈ)
def update_student_id_with_state():
"""μ νμ ID μμ± λ° μν μ
λ°μ΄νΈ"""
new_id = generate_student_id()
is_admin = (new_id == "admin")
role = "admin" if is_admin else "student"
tab_visibility = gr.update(visible=is_admin)
return new_id, new_id, role, tab_visibility
generate_id_btn.click(
fn=update_student_id_with_state,
outputs=[student_id_input, student_id_state, user_role_state, tab_admin]
)
def select_scenario_and_create_session(scenario_id, student_id):
"""μλλ¦¬μ€ μ ν λ° μΈμ
μμ±"""
scenario, patient, emr_html = load_scenario_data(scenario_id)
if scenario:
# μ μ±ν
μΈμ
μμ±
try:
supabase_service = SupabaseService()
new_session_id = supabase_service.create_chat_session(student_id, scenario_id)
print(f"π μλλ¦¬μ€ μ ν μ μΈμ
μμ±: session_id={new_session_id}")
scenario_info = f"**νμ¬ μλ리μ€**: {scenario.title}"
return emr_html, new_session_id, scenario_id, scenario_info
except Exception as e:
print(f"β οΈ μΈμ
μμ± μ€ν¨: {e}")
import traceback
traceback.print_exc()
return emr_html, "", scenario_id, "**νμ¬ μλ리μ€**: μ νλμ§ μμ"
return emr_html, "", scenario_id, "**νμ¬ μλ리μ€**: μ νλμ§ μμ"
scenario_dropdown.change(
fn=select_scenario_and_create_session,
inputs=[scenario_dropdown, student_id_state],
outputs=[emr_display, session_id_state, scenario_id_state, current_scenario_display]
)
# μ±ν
λ©μμ§ μ μ‘ (κ°μ λ λ²μ )
send_btn.click(
fn=handle_chat_message,
inputs=[msg_input, chatbot, session_id_state, student_id_state, scenario_id_state],
outputs=[chatbot, msg_input],
show_progress="minimal"
)
msg_input.submit(
fn=handle_chat_message,
inputs=[msg_input, chatbot, session_id_state, student_id_state, scenario_id_state],
outputs=[chatbot, msg_input],
show_progress="minimal"
)
# μ±ν
μ’
λ£ λ° νκ°
finalize_btn.click(
fn=finalize_chat_session,
inputs=[chatbot, session_id_state, student_id_state, scenario_id_state],
outputs=[chatbot, msg_input]
)
# λν μ΄κΈ°ν
def clear_chat(student_id, scenario_id):
"""λν μ΄κΈ°ν λ° μ μΈμ
μμ±"""
try:
supabase_service = SupabaseService()
new_session_id = supabase_service.create_chat_session(student_id, scenario_id)
print(f"π λν μ΄κΈ°ν - μ μΈμ
μμ±: {new_session_id}")
return [], new_session_id
except Exception as e:
print(f"β οΈ λν μ΄κΈ°ν μ€ μΈμ
μμ± μ€ν¨: {e}")
return [], ""
clear_btn.click(
fn=clear_chat,
inputs=[student_id_state, scenario_id_state],
outputs=[chatbot, session_id_state]
)
# μ΄λ ₯ μ‘°ν
history_btn.click(
fn=get_student_history,
inputs=[history_student_id],
outputs=[history_display]
)
# λ²νΌ νΈλ€λ¬ μΆκ°
def navigate_to_chat(session_id, scenario_id):
"""μ±ν
νμ΄μ§λ‘ μ΄λ"""
return gr.update(selected=1) # μ±ν
νμΌλ‘ μ ν
def navigate_to_emr():
"""EMR νμ΄μ§λ‘ μ΄λ"""
return gr.update(selected=0) # EMR νμΌλ‘ μ ν
# λ΅μ μμ±νκΈ° λ²νΌ ν΄λ¦ μ μ±ν
νμ΄μ§λ‘ μ΄λ
go_to_chat_btn.click(
fn=navigate_to_chat,
inputs=[session_id_state, scenario_id_state],
outputs=[tabs]
)
# EMR λ€μ 보기 λ²νΌ ν΄λ¦ μ EMR νμ΄μ§λ‘ μ΄λ
back_to_emr_btn.click(
fn=navigate_to_emr,
outputs=[tabs]
)
# μ΄κΈ° λ‘λ ν¨μ
def initialize_app():
"""μ± μ΄κΈ° λ‘λ μ μ€ν"""
default_scenario = "S001_D0_ER_WARD"
# student_id_stateλ₯Ό μ΄κΈ° IDλ‘ μ€μ (λͺ¨λ λ 벨 λ³μ μ¬μ©)
current_student_id = initial_student_id
initial_session_id = ""
# Supabase μλΉμ€κ° μμΌλ©΄ μλλ¦¬μ€ λ°μ΄ν° λ‘λ
if supabase_service:
scenario, patient, emr_html = load_scenario_data(default_scenario)
if scenario:
# κΈ°λ³Έ μλλ¦¬μ€ μ 보 νμ
scenario_info = f"**νμ¬ μλ리μ€**: {scenario.title}"
# μ΄κΈ° μΈμ
μμ±
try:
initial_session_id = supabase_service.create_chat_session(current_student_id, default_scenario)
print(f"β
μ΄κΈ° μΈμ
μμ± μλ£: {initial_session_id}")
except Exception as e:
print(f"β οΈ μ΄κΈ° μΈμ
μμ± μ€ν¨: {e}")
import traceback
traceback.print_exc()
return emr_html, default_scenario, scenario_info, current_student_id, "student", initial_session_id
else:
return emr_html, default_scenario, "**νμ¬ μλ리μ€**: μ νλμ§ μμ", current_student_id, "student", ""
else:
return "", default_scenario, "**νμ¬ μλ리μ€**: μ νλμ§ μμ", current_student_id, "student", ""
# μ΄κΈ° λ‘λ
app.load(
fn=initialize_app,
outputs=[emr_display, scenario_id_state, current_scenario_display, student_id_state, user_role_state, session_id_state]
)
if __name__ == "__main__":
# Hugging Face Space νκ²½ νμΈ
is_hf_space = bool(os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID"))
if is_hf_space:
# Hugging Face Spaceμμ μ€ν
print("π Hugging Face Spaceμμ μ€ν μ€...")
# Queue μ€μ μΌλ‘ API νΈμΆ μμ μ± ν₯μ
app.queue()
# Spaceλ μλμΌλ‘ νΈμ€ν
νλ―λ‘ μ΅μ μ€μ
app.launch(server_name="0.0.0.0", server_port=7860)
else:
# λ‘컬/μ§μ μ€ν
print("π λ‘컬 νκ²½μμ μ€ν μ€...")
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|