A very basic implementation of the magic 8 ball game that simply asks the user for a question and uses a Gemini Pro model to generate an answer. The model simulates a magic 8 ball in real life.
Get your Google API Key from here.
Open up a terminal and clone the repository.
git clone <repo-link>
Navigate to the cloned repo directory.
cd magic_8_ball
Set up your Google API key as an environment variable.
Alternatively, you can create a .env
file in your directory and use the python-dotenv
library to read environment variables.
GOOGLE_API_KEY='<your-api-key>'
Create a Python virtual environment and activate it.
python -m venv env
env\Scripts\activate
Install the necessary dependencies in requirements.txt
file.
pip install -r requirements.txt
Open up a terminal and run the app.py
file.
uvicorn app:app --reload
Open the index.html
file in your browser of choice and play the game.
Test the API by make a POST request on the /ask
endpoint.
curl -X POST "http://localhost:8000/ask" -H "Content-Type: application/json" -d "{\"question\":\"Will I succeed?\"}"
You can also play the game in command line by running cli.py
in any terminal.
python cli.py --question "<your-question>"
The FastAPI endpoint is deployed on Leapcell and the frontend is deployed on GitHub pages as a static webpage.
Feel free to open up a pull request to point out a bug or an improvement.