gladguy commited on
Commit
3409908
Β·
1 Parent(s): 3fb3d32

Add VIVA button to Book Mode and update AI persona

Browse files
Files changed (1) hide show
  1. app.py +105 -66
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 tutor for MBBS students. Provide key educational points about: {query}
190
 
191
  Format your response with clear sections using these exact emoji icons:
192
 
193
  πŸ“ **Location & Definition:**
194
- [Brief description of what it is and where it's located]
195
 
196
  πŸ” **Key Anatomical Features:**
197
- - [Feature 1]
198
- - [Feature 2]
199
- - [Feature 3]
200
 
201
  πŸ₯ **Clinical Significance:**
202
- - [Clinical point 1]
203
- - [Clinical point 2]
204
 
205
  πŸ”— **Related Structures:**
206
  - [Related structure 1]
207
  - [Related structure 2]
208
 
209
  πŸ’‘ **Quick Memory Tip:**
210
- [A mnemonic or helpful tip to remember this anatomy]
211
 
212
- Keep it concise, clear, and educational. Use simple medical terminology."""
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 an anatomy professor conducting a VIVA exam on: {topic}
253
 
254
- Generate exactly 5 viva questions that would be asked during an MBBS anatomy practical exam. For each question, provide:
255
- 1. The question
256
- 2. A helpful hint (not the answer, but guides student thinking)
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 identification, then structure, then clinical relevance."""
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 encouraging anatomy professor evaluating a student's VIVA answer.
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 encouraging sentence praising effort or any correct elements]
334
 
335
  βœ… **What was correct:**
336
- [List what the student got right - be specific. If nothing, write "Unfortunately, the answer didn't cover the key anatomical points."]
337
 
338
  ❌ **What was missing:**
339
- [List what important points were missed - be specific. If nothing was missed, write "Nothing! You covered all the key points."]
340
 
341
- **Score:** [Choose: EXCELLENT, GOOD, FAIR, or NEEDS_IMPROVEMENT]
342
 
343
- [End with an encouraging message that motivates continued learning]
344
 
345
- Be warm, supportive, and constructive. Celebrate correct answers enthusiastically!"""
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 "EXCELLENT" in feedback_upper:
363
  emoji = "🌟"
364
- encouragement = "\n\nπŸŽ‰ **Outstanding!** You're mastering this topic! Keep up the excellent work!"
365
- elif "GOOD" in feedback_upper:
366
  emoji = "βœ…"
367
- encouragement = "\n\nπŸ‘ **Well done!** You're doing great! A bit more practice and you'll ace this!"
368
- elif "FAIR" in feedback_upper:
369
- emoji = "πŸ‘"
370
- encouragement = "\n\nπŸ’ͺ **Good effort!** You're on the right track. Review the key points and try again!"
371
  else:
372
  emoji = "πŸ“š"
373
- encouragement = "\n\n🌱 **Keep learning!** Don't worry, understanding anatomy takes practice. You've got this!"
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 learn from their textbook.
497
 
498
  A student is looking at {page_info} of their anatomy textbook.
499
  {context_text}
500
 
501
- Based on the text content above (and typical anatomical diagrams found in such contexts), provide a comprehensive explanation:
502
 
503
  ## πŸ“– Page Overview
504
- [Summarize the key anatomical topic discussed on this page based on the text]
505
 
506
  ## πŸ” Key Concepts Explained
507
- [Explain the main concepts covered in the text in simple terms]
508
 
509
  ## πŸ₯ Clinical Relevance
510
- [Extract or infer clinical points mentioned or relevant to this topic]
511
 
512
  ## πŸ’‘ Study Tips
513
- [How to remember this specific information]
514
 
515
- ## ❓ Self-Test Questions (Answer these to test your understanding)
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 identification, function, clinical application, and relationships)
522
 
523
- Be educational and specific to the provided text content."""
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
- return img, analysis
 
 
 
 
753
 
754
- page_dropdown.change(fn=show_page_analysis, inputs=[page_dropdown, book_images_state, page_captions_state, page_texts_state], outputs=[selected_page_image, analysis_output])
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
- with gr.Column(visible=False) as viva_container:
761
- with gr.Row():
762
- with gr.Column(scale=1):
763
- viva_image = gr.Image(label="Reference Image", type="pil", interactive=False)
764
-
765
- with gr.Column(scale=2):
766
- current_question_display = gr.Markdown("### Question will appear here")
767
- hint_display = gr.Markdown("πŸ’‘ Hint will appear here")
768
-
769
- # Audio player for question
770
- question_audio = gr.Audio(label="πŸ”Š Listen to Question", autoplay=True, interactive=False)
771
-
772
- student_answer = gr.Textbox(
773
- label="Your Answer",
774
- placeholder="Type your answer here...",
775
- lines=4
776
- )
777
-
778
- submit_answer_btn = gr.Button("Submit Answer", variant="primary")
779
-
780
- feedback_display = gr.Markdown("Feedback will appear here after you submit your answer")
 
 
 
 
 
 
 
 
 
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