Spaces:
Runtime error
A newer version of the Gradio SDK is available:
6.5.1
title: EcoLogits Chat
emoji: π±
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
short_description: Mistral tracking environmental impact real-time
suggested_hardware: cpu-basic
suggested_storage: small
tags:
- mistral
- ecologits
- environment
- sustainability
- ai-chat
- carbon-footprint
- energy-consumption
python_version: 3.12
fullWidth: true
header: default
EcoLogits - AI Environmental Impact Tracker
A clean, modular chat application that tracks the environmental impact of AI model usage using EcoLogits library and Mistral AI models.
π± Overview
This application provides a user-friendly interface to chat with Mistral AI models while tracking their environmental impact in real-time. It displays energy consumption and carbon footprint for each conversation, promoting awareness of AI's environmental costs.
β¨ Features
- Clean Chat Interface: Simple Gradio-based web interface with tabbed impact tracking
- Environmental Tracking: Real-time tracking of energy usage and carbon emissions using EcoLogits
- Smart Model Filtering: Automatically filters to show only text-to-text capable models (excludes OCR, embedding, vision models)
- Tabbed Impact Visualization:
- π― Last Message: Impact of the specific last request with warnings/errors
- π Total Session: Cumulative environmental metrics across the entire session
- Warning System: Shows EcoLogits warnings and errors conditionally in the UI
- Modular Architecture: Clean separation of concerns across multiple files
- Session Management: Clear conversation and reset impacts with the "Effacer tout" button
ποΈ Architecture
The application is organized into focused, reusable modules:
βββ app.py # Main application entry point
βββ config.py # Configuration and environment variables
βββ mistral_client.py # Mistral API wrapper with EcoLogits integration
βββ impacts_tracker.py # Environmental impact tracking and calculations
βββ chat_interface.py # Gradio UI components and user interaction
βββ app_original.py # Backup of original monolithic version
Module Responsibilities
config.py: Centralized configuration management, environment variables, fallback modelsmistral_client.py: Handles Mistral API communication, intelligent model filtering, EcoLogits integrationimpacts_tracker.py: Tracks and calculates cumulative environmental impactschat_interface.py: Manages the Gradio web interface with tabbed impact displayapp.py: Simple entry point that ties everything together
π Setup
Prerequisites
- Python 3.8+
- Mistral AI API key
Installation
Clone or download the project files
Create a virtual environment:
python -m venv .venvActivate the virtual environment:
# Windows .venv\Scripts\Activate.ps1 # Linux/Mac source .venv/bin/activateInstall dependencies:
pip install gradio mistralai ecologits python-dotenvSet up environment variables:
Create a
.envfile in the project root:MISTRAL_API_KEY=your_mistral_api_key_hereOr set the environment variable directly:
# Windows $env:MISTRAL_API_KEY="your_mistral_api_key_here" # Linux/Mac export MISTRAL_API_KEY="your_mistral_api_key_here"
Getting a Mistral API Key
- Visit Mistral AI Console
- Create an account or sign in
- Navigate to API Keys section
- Create a new API key
- Copy the key and add it to your
.envfile
π― Usage
Running the Application
Activate your virtual environment:
.venv\Scripts\Activate.ps1Run the application:
python app.pyOpen your browser to the displayed URL (typically
http://127.0.0.1:7860)
Using the Interface
- Select a Model: Choose from available text-to-text Mistral models (automatically filtered)
- Start Chatting: Enter your message and click Send
- Monitor Impact: Use the tabs to view different impact metrics:
- π― Dernier message: Impact of your last request + any EcoLogits warnings/errors
- π Session totale: Cumulative impact across the entire conversation
- Track Progress: See real-time energy and carbon consumption updates
- Clear Session: Use "ποΈ Effacer tout" to start fresh and reset all impacts
π Environmental Metrics
The application tracks and displays:
- Energy Consumption: Measured in kilowatt-hours (kWh)
- Carbon Emissions: CO2 equivalent emissions in grams
- Cumulative Totals: Running totals across the entire session
- Per-Message Impact: Individual impact of each AI response
π§ Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
MISTRAL_API_KEY |
Your Mistral AI API key | Required |
Model Selection
The application automatically:
- Fetches available models from Mistral API
- Filters to only show text-to-text capable models (using
completion_chatcapability) - Falls back to predefined models if API is unavailable
Fallback Models
If the Mistral API is unavailable, the application uses these models:
mistral-small-latestmistral-large-latestopen-mistral-nemo
π οΈ Development
Code Structure
The codebase follows clean architecture principles:
# Clean separation of concerns
config.py # Configuration management
mistral_client.py # External API integration
impacts_tracker.py # Business logic for tracking
chat_interface.py # UI presentation layer
app.py # Application composition
Key Design Decisions
- Model Filtering: Only shows models with
completion_chat: truecapability - Error Handling: Graceful degradation when APIs are unavailable
- Environmental Focus: EcoLogits warnings displayed prominently in UI
- Modular Design: Each file has a single, clear responsibility
Adding New Features
The modular structure makes it easy to extend:
- New Providers: Add to
mistral_client.pyor create similar modules - UI Changes: Modify
chat_interface.py - Tracking Logic: Extend
impacts_tracker.py - Configuration: Add to
config.py
π About EcoLogits
EcoLogits is a Python library that tracks the environmental impact of AI model usage. It provides:
- Real-time energy consumption tracking
- Carbon footprint calculations
- Support for multiple AI providers
- Detailed impact reporting
This application demonstrates responsible AI usage by making environmental costs visible and measurable.
π Troubleshooting
Common Issues
"Invalid model" errors:
- Fixed! The app now filters out incompatible models automatically
- Check the console output to see which models are included/excluded
Clear button not working:
- Fixed! The "Effacer tout" button now properly resets conversation and impacts
Missing tabs:
- Fixed! Tabbed interface restored with "Dernier message" and "Session totale"
API connection issues:
- Check your
MISTRAL_API_KEYin the.envfile - The app will fall back to predefined models if the API is unavailable
- Check your
Recent Improvements
- β Fixed Model Filtering: No more "Invalid model" errors from OCR/specialized models
- β Restored Tabbed Interface: Full impact tracking with organized tabs
- β Fixed Clear Button: "Effacer tout" now properly resets conversation and impacts
- β Enhanced Debugging: Visible model filtering process with inclusion/exclusion lists
π License
This project is provided as-is for educational and development purposes.
π€ Contributing
Feel free to fork, modify, and improve this application. The modular structure makes it easy to:
- Add new AI providers
- Enhance the UI
- Improve environmental tracking
- Add new features
Made with π± for sustainable AI development