24 Streamlit app with Gemini CLI
Aim
The aim for this in-class exercise is to practice using an agentic programming command line interface to work on code. We’ll continue with our food-centric theme and create a Streamlit app that will:
Take a list of ingredients as input
Query Google Gemini for a recipe using those ingredients
Display the query results
We’ll be running everything on Google cloud, using the Gemini CLI.
Setup
Log into https://console.cloud.google.com
Get a Gemini API key here: https://aistudio.google.com/app/api-keys
Create a new project
Create a new key for your project
Add your api key to the end of your
.bashrcfile withnano ~/.bashrcAdd this line:
export GOOGLE_API_KEY="<key>"where “key” is the API key you just createdThis will save it for future sessions, but you’ll either need to log out and back in again or run that line of code from the command prompt (i.e.
export GEMINI_API_KEY="<key>")
Set up your python virtual environment
python -m venv .venvsource .venv/bin/activatepip install streamlit google-genai
Building the app
Open the Gemini CLI and let’s get started:
The cloud shell will automagically open a Gemini CLI terminal window and then immediately complain that it is running your home directory. You can get rid of this warning by:
Close the Gemini CLI tab
Open a new tab
Create a project work directory (only do this once - e.g. with
mkdir recipeApp) and run:cd recipeAppgemini
Prompt it with something like the following:
Please create a streamlit app inside of the recipeApp directory. It should have an entry field for ingredients I have on hand and query Gemini using the google-genai connector to recommend a recipe using the provided ingredients. The output should be displayed below the text entry field.
Follow the instructions by running:
pip install -r requirements.txtstreamlit run app.py --server.port=8080 --server.address=0.0.0.0 --server.enableCORS=false(this is slightly different from what the CLI will probably tell you, but after troubleshooting an issue where the app persistently hangs on startup, this works better on Google cloud)Click on the link at the bottom of the terminal window to start up the app
Testing the app
It probably won’t get things right on the first try, but keep working on it and you’ll probably get something relatively quickly. A few issues I ran across:
Networking issues: This was the most difficult issue I had to deal with. I think the Gemini CLI wasn’t aware that it was running in the cloud. It was sure that the app was able to start up just fine, but when trying to connect from my computer, it had issues. After some troubleshooting, I was able to find the recommended flags above that fixed the issue (i.e.
--server.port=8080 --server.address=0.0.0.0 --server.enableCORS=false).Syntax errors: there were a couple syntax errors. After passing error messages along to the Gemini CLI it was able to fix these.
The Gemini CLI didn’t use the correct model. You’ll probably want to use “gemini-2.5-flash”.
Pushing to GitHub
When you are finished, create a new repository using this link, and push your new recipe app to GitHub. When you first open your repository on GitHub, you should see a list of instructions for how to set up your repo:
Initialize the repository
git init
Commit your app code
git add app.py requirements.txtgit commit -m "initial version"
Change the branch name and push
git branch -M maingit remote add origin https://github.com/ITMG533/<repo>where “<repo>” is the name of your new repositorygit push -u origin mainYou will need a GitHub command line token for this step. You can set one up here:
- git branch -M main