TariffDoc AI is a Streamlit-based application that streamlines tariff documentation for global manufacturing. It allows users to input a part number or product description, fetch relevant tariff information from the USITC Harmonized Tariff Schedule, and generate a downloadable PDF document for compliance purposes.
- Tariff Intelligence Assistant: Search for HTS codes based on product descriptions
- LLM-Enhanced Search: Improve search accuracy with AI-powered query enhancement
- Trade Agreement Analysis: Identify eligibility for trade agreements and potential duty savings
- Document Generation: Create professional, compliance-ready PDF documents
- Expert Analysis: Get AI-generated explanations of tariff implications
- Python 3.8 or higher
- pip (Python package installer)
-
Clone or download this repository to your local machine.
-
Navigate to the project directory:
cd TIA -
Install the required dependencies:
pip install -r requirements.txtNote: If you encounter compatibility issues between NumPy and Pandas (such as
ValueError: numpy.dtype size changed, may indicate binary incompatibility), use the provided reinstallation scripts:- On Windows: Run
.\reinstall_dependencies.bat(PowerShell) orreinstall_dependencies.bat(Command Prompt) - On Unix-based systems: Run
./reinstall_dependencies.sh
- On Windows: Run
-
(Optional) Set up OpenAI API for enhanced features:
- Copy the
.env.examplefile to.env:copy .env.example .env - Edit the
.envfile and add your OpenAI API key:OPENAI_API_KEY=your_api_key_here
- Copy the
-
Start the Streamlit application:
- On Windows (PowerShell):
.\run_app.bat - On Windows (Command Prompt):
run_app.bat - On Unix-based systems:
./run_app.sh - Or directly with Streamlit:
streamlit run app.py
- On Windows (PowerShell):
-
Open your web browser and navigate to the URL displayed in the terminal (typically http://localhost:8501).
-
Use the application:
- Enter a product description in the Search tab
- Select the country of origin and destination country
- Click "Search for HTS Codes" to find matching tariff classifications
- In the Results tab, select an HTS code and click "Generate Document"
- In the Document tab, view the tariff information and download the PDF
TIA/
├── app.py # Main Streamlit application
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── .env.example # Example environment variables
├── README.md # Project documentation
├── run_app.bat # Windows run script
├── run_app.sh # Unix run script
├── reinstall_dependencies.bat # Windows dependency reinstall script
├── reinstall_dependencies.sh # Unix dependency reinstall script
├── utils/
│ ├── api_client.py # USITC API client
│ ├── llm_service.py # LLM integration
│ ├── pdf_generator.py # PDF generation
│ └── product_analyzer.py # Product analysis logic
├── data/
│ ├── country_codes.json # Country information
│ └── trade_agreements.json # Trade agreement data
└── assets/
└── multifactor_logo.png # Multifactor logo for branding
This application integrates with the USITC Harmonized Tariff Schedule API to retrieve tariff information. The API is used to:
- Search for HTS codes based on product descriptions
- Retrieve detailed information about specific HTS codes
- Determine trade agreement eligibility
When configured with an OpenAI API key, the application uses AI to enhance functionality:
- Improve search queries by generating industry-specific terminology
- Analyze confidence levels for HTS code matches
- Generate plain-language explanations of tariff implications
If you encounter an error like:
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
This indicates a compatibility issue between NumPy and Pandas. To resolve:
-
Use the provided reinstallation scripts:
- On Windows (PowerShell): Run
.\reinstall_dependencies.bat - On Windows (Command Prompt): Run
reinstall_dependencies.bat - On Unix-based systems: Run
./reinstall_dependencies.sh
- On Windows (PowerShell): Run
-
Or manually reinstall the packages with compatible versions:
pip uninstall -y numpy pandas pip install numpy==1.23.5 pandas==1.5.3
If you're using PowerShell and get an error like:
The term 'run_app.bat' is not recognized as the name of a cmdlet, function, script file, or executable program.
Use the .\ prefix to run scripts in the current directory:
.\run_app.bat
If LLM features are not working:
- Verify your API key is correctly set in the
.envfile - Check your OpenAI account has sufficient credits
- Ensure your internet connection allows access to the OpenAI API
This is a proof-of-concept application with the following limitations:
- The USITC API integration is simplified and may not capture all nuances of the actual API
- Trade agreement eligibility is determined using basic rules and may not reflect all requirements
- The application focuses on US imports (with the US as the destination country)
- PDF generation uses a basic template that may need customization for production use
Potential enhancements for future versions:
- Integration with additional tariff databases (TARIC, etc.)
- Support for Bill of Materials (BOM) uploads
- Tariff-minimization advisor functionality
- Real-time regulatory monitoring
- Enhanced audit trail and export history
This project is proprietary software developed for Multifactor AI.
- USITC for providing the Harmonized Tariff Schedule data
- Streamlit for the web application framework
- OpenAI for the language model capabilities