This project is a Streamlit-based Blackjack Agent that uses PyTorch to load a trained model and make decisions in a simplified Blackjack game. The app allows users to input the game state (player's hand sum, dealer's visible card, usable ace) and get the agent's recommended action (hit or stick).
- Interactive UI built with Streamlit
- Loads a trained PyTorch model
- Accepts user input for game state
- Outputs the agent's recommended action
- Lightweight and easy to deploy
-
Clone the repository:
git clone https://github.com/BrianP490/BlackJack-Agent.git cd BlackJack-Agent
-
Create and Activate the Conda Environment for local app hosting: This project uses a Conda environment for managing dependencies, including PyTorch. The environment configuration is provided in dev_requirements.yaml
- Create the environment: Ensure you are in the root directory of the cloned repository (BlackJack-Agent/).
conda env create -f dev_requirements.yaml
- Activate the environment:
conda activate GRPO_env
Your terminal prompt should change to (GRPO_env) indicating the environment is active.
If running ipynb file on VS code: Select install ikernel when popup appears when first activating the env, select the GRPO_env for the kernel, and run the cells. -
(OPTIONAL) Train a New Model: You can also run the training script "./app/scripts/train.py":
# Use the -h option for running options: python ./app/scripts/train.py -h
You will have to change line 10's variable "weights_file" in "./app/main.py" to use the correct path to your trained model weights. This is if you chose to save you model in another location besides the default path "./app/model_weights/blackjack_policy_model.pth"
-
Run the Streamlit Application: Once your Conda environment is active, you can launch the Streamlit application.
- Navigate to the correct directory (if not already there): Make sure your current working directory in the terminal is BlackJack-Agent/ (the root of the project where app/ resides).
# If you're not in the BlackJack-Agent directory, navigate there: # cd C:\Users\brian\DESKTOP\Dev\GIT_CLONES\projects\GRPO_Project_Iteration\BlackJack
- Launch the Streamlit app:
streamlit run app/main.py
Enjoy!
You can also launch this with the streamlit online app deployment on https://streamlit.io/, just make sure to follow the steps to create a new repository with this clone and make sure that "requirements.txt" is at the root directory.