A study project demonstrating how to build small tools with the Google Gemini API using Python. The scripts cover text generation, classification, sentiment analysis, model selection by token limit, and cost estimation.
- Python 3.12+: base of the project.
- google-generativeai: official SDK for accessing Gemini models.
- python-dotenv: loads environment variables from a
.envfile. - Gemini 2.5 Flash / Pro: models used in the examples.
.
├── main.py # Generates a product list with brief descriptions
├── categorizer.py # Classifies a product into predefined categories
├── sentiment_analyzer.py # Summarizes reviews and extracts sentiment/strengths/weaknesses
├── model_selector.py # Picks Flash or Pro based on the prompt's token count
├── token_counter.py # Shows token limits and estimates cost per response
└── data/
├── purchase_profile.csv # Sample customer purchase history
├── reviews-<product>.txt # Sample product reviews (input)
└── response-<product> # Generated sentiment analysis (output)
| Script | Description |
|---|---|
main.py |
Generates a list of products with a brief description using a system prompt. |
categorizer.py |
Classifies a product into predefined categories (input via terminal). |
sentiment_analyzer.py |
Summarizes reviews and reports overall sentiment, strengths and weaknesses. Reads data/reviews-<product>.txt files and saves the result to data/response-<product>. |
model_selector.py |
Picks a model based on the token limit and analyzes purchase profiles in data/purchase_profile.csv. |
token_counter.py |
Shows token limits and estimates the cost per response. |
- Python 3.12+ installed
- A Gemini API key (
GEMINI_API_KEYenvironment variable)
Option A (pip):
python -m venv .venv
. .venv/bin/activate
pip install -U pip
pip install .Option B (uv):
uv syncCreate a .env file in the project root:
GEMINI_API_KEY=your_key_herepython main.py
python categorizer.py
python sentiment_analyzer.py
python model_selector.py
python token_counter.py- E-commerce and retail: automatic product categorization and catalog enrichment.
- Customer service and support: sentiment analysis on reviews and tickets to spot recurring issues.
- Marketing: fast generation of descriptions and segmented campaigns.
- Finance and planning: cost-per-query estimation and routing to the most cost-effective model.
- BI and CRM: customer segmentation based on purchase history.
- Adjust the prompts to fit your domain and business rules.
- For production use, consider error handling, structured logging, and input validation.