Spaces:
Sleeping
Sleeping
Implement modal popup for registration - fixes visibility bug completely
Browse files
app.py
CHANGED
|
@@ -709,53 +709,10 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 709 |
current_question_idx = gr.State(0)
|
| 710 |
current_topic = gr.State("")
|
| 711 |
current_image_state = gr.State(None)
|
|
|
|
| 712 |
|
| 713 |
-
#
|
| 714 |
-
with gr.Column(
|
| 715 |
-
gr.Markdown(
|
| 716 |
-
"""
|
| 717 |
-
# 🩺 Welcome to AnatomyBot
|
| 718 |
-
### Your Personal MBBS Anatomy Tutor
|
| 719 |
-
|
| 720 |
-
Master anatomy through AI-powered learning and interactive VIVA practice!
|
| 721 |
-
"""
|
| 722 |
-
)
|
| 723 |
-
gr.Markdown("---")
|
| 724 |
-
gr.Markdown("## 👨⚕️ Let's Get Started!")
|
| 725 |
-
gr.Markdown("Please enter your information to begin your personalized learning journey.")
|
| 726 |
-
|
| 727 |
-
with gr.Row():
|
| 728 |
-
with gr.Column(scale=1):
|
| 729 |
-
pass # Empty column for centering
|
| 730 |
-
with gr.Column(scale=2):
|
| 731 |
-
welcome_name_input = gr.Textbox(
|
| 732 |
-
label="Your Name",
|
| 733 |
-
placeholder="Enter your name (e.g., Ahmed, Sarah, etc.)",
|
| 734 |
-
lines=1,
|
| 735 |
-
scale=1
|
| 736 |
-
)
|
| 737 |
-
welcome_school_input = gr.Textbox(
|
| 738 |
-
label="Medical School",
|
| 739 |
-
placeholder="Enter your medical school (e.g., King Saud University)",
|
| 740 |
-
lines=1,
|
| 741 |
-
scale=1
|
| 742 |
-
)
|
| 743 |
-
welcome_year_input = gr.Dropdown(
|
| 744 |
-
label="Year/Level",
|
| 745 |
-
choices=["MBBS 1st Year", "MBBS 2nd Year", "MBBS 3rd Year", "MBBS Final Year", "Intern"],
|
| 746 |
-
value=None,
|
| 747 |
-
interactive=True
|
| 748 |
-
)
|
| 749 |
-
welcome_submit_btn = gr.Button(
|
| 750 |
-
"🚀 Start Learning",
|
| 751 |
-
variant="primary",
|
| 752 |
-
size="lg"
|
| 753 |
-
)
|
| 754 |
-
with gr.Column(scale=1):
|
| 755 |
-
pass # Empty column for centering
|
| 756 |
-
|
| 757 |
-
# Main Application (hidden initially)
|
| 758 |
-
with gr.Column(visible=False, elem_id="main_app_container") as main_app:
|
| 759 |
gr.Markdown(
|
| 760 |
"""
|
| 761 |
# 🩺 AnatomyBot - Your MBBS Anatomy Tutor
|
|
@@ -970,50 +927,71 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 970 |
interactive=False,
|
| 971 |
wrap=True
|
| 972 |
)
|
| 973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 974 |
|
| 975 |
|
| 976 |
-
#
|
| 977 |
-
|
| 978 |
-
|
|
|
|
|
|
|
| 979 |
if not name or not name.strip():
|
| 980 |
-
return gr.update(), gr.update(),
|
| 981 |
|
| 982 |
if not medical_school or not medical_school.strip():
|
| 983 |
-
return gr.update(), gr.update(),
|
| 984 |
|
| 985 |
if not year:
|
| 986 |
-
return gr.update(), gr.update(),
|
| 987 |
|
| 988 |
# Save to database
|
| 989 |
save_student(name.strip(), medical_school.strip(), year)
|
| 990 |
|
| 991 |
greeting = f"**Welcome, Doctor {name}!** 👋 from {medical_school} ({year})"
|
| 992 |
return (
|
| 993 |
-
gr.update(visible=False), # Hide
|
| 994 |
-
gr.update(visible=True), # Show main app
|
| 995 |
-
gr.update(visible=True), # Show tabs
|
| 996 |
greeting, # Display greeting
|
| 997 |
name # Store name in state
|
| 998 |
)
|
| 999 |
|
| 1000 |
-
|
| 1001 |
-
fn=
|
| 1002 |
-
inputs=[
|
| 1003 |
-
outputs=[
|
| 1004 |
-
)
|
| 1005 |
-
|
| 1006 |
-
# Also allow Enter key to submit
|
| 1007 |
-
welcome_name_input.submit(
|
| 1008 |
-
fn=handle_welcome_submit,
|
| 1009 |
-
inputs=[welcome_name_input, welcome_school_input, welcome_year_input],
|
| 1010 |
-
outputs=[welcome_screen, main_app, tabs, student_name_display, student_name_state]
|
| 1011 |
-
)
|
| 1012 |
-
|
| 1013 |
-
welcome_school_input.submit(
|
| 1014 |
-
fn=handle_welcome_submit,
|
| 1015 |
-
inputs=[welcome_name_input, welcome_school_input, welcome_year_input],
|
| 1016 |
-
outputs=[welcome_screen, main_app, tabs, student_name_display, student_name_state]
|
| 1017 |
)
|
| 1018 |
|
| 1019 |
# Event handlers for Learning Mode
|
|
|
|
| 709 |
current_question_idx = gr.State(0)
|
| 710 |
current_topic = gr.State("")
|
| 711 |
current_image_state = gr.State(None)
|
| 712 |
+
is_registered = gr.State(False) # Track if user has registered
|
| 713 |
|
| 714 |
+
# Main Application (always visible now)
|
| 715 |
+
with gr.Column() as main_app:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
gr.Markdown(
|
| 717 |
"""
|
| 718 |
# 🩺 AnatomyBot - Your MBBS Anatomy Tutor
|
|
|
|
| 927 |
interactive=False,
|
| 928 |
wrap=True
|
| 929 |
)
|
| 930 |
+
|
| 931 |
+
# Registration Modal Popup (shown on first load)
|
| 932 |
+
with gr.Column(visible=True, elem_id="registration_modal") as registration_modal:
|
| 933 |
+
with gr.Row():
|
| 934 |
+
with gr.Column(scale=1):
|
| 935 |
+
pass # Spacer
|
| 936 |
+
with gr.Column(scale=2):
|
| 937 |
+
gr.Markdown(
|
| 938 |
+
"""
|
| 939 |
+
# 👨⚕️ Welcome to AnatomyBot!
|
| 940 |
+
### Please enter your information to get started
|
| 941 |
+
"""
|
| 942 |
+
)
|
| 943 |
+
modal_name_input = gr.Textbox(
|
| 944 |
+
label="Your Name",
|
| 945 |
+
placeholder="Enter your name",
|
| 946 |
+
lines=1
|
| 947 |
+
)
|
| 948 |
+
modal_school_input = gr.Textbox(
|
| 949 |
+
label="Medical School",
|
| 950 |
+
placeholder="Enter your medical school",
|
| 951 |
+
lines=1
|
| 952 |
+
)
|
| 953 |
+
modal_year_input = gr.Dropdown(
|
| 954 |
+
label="Year/Level",
|
| 955 |
+
choices=["MBBS 1st Year", "MBBS 2nd Year", "MBBS 3rd Year", "MBBS Final Year", "Intern"],
|
| 956 |
+
value=None
|
| 957 |
+
)
|
| 958 |
+
modal_submit_btn = gr.Button(
|
| 959 |
+
"✅ Start Learning",
|
| 960 |
+
variant="primary",
|
| 961 |
+
size="lg"
|
| 962 |
+
)
|
| 963 |
+
with gr.Column(scale=1):
|
| 964 |
+
pass # Spacer
|
| 965 |
|
| 966 |
|
| 967 |
+
# Event Handlers
|
| 968 |
+
|
| 969 |
+
# Welcome Screen Handler (now for modal)
|
| 970 |
+
def handle_modal_submit(name, medical_school, year):
|
| 971 |
+
"""Handle registration modal submission."""
|
| 972 |
if not name or not name.strip():
|
| 973 |
+
return gr.update(), gr.update(), "" # Don't proceed if name is empty
|
| 974 |
|
| 975 |
if not medical_school or not medical_school.strip():
|
| 976 |
+
return gr.update(), gr.update(), "" # Don't proceed if medical school is empty
|
| 977 |
|
| 978 |
if not year:
|
| 979 |
+
return gr.update(), gr.update(), "" # Don't proceed if year is not selected
|
| 980 |
|
| 981 |
# Save to database
|
| 982 |
save_student(name.strip(), medical_school.strip(), year)
|
| 983 |
|
| 984 |
greeting = f"**Welcome, Doctor {name}!** 👋 from {medical_school} ({year})"
|
| 985 |
return (
|
| 986 |
+
gr.update(visible=False), # Hide modal
|
|
|
|
|
|
|
| 987 |
greeting, # Display greeting
|
| 988 |
name # Store name in state
|
| 989 |
)
|
| 990 |
|
| 991 |
+
modal_submit_btn.click(
|
| 992 |
+
fn=handle_modal_submit,
|
| 993 |
+
inputs=[modal_name_input, modal_school_input, modal_year_input],
|
| 994 |
+
outputs=[registration_modal, student_name_display, student_name_state]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
)
|
| 996 |
|
| 997 |
# Event handlers for Learning Mode
|