Spaces:
Sleeping
Sleeping
Add VIVA button to Book Mode and update AI persona
Browse files
app.py
CHANGED
|
@@ -186,30 +186,30 @@ def generate_anatomy_info(query: str) -> str:
|
|
| 186 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 187 |
}
|
| 188 |
|
| 189 |
-
prompt = f"""You are an anatomy
|
| 190 |
|
| 191 |
Format your response with clear sections using these exact emoji icons:
|
| 192 |
|
| 193 |
π **Location & Definition:**
|
| 194 |
-
[
|
| 195 |
|
| 196 |
π **Key Anatomical Features:**
|
| 197 |
-
- [
|
| 198 |
-
- [
|
| 199 |
-
- [
|
| 200 |
|
| 201 |
π₯ **Clinical Significance:**
|
| 202 |
-
- [Clinical
|
| 203 |
-
- [Clinical
|
| 204 |
|
| 205 |
π **Related Structures:**
|
| 206 |
- [Related structure 1]
|
| 207 |
- [Related structure 2]
|
| 208 |
|
| 209 |
π‘ **Quick Memory Tip:**
|
| 210 |
-
[A mnemonic or
|
| 211 |
|
| 212 |
-
Keep it
|
| 213 |
|
| 214 |
payload = {
|
| 215 |
"model": HYPERBOLIC_MODEL,
|
|
@@ -249,12 +249,12 @@ def generate_viva_questions(topic: str) -> list:
|
|
| 249 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 250 |
}
|
| 251 |
|
| 252 |
-
prompt = f"""You are
|
| 253 |
|
| 254 |
-
Generate exactly 5 viva questions that
|
| 255 |
-
1. The question
|
| 256 |
-
2. A helpful hint (
|
| 257 |
-
3. The expected key points in the answer
|
| 258 |
|
| 259 |
Format your response EXACTLY as follows:
|
| 260 |
Q1: [question]
|
|
@@ -267,7 +267,7 @@ ANSWER: [expected answer key points]
|
|
| 267 |
|
| 268 |
... and so on for all 5 questions.
|
| 269 |
|
| 270 |
-
Make questions progressively harder. Start with
|
| 271 |
|
| 272 |
payload = {
|
| 273 |
"model": HYPERBOLIC_MODEL,
|
|
@@ -322,7 +322,7 @@ def evaluate_viva_answer(question: str, student_answer: str, expected_answer: st
|
|
| 322 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 323 |
}
|
| 324 |
|
| 325 |
-
prompt = f"""You are an
|
| 326 |
|
| 327 |
Question: {question}
|
| 328 |
Expected key points: {expected_answer}
|
|
@@ -330,19 +330,19 @@ Student's answer: {student_answer}
|
|
| 330 |
|
| 331 |
Provide feedback in this EXACT format:
|
| 332 |
|
| 333 |
-
[First, write one
|
| 334 |
|
| 335 |
β
**What was correct:**
|
| 336 |
-
[List
|
| 337 |
|
| 338 |
β **What was missing:**
|
| 339 |
-
[List
|
| 340 |
|
| 341 |
-
**Score:** [Choose:
|
| 342 |
|
| 343 |
-
[End with
|
| 344 |
|
| 345 |
-
Be
|
| 346 |
|
| 347 |
payload = {
|
| 348 |
"model": HYPERBOLIC_MODEL,
|
|
@@ -359,18 +359,18 @@ Be warm, supportive, and constructive. Celebrate correct answers enthusiasticall
|
|
| 359 |
|
| 360 |
# Determine emoji and encouragement based on feedback content
|
| 361 |
feedback_upper = feedback.upper()
|
| 362 |
-
if "
|
| 363 |
emoji = "π"
|
| 364 |
-
encouragement = "\n\nπ **Outstanding!** You're mastering this topic!
|
| 365 |
-
elif "
|
| 366 |
emoji = "β
"
|
| 367 |
-
encouragement = "\n\nπ **
|
| 368 |
-
elif "
|
| 369 |
-
emoji = "
|
| 370 |
-
encouragement = "\n\nπͺ **
|
| 371 |
else:
|
| 372 |
emoji = "π"
|
| 373 |
-
encouragement = "\n\nπ± **Keep
|
| 374 |
|
| 375 |
# Format the complete feedback
|
| 376 |
formatted_feedback = f"{emoji} **VIVA Feedback:**\n\n{feedback}{encouragement}\n\n---\n\nπ **Reference Answer:**\n{expected_answer}"
|
|
@@ -493,34 +493,34 @@ def analyze_book_image(image, page_info, page_text=""):
|
|
| 493 |
# Include extracted text in the prompt context
|
| 494 |
context_text = f"Page Content:\n{page_text}" if page_text else "No text extracted from this page."
|
| 495 |
|
| 496 |
-
prompt = f"""You are an anatomy professor helping MBBS students
|
| 497 |
|
| 498 |
A student is looking at {page_info} of their anatomy textbook.
|
| 499 |
{context_text}
|
| 500 |
|
| 501 |
-
Based on the text content above
|
| 502 |
|
| 503 |
## π Page Overview
|
| 504 |
-
[Summarize the key anatomical topic
|
| 505 |
|
| 506 |
## π Key Concepts Explained
|
| 507 |
-
[Explain the
|
| 508 |
|
| 509 |
## π₯ Clinical Relevance
|
| 510 |
-
[
|
| 511 |
|
| 512 |
## π‘ Study Tips
|
| 513 |
-
[
|
| 514 |
|
| 515 |
-
## β Self-Test Questions (
|
| 516 |
1. [Question based on the page text]
|
| 517 |
2. [Question based on the page text]
|
| 518 |
...
|
| 519 |
15. [Question based on the page text]
|
| 520 |
|
| 521 |
-
(Provide at least 15 distinct questions covering
|
| 522 |
|
| 523 |
-
Be
|
| 524 |
|
| 525 |
payload = {
|
| 526 |
"model": HYPERBOLIC_MODEL,
|
|
@@ -693,6 +693,32 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 693 |
with gr.Column(scale=1):
|
| 694 |
image_output = gr.Image(label="πΌοΈ Anatomy Diagram", type="pil")
|
| 695 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
# BOOK LEARNING MODE TAB
|
| 697 |
with gr.Tab("π Book Learning Mode") as book_tab:
|
| 698 |
# Upload PDF
|
|
@@ -713,6 +739,9 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 713 |
# Analysis output
|
| 714 |
analysis_output = gr.Markdown(label="Page Analysis")
|
| 715 |
|
|
|
|
|
|
|
|
|
|
| 716 |
# Process upload
|
| 717 |
def handle_book_upload(pdf_bytes):
|
| 718 |
extracted_data, status_msg = process_uploaded_book(pdf_bytes)
|
|
@@ -749,35 +778,45 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 749 |
text = texts[idx] if idx < len(texts) else ""
|
| 750 |
|
| 751 |
analysis = analyze_book_image(img, selected_caption, text)
|
| 752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
# VIVA MODE TAB
|
| 757 |
-
with gr.Tab("π― VIVA Training Mode") as viva_tab:
|
| 758 |
-
viva_status = gr.Markdown("Click 'Start VIVA Training' from Learning Mode after studying a topic!")
|
| 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 |
|
|
|
|
| 186 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 187 |
}
|
| 188 |
|
| 189 |
+
prompt = f"""You are an expert anatomy professor teaching MBBS students. Provide a detailed, high-level educational summary about: {query}
|
| 190 |
|
| 191 |
Format your response with clear sections using these exact emoji icons:
|
| 192 |
|
| 193 |
π **Location & Definition:**
|
| 194 |
+
[Precise anatomical definition, location, and relations using standard medical terminology]
|
| 195 |
|
| 196 |
π **Key Anatomical Features:**
|
| 197 |
+
- [Detailed feature 1 (e.g., attachments, blood supply, innervation)]
|
| 198 |
+
- [Detailed feature 2]
|
| 199 |
+
- [Detailed feature 3]
|
| 200 |
|
| 201 |
π₯ **Clinical Significance:**
|
| 202 |
+
- [Clinical correlation 1 (e.g., pathologies, surgical relevance)]
|
| 203 |
+
- [Clinical correlation 2]
|
| 204 |
|
| 205 |
π **Related Structures:**
|
| 206 |
- [Related structure 1]
|
| 207 |
- [Related structure 2]
|
| 208 |
|
| 209 |
π‘ **Quick Memory Tip:**
|
| 210 |
+
[A high-yield mnemonic or tip for exams]
|
| 211 |
|
| 212 |
+
Keep it professional, accurate, and suitable for medical school level study. Use proper anatomical terminology throughout."""
|
| 213 |
|
| 214 |
payload = {
|
| 215 |
"model": HYPERBOLIC_MODEL,
|
|
|
|
| 249 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 250 |
}
|
| 251 |
|
| 252 |
+
prompt = f"""You are a strict but fair anatomy professor conducting a VIVA exam for final year MBBS students on: {topic}
|
| 253 |
|
| 254 |
+
Generate exactly 5 viva questions that test deep anatomical understanding, clinical application, and relations. For each question, provide:
|
| 255 |
+
1. The question (challenging, requiring synthesis of knowledge)
|
| 256 |
+
2. A helpful hint (guides thinking without giving the answer)
|
| 257 |
+
3. The expected key points in the answer (using proper terminology)
|
| 258 |
|
| 259 |
Format your response EXACTLY as follows:
|
| 260 |
Q1: [question]
|
|
|
|
| 267 |
|
| 268 |
... and so on for all 5 questions.
|
| 269 |
|
| 270 |
+
Make questions progressively harder. Start with detailed relations/supply, then move to complex clinical scenarios."""
|
| 271 |
|
| 272 |
payload = {
|
| 273 |
"model": HYPERBOLIC_MODEL,
|
|
|
|
| 322 |
"Authorization": f"Bearer {HYPERBOLIC_API_KEY}"
|
| 323 |
}
|
| 324 |
|
| 325 |
+
prompt = f"""You are an anatomy professor evaluating an MBBS student's VIVA answer. Expect high standards and precise terminology.
|
| 326 |
|
| 327 |
Question: {question}
|
| 328 |
Expected key points: {expected_answer}
|
|
|
|
| 330 |
|
| 331 |
Provide feedback in this EXACT format:
|
| 332 |
|
| 333 |
+
[First, write one sentence evaluating the precision and depth of the answer]
|
| 334 |
|
| 335 |
β
**What was correct:**
|
| 336 |
+
[List correct points. Praise use of proper terminology.]
|
| 337 |
|
| 338 |
β **What was missing:**
|
| 339 |
+
[List missing key points, relations, or clinical aspects. Be specific about missing terminology.]
|
| 340 |
|
| 341 |
+
**Score:** [Choose: DISTINCTION, PASS, BORDERLINE, or FAIL]
|
| 342 |
|
| 343 |
+
[End with a constructive comment on how to improve to a professional medical standard]
|
| 344 |
|
| 345 |
+
Be professional and constructive. Demand accuracy."""
|
| 346 |
|
| 347 |
payload = {
|
| 348 |
"model": HYPERBOLIC_MODEL,
|
|
|
|
| 359 |
|
| 360 |
# Determine emoji and encouragement based on feedback content
|
| 361 |
feedback_upper = feedback.upper()
|
| 362 |
+
if "DISTINCTION" in feedback_upper:
|
| 363 |
emoji = "π"
|
| 364 |
+
encouragement = "\n\nπ **Outstanding!** Distinction level answer! You're mastering this topic!"
|
| 365 |
+
elif "PASS" in feedback_upper:
|
| 366 |
emoji = "β
"
|
| 367 |
+
encouragement = "\n\nπ **Good Pass!** Solid understanding. Review the finer details to reach distinction level."
|
| 368 |
+
elif "BORDERLINE" in feedback_upper:
|
| 369 |
+
emoji = "β οΈ"
|
| 370 |
+
encouragement = "\n\nπͺ **Borderline.** You have the basics, but need more precision with terminology."
|
| 371 |
else:
|
| 372 |
emoji = "π"
|
| 373 |
+
encouragement = "\n\nπ± **Keep studying.** Focus on the key anatomical relations and clinical points."
|
| 374 |
|
| 375 |
# Format the complete feedback
|
| 376 |
formatted_feedback = f"{emoji} **VIVA Feedback:**\n\n{feedback}{encouragement}\n\n---\n\nπ **Reference Answer:**\n{expected_answer}"
|
|
|
|
| 493 |
# Include extracted text in the prompt context
|
| 494 |
context_text = f"Page Content:\n{page_text}" if page_text else "No text extracted from this page."
|
| 495 |
|
| 496 |
+
prompt = f"""You are an expert anatomy professor helping MBBS students analyze their textbook content.
|
| 497 |
|
| 498 |
A student is looking at {page_info} of their anatomy textbook.
|
| 499 |
{context_text}
|
| 500 |
|
| 501 |
+
Based on the text content above, provide a high-level medical analysis:
|
| 502 |
|
| 503 |
## π Page Overview
|
| 504 |
+
[Summarize the key anatomical topic using standard medical terminology]
|
| 505 |
|
| 506 |
## π Key Concepts Explained
|
| 507 |
+
[Explain the concepts in detail, focusing on relations, blood supply, nerve supply, and lymphatic drainage where applicable]
|
| 508 |
|
| 509 |
## π₯ Clinical Relevance
|
| 510 |
+
[Detailed clinical correlations, surgical landmarks, or pathological conditions mentioned or relevant]
|
| 511 |
|
| 512 |
## π‘ Study Tips
|
| 513 |
+
[High-yield memory aids for medical exams]
|
| 514 |
|
| 515 |
+
## β Self-Test Questions (MBBS Level)
|
| 516 |
1. [Question based on the page text]
|
| 517 |
2. [Question based on the page text]
|
| 518 |
...
|
| 519 |
15. [Question based on the page text]
|
| 520 |
|
| 521 |
+
(Provide at least 15 distinct, challenging questions covering detailed anatomy, relations, and clinical application)
|
| 522 |
|
| 523 |
+
Be professional, accurate, and suitable for medical school level study."""
|
| 524 |
|
| 525 |
payload = {
|
| 526 |
"model": HYPERBOLIC_MODEL,
|
|
|
|
| 693 |
with gr.Column(scale=1):
|
| 694 |
image_output = gr.Image(label="πΌοΈ Anatomy Diagram", type="pil")
|
| 695 |
|
| 696 |
+
# VIVA MODE TAB (Defined before Book Mode to allow component access)
|
| 697 |
+
with gr.Tab("π― VIVA Training Mode") as viva_tab:
|
| 698 |
+
viva_status = gr.Markdown("Click 'Start VIVA Training' from Learning Mode after studying a topic!")
|
| 699 |
+
|
| 700 |
+
with gr.Column(visible=False) as viva_container:
|
| 701 |
+
with gr.Row():
|
| 702 |
+
with gr.Column(scale=1):
|
| 703 |
+
viva_image = gr.Image(label="Reference Image", type="pil", interactive=False)
|
| 704 |
+
|
| 705 |
+
with gr.Column(scale=2):
|
| 706 |
+
current_question_display = gr.Markdown("### Question will appear here")
|
| 707 |
+
hint_display = gr.Markdown("π‘ Hint will appear here")
|
| 708 |
+
|
| 709 |
+
# Audio player for question
|
| 710 |
+
question_audio = gr.Audio(label="π Listen to Question", autoplay=True, interactive=False)
|
| 711 |
+
|
| 712 |
+
student_answer = gr.Textbox(
|
| 713 |
+
label="Your Answer",
|
| 714 |
+
placeholder="Type your answer here...",
|
| 715 |
+
lines=4
|
| 716 |
+
)
|
| 717 |
+
|
| 718 |
+
submit_answer_btn = gr.Button("Submit Answer", variant="primary")
|
| 719 |
+
|
| 720 |
+
feedback_display = gr.Markdown("Feedback will appear here after you submit your answer")
|
| 721 |
+
|
| 722 |
# BOOK LEARNING MODE TAB
|
| 723 |
with gr.Tab("π Book Learning Mode") as book_tab:
|
| 724 |
# Upload PDF
|
|
|
|
| 739 |
# Analysis output
|
| 740 |
analysis_output = gr.Markdown(label="Page Analysis")
|
| 741 |
|
| 742 |
+
# Button to start VIVA from this page
|
| 743 |
+
start_viva_book_btn = gr.Button("π― Start VIVA Training from this Page", variant="primary", visible=False)
|
| 744 |
+
|
| 745 |
# Process upload
|
| 746 |
def handle_book_upload(pdf_bytes):
|
| 747 |
extracted_data, status_msg = process_uploaded_book(pdf_bytes)
|
|
|
|
| 778 |
text = texts[idx] if idx < len(texts) else ""
|
| 779 |
|
| 780 |
analysis = analyze_book_image(img, selected_caption, text)
|
| 781 |
+
|
| 782 |
+
# Construct a topic string for VIVA
|
| 783 |
+
viva_topic = f"Anatomy of {selected_caption} (from textbook)"
|
| 784 |
+
|
| 785 |
+
return img, analysis, viva_topic, gr.update(visible=True)
|
| 786 |
|
| 787 |
+
# Hidden state to store current page topic for VIVA
|
| 788 |
+
current_book_topic = gr.State("")
|
|
|
|
|
|
|
|
|
|
| 789 |
|
| 790 |
+
page_dropdown.change(
|
| 791 |
+
fn=show_page_analysis,
|
| 792 |
+
inputs=[page_dropdown, book_images_state, page_captions_state, page_texts_state],
|
| 793 |
+
outputs=[selected_page_image, analysis_output, current_book_topic, start_viva_book_btn]
|
| 794 |
+
)
|
| 795 |
+
|
| 796 |
+
# Start VIVA from Book Mode
|
| 797 |
+
start_viva_book_btn.click(
|
| 798 |
+
fn=lambda: gr.update(value="β³ Processing VIVA Question...", interactive=False),
|
| 799 |
+
outputs=[start_viva_book_btn]
|
| 800 |
+
).then(
|
| 801 |
+
fn=start_viva_mode,
|
| 802 |
+
inputs=[current_book_topic, selected_page_image],
|
| 803 |
+
outputs=[
|
| 804 |
+
viva_container, viva_status, viva_image,
|
| 805 |
+
current_question_display, hint_display,
|
| 806 |
+
student_answer, feedback_display, submit_answer_btn,
|
| 807 |
+
viva_questions_state,
|
| 808 |
+
question_audio
|
| 809 |
+
]
|
| 810 |
+
).then(
|
| 811 |
+
fn=lambda: gr.update(selected=1), # Switch to VIVA tab (index 1 is VIVA tab)
|
| 812 |
+
outputs=[tabs]
|
| 813 |
+
).then(
|
| 814 |
+
fn=lambda: gr.update(value="π― Start VIVA Training from this Page", interactive=True),
|
| 815 |
+
outputs=[start_viva_book_btn]
|
| 816 |
+
).then(
|
| 817 |
+
fn=lambda: 0,
|
| 818 |
+
outputs=[current_question_idx]
|
| 819 |
+
)
|
| 820 |
|
| 821 |
|
| 822 |
|