Skip to content

pythonhealthdatascience/llm_simpy_models

Repository files navigation

Licence: MIT Python 3.10+ DOI

Complementary repository: Final discrete-event simulation models and streamlit applications from Large Language Models

This repository is complementary to:

Thomas Monks, Alison Harper, and Amy Heather. Research Compendium: Replicating Simulations in Python using Generative AI. https://github.com/pythonhealthdatascience/llm_simpy.

It contains the final formatted code from each of the SimPy discrete-event simulation models that were generated by Perplexity as part of that project.

The web applications are deployed as a single app on GitHub pages using stlite. This allows the app to run directly in a user's web browser without requiring any manual installations. It achieves this by using WebAssembly technology to run a serverless version of streamlit (i.e. stlite). The entire app, along with all its dependencies, are downloaded and installed within the browser at runtime using pyodide and micropip. There will be a short wait while the app is setup. Once the setup is complete, the app runs locally in the browser, meaning that no user data leaves the local machine. Please note that stlite does not currently work in Mozilla Firefox.

Link to the deployed app: https://pythonhealthdatascience.github.io/llm_simpy_models/

Code: The final formatted code from each stage are stored in 📁pages\:

  • CCU_Stage_1.py
  • CCU_Stage_2.py
  • Stroke_Stage_1.py
  • Stroke_Stage_2.py

The stroke .py files combine the seperate model and app .py files from the llm_simpy repository.

For a full record of the generation of these models, please refer to: https://github.com/pythonhealthdatascience/llm_simpy.


👥 Authors

  • Thomas Monks    ORCID: Monks

  • Alison Harper    ORCID: Harper

  • Amy Heather    ORCID: Heather


🌐 Creating the environment

conda

The project uses conda to manage dependencies. Navigate your terminal to the directory containing the code and run:

conda env create -f binder/environment.yml

This will create a conda environment called gen_simpy_apps. To activate:

conda activate gen_simpy_apps

This environment is a simplified version of that from the llm_simpy repository, containing only the dependencies required for running the models and apps.

venv

Another option is to use venv. You can build the environment by running:

python -m venv venv

Then install the packages using:

pip install -r requirements.txt

venv cannot control which python version is used, it will just use one on system. You can check what this is by running:

venv/bin/python --version

You can find the version of python used for the models and app in the binder/environment.yaml file.

Docker

Alternatively, a docker environment has been provided.

Build docker image locally

You can build the image by running:

docker build -f binder/Dockerfile -t gen_simpy_apps .

And run the container:

docker run -p 8501:8501 gen_simpy_apps

Open your browser to http://localhost:8501/ to view the app.

Pull docker image from container registry

Another option is to pull the image from the GitHub Container Registry (GHCR). As explained in the GHCR documentation, you'll need to create an access token to install from GHCR (even when it is a public image). You can create a token by going to your profile Settings > Developer Settings > Personal access tokens > Tokens (classic) > Generate new token. You can then login:

docker login ghcr.io -u username -p accesstoken

And should be able to pull the image:

docker pull ghcr.io/pythonhealthdatascience/llm_simpy_models:latest

You can then run the container:

docker run -p 8501:8501 ghcr.io/pythonhealthdatascience/llm_simpy_models

Open your browser to http://localhost:8501/ to view the app.


🖥️ Viewing the apps locally

For deployment, we have brought the LLM-generated apps together into a single app, which can be deployed by running:

streamlit run Home.py

However, you can also run the individual original apps generated by the LLMs by calling on a specific file - for example:

streamlit run pages/CCU_Stage_1.py

To test the stlite app locally, run the following command, and then open http://0.0.0.0:8000/ on your web browser:

python3 -m http.server

📝 Citation

Please cite the archived repository:

Thomas Monks, Alison Harper, and Amy Heather. Complementary repository: Final discrete-event simulation models and streamlit applications from Large Language Models. https://doi.org/10.5281/zenodo.15082494.

You can also cite this GitHub repository as:

Thomas Monks, Alison Harper, and Amy Heather. Complementary repository: Final discrete-event simulation models and streamlit applications from Large Language Models. https://github.com/pythonhealthdatascience/llm_simpy_models.

A CITATION.cff file is also provided.


💰 Funding

This project was developed as part of the project STARS: Sharing Tools and Artefacts for Reproducible Simulations. It is supported by the Medical Research Council [grant number MR/Z503915/1].

About

The SimPy models and apps generated by LLMs, deployed as a single app.

Resources

License

Stars

Watchers

Forks

Packages

No packages published