π Note: This is the code repository of our paper "MedGAME: Storytelling Gamification Empowered by Large Language Models for Medical Education".
- Before diving into our code configuration, we would like to first present a silhouette of our MedGame...
An interactive storytelling game for medical education that can be automatically designed, planned and generated with LLM-driven workflow.
Case 1 |
Case 2 |
(Note: Sometimes GitHub may fail to render the MedGame demo GIFs above. If this happens, you can download them directly from ./Assets/GIFS.)
- Next, we introduce the building blocks of a Clinical Story: ACT and Scene.
An ACT serves as a container for multiple Scenes, representing a major phase in the patient's clinical journey.
ACT Structure - Example 1 |
ACT Structure - Example 2 |
A Scene is a focused clinical encounter within an ACT, containing narrative segments and various interactive elements.
Scene Structure - Example 1 |
Scene Structure - Example 2 |
Each Scene contains interactive puzzle nodes that test student knowledge through different question formats.
Single Choice |
Batch Question (Multiple Selection) |
Interactive Question |
- Now let's dive into the technical details of our MedGame framework...
MedGame/
βββ README.md # This file
βββ requirements.txt # Python dependencies
β
βββ MedGame_Pipeline/ # Core MedGame framework
β βββ config.py # Configuration (API keys placeholder)
β βββ prompts.py # LLM prompts for narrative design
β βββ pydantic_models.py # Clinical story tree schema
β βββ generation_factory.py # Phase 1: Medical Narrative Designer
β βββ movie_builder.py # Phase 2: Story Director (Visual)
β βββ audio_video_pipeline.py # Phase 2: Multimodal Execution (Audio)
β βββ infinitetalk_runner.py # Phase 2: Multimodal Execution (Video)
β
βββ MedGAME_UI/ # Interactive Game Player Application
β βββ BackEnd/ # FastAPI backend server
β β βββ app/
β β β βββ api/ # API endpoints (cases, game, media, player)
β β β βββ models/ # Data models (media, player, story)
β β β βββ services/ # Business logic services
β β β βββ config.py # Backend configuration
β β β βββ main.py # FastAPI application entry
β β βββ requirements.txt # Backend dependencies
β β βββ run.py # Backend launcher
β βββ Frontend/ # React + TypeScript frontend
β β βββ src/
β β β βββ components/ # UI components (game, interaction, layout)
β β β βββ pages/ # Page components (HomePage, GamePage)
β β β βββ stores/ # State management (gameStore)
β β β βββ types/ # TypeScript type definitions
β β β βββ api/ # API client
β β βββ vite.config.ts # Vite build configuration
β β βββ tailwind.config.js # Tailwind CSS configuration
β βββ Data_Samples/ # Sample game data for demo
β βββ run.sh # Start frontend & backend
β βββ stop.sh # Stop all services
β
βββ Shells/ # Training & evaluation scripts
β βββ Training/
β β βββ MedicalNarrativeGeneration/ # Phase 1 training
β β βββ StoryDirection/ # Phase 2 training
β βββ Evaluation/
β β βββ MedicalNarrativeGeneration/ # Phase 1 evaluation
β β βββ StoryDirection/ # Phase 2 evaluation
β βββ Evaluation_0shot_StoryDirection/ # Zero-shot evaluation
β βββ Evaluation_2shot_MedicalNarrativeGeneration/ # Two-shot evaluation
β
βββ Assets/
βββ GIFS/ # Demo GIFs for README
βββ images/ # Static images (Banner, etc.)
βββ SFT_data/ # Training/evaluation datasets
The MedGame pipeline follows a two-phase generative workflow as described in Section 4 of the paper (see Figure 1):
- Phase 1: Script Synthesis (Steps 1-2) β The Medical Narrative Designer transforms raw patient summaries into a structured Game Script.
- Phase 2: Orchestration and Execution (Steps 3-6) β The Story Director decomposes the script into multimodal generation primitives and coordinates task execution.
Corresponds to Steps 1-2 in Figure 1 Β· Implementation:
generation_factory.py
The Medical Narrative Designer
where
| Component | Description |
|---|---|
| Few-shot exemplars |
Clinical examples for in-context learning |
| Pydantic schema | Structural constraints enforcing output validity |
| Medical rubrics |
Standards for clinical reasoning and pedagogical design |
| Narrative elements |
Character and scene selection constraints |
Corresponds to Steps 3-4 in Figure 1 Β· Implementation:
movie_builder.py
The Story Director
where
Key concepts:
- Initial frame synthesis: Establishes canonical visual reference by fixing identity and scene layout
-
Dependency edges
$(u \rightarrow v) \in E$ : Encode asset-level dependencies between tasks - Asset propagation: Promotes long-horizon visual coherence by reusing upstream assets
Corresponds to Steps 5-6 in Figure 1 Β· Implementation:
audio_video_pipeline.py,infinitetalk_runner.py
The system materializes interactive assets by executing generation primitives following the DAG:
where
We use two conda environments:
medgame: For the MedGame pipelinemedgame_llm: For LLM training and inference
# Create MedGame pipeline environment
conda create -n medgame python=3.10
conda activate medgame
pip install -r requirements.txt
# Create LLM training environment
conda create -n medgame_llm python=3.10
conda activate medgame_llm
pip install ms-swift[all]
pip install unslothBefore running the pipeline, configure your API keys in MedGame_Pipeline/config.py:
# Replace with your actual API keys
LLM_API_BASE = "YOUR_API_BASE_URL"
LLM_API_KEY = "YOUR_API_KEY"For setting up the interactive game player UI (Frontend + Backend), please refer to MedGAME_UI/README.md.
from MedGame_Pipeline.generation_factory import Generation_Factory
# Initialize factory
factory = Generation_Factory()
# Run Phase 1: Script Synthesis (Steps 1-2)
factory.pipeline_with_scene_and_character_constraints(
input_text=patient_summary,
output_dir="./output",
model_version="3",
reasoning_effort="low"
)# Train Medical Narrative Generation model
conda activate medgame_llm
cd Shells/Training/MedicalNarrativeGeneration
bash train_qwen3_8b_medical_narrative_generation.sh
# Train Story Direction model
cd Shells/Training/StoryDirection
bash train_qwen3_8b_story_direction.sh# Evaluate Medical Narrative Generation
cd Shells/Evaluation/MedicalNarrativeGeneration
bash eval_qwen3_8b_medical_narrative_generation.sh
# Evaluate Story Direction
cd Shells/Evaluation/StoryDirection
bash eval_qwen3_8b_story_direction_sft.shIf you find this repo useful, please consider giving us a star and citing our paper:
@misc{wu2026medgamestorytellinggamificationempowered,
title={MedGame: Storytelling Gamification Empowered by Large Language Models for Medical Education},
author={Qian Wu and Xinrong Zhou and Zizhan Ma and Kai Chen and Zheyao Gao and Xun Lin and Hongqiu Wu and Longfei Gou and Yixiao Liu and Ann Sin Nga Lau and Qi Dou},
year={2026},
eprint={2607.21570},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2607.21570},
}
If you have any question / want to collaborate with us, please email to qianwu@link.cuhk.edu.hk. Thanks









