A Streamlit application that automates tip allocation and cash distribution for service teams using OCR (Optical Character Recognition) to process partner hours from PDFs or images.
-
Dual AI Provider Support:
- Mistral AI for both PDF and Image OCR
- Gemini AI for Image OCR
-
Multiple Document Types:
- PDF documents (Mistral only)
- Images (JPG, JPEG, PNG)
-
Flexible Input Methods:
- URL input for online documents
- Local file upload
-
Tip Distribution Functions:
- Extract partner hours from documents
- Calculate tip allocation based on hours worked
- Distribute bills equitably among partners
- Track distribution history
- Generate copy-paste ready outputs
-
Hour Processing:
- Process partner hours from PDF/image input
- Sum total hours worked
-
Tip Allocation:
- Calculate individual tips using the formula: (Individual Hours ÷ Total Hours) × Total Tips
- Apply strict downward rounding (e.g., $58.99 → $58)
-
Bill Distribution:
- Distribute available bills [$20, $10, $5, $1] equitably
- Rotate starting partner weekly to ensure fairness
- Prevent denomination bias
-
Output Format:
- Partner Name | # | Hours | Tip Amount | Bills
- Example: Alex | #3 | 38h | $224 | 4x$20,2x$10,4x$1
- Clone the repository:
git clone <repository-url>
cd <repository-directory>- Create and activate a virtual environment:
python -m venv venv
# On Windows
venv\Scripts\activate
# On Unix or MacOS
source venv/bin/activate- Install the required packages:
pip install -r requirements.txt- Configure API keys:
# Copy the sample environment file
cp sample.env .env
# Edit the .env file with your actual API keys
# On Windows
notepad .env
# On Unix/MacOS
nano .env- Mistral AI: Get your API key from Mistral AI Console
- Gemini AI: Get your API key from Google AI Studio
Add your API keys to the .env file:
MISTRAL_API_KEY=your_mistral_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
- Run the Streamlit app:
streamlit run main.py-
Select your preferred AI provider (Mistral or Gemini)
-
Choose document type (PDF/Image) and source type (URL/Local Upload)
-
Process your document to extract partner hours
-
Enter the total tip amount and calculate the tip distribution
-
View and save your results
For a total of $875 in tips for 148 hours worked:
- Partner 1 (40h → $236.48 → $236)
- Partner 2 (32h → $189.19 → $189)
- Partner 3 (38h → $224.65 → $224)
- Partner 4 (38h → $224.65 → $224)
With week 3 rotation starting with the last partner, the output might look like:
- Alex | #3 | 38h | $224 | 4x$20,2x$10,4x$1
-
Mistral OCR:
- Supports both PDF and image processing
- Maintains document structure and formatting
- Works with both local files and URLs
-
Gemini Vision:
- Specialized in image processing
- Provides detailed text extraction with context
- Currently does not support PDFs
- AI-assisted extraction of names and hours
- Manual data entry option for corrections
- Mathematically fair distribution based on hours worked
- Strict downward rounding to ensure no overpayment
- Equitable distribution of bills
- Weekly rotation to ensure fairness over time
- Tracking of distribution history
This application uses a .env file to securely store your API keys. The file is:
- Excluded from version control via
.gitignore - Loaded at runtime using
python-dotenv - Only accessible within the application
If you need to update your API keys, simply edit the .env file - no need to modify the code.
- Gemini AI does not currently support PDF processing
- PDF preview may require browser PDF plugin support
- Maximum file size limits apply based on the AI provider's restrictions
- OCR accuracy depends on document quality and formatting
If you encounter issues:
-
API Key Configuration:
- Ensure you've created a
.envfile with the correct API keys - Check for any typos in your API keys
- Verify that your API keys are still valid and not expired
- Ensure you've created a
-
PDF Preview Not Working:
- Ensure your browser supports PDF viewing
- Try using a different browser
- Check if the PDF URL is accessible
-
OCR Not Working:
- Verify your API key is correct
- Check if the document is in a supported format
- Ensure the document is readable and not corrupted
-
Partner Data Extraction Issues:
- Try using the manual data entry option
- Check if names and hours are clearly visible in the document
- Improve document quality if possible
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.