AQIVisualizer is a command-line Python application that fetches the Air Quality Index (AQI) data for a specified city and generates a landscape image that artistically represents the current air quality conditions. The tool uses environmental data APIs and OpenAI's image generation capabilities to overlay the AQI value on the image in a hyper-realistic style.
For example:
- Fetch real-time AQI data for any specified city.
- Generate a hyper-realistic image of the city's landmark with an AQI representation.
- Customize the text overlay on the generated image.
- Command-line arguments for easy customization.
- Save the final image to a specified path.
Before you begin, ensure you have met the following requirements:
- Python 3.6 or higher installed on your machine.
- An active internet connection to fetch data from APIs and generate images.
- API keys for OpenAI and AQICN services.
The project is organized into the following modules:
aqi_api.py: Handles the fetching of AQI data from the environmental data API.image_generator.py: Manages the generation of images and the addition of text overlays.cli.py: Contains the command-line interface logic for accepting user inputs.utils.py: Provides utility functions such as logging setup.main.py: Serves as the entry point to the application, orchestrating the flow between modules
To install AQIVisualizer, follow these steps:
- Clone the repository or download the source code to your local machine.
- Navigate to the project directory.
- Install the required Python dependencies:
pip install -r requirements.txt
- Set up your API keys as environment variables:
Replace
export OPEN_AI_TOKEN=your_openai_token export AQICN_TOKEN=your_aqicn_token
your_openai_tokenandyour_aqicn_tokenwith your actual OpenAI and AQICN API keys, respectively.
To use AQIVisualizer, you can run the script with optional command-line arguments. Here's how you can execute the script:
python main.py --city "City Name" --text "Custom Text Overlay" --output "path/to/save/image"Example:
❯ python main.py --city "Pune" --output "/Users/jmalik/Downloads"
2023-11-10 09:41:41,677 - INFO - Fetching AQI data for Pune
2023-11-10 09:41:42,502 - INFO - Successfully retrieved AQI data: 232
2023-11-10 09:41:42,504 - INFO - Generating image prompt for city: Pune, with AQI: 232
2023-11-10 09:41:42,504 - INFO - Requesting image generation with prompt: Create a realistic landscape image of a famous landmark or popular destination from Pune. The image should be altered to reflect an Air Quality Index based on AQI value: 232. The artistic style should be a hyper-realistic render, closely resembling a high-resolution photograph. The aspect ratio of the image should be 16:9 to provide a wide landscape view
2023-11-10 09:41:58,217 - INFO - HTTP Request: POST https://api.openai.com/v1/images/generations "HTTP/1.1 200 OK"
2023-11-10 09:41:58,220 - INFO - Image generated successfully
2023-11-10 09:41:58,220 - INFO - Downloading image from URL: https://oaidal......<image-url>.....
2023-11-10 09:42:04,679 - INFO - Image downloaded successfully
2023-11-10 09:42:04,688 - INFO - Adding text overlay to image
2023-11-10 09:42:05,035 - INFO - Text overlay added successfully
2023-11-10 09:42:05,036 - INFO - Saving and copying image to the specified path
2023-11-10 09:42:05,477 - INFO - Image saved to temporary path: /tmp/Pune_232.png
2023-11-10 09:42:05,481 - INFO - Image copied to user-specified path: /Users/jmalik/Downloads/Pune_232.png--city: Specify the city name for which you want to fetch the AQI data and generate the image. If not provided, "here" will be used as the default value.--text: Custom text to overlay on the image. If not provided, the default text will be in the format "City Name // AQI".--output: Specify the path where you want to save the generated image. If not provided, the image will be saved in the current directory.--help: Display help information and exit.
If you would like to contribute to the development of AQIVisualizer, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature_branch). - Make changes and add them (
git add .). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature_branch). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or feedback, please contact the project maintainer.
Happy visualizing!

