This project is a web application that predicts financial returns based on input CSV files. It consists of a FastAPI-based backend for predictions and a Streamlit-based frontend for user interaction. The service uses a pre-trained XGBoost model to make predictions.
- User-friendly Streamlit frontend for uploading CSV files and viewing results.
- FastAPI backend for handling prediction requests.
- Upload a CSV file containing financial data.
- Validate the CSV file for required columns.
- Predict financial returns using the XGBoost model.
- Return predictions in JSON format.
- Python 3.10+
- FastAPI
- Streamlit
- Pandas
- XGBoost
-
Clone the repository:
git clone https://github.com/ReynardL/Bankruptcy-predictor.git cd Bankruptcy-predictor -
Install the required packages:
uv sync
docker-compose upThis will start both the FastAPI backend and the Streamlit frontend.
uvicorn App.main:app --reloadIf you want to start the frontend manually, run:
streamlit run app.pyAfter starting, open your browser and navigate to http://localhost:8501 to use the web interface, or to http://127.0.0.1:8000 to see the FastAPI welcome message.
You can use the /predict endpoint to upload a CSV file and get predictions via API, or use the Streamlit frontend for a graphical interface.
You can access the deployed website at:
https://app-978501737888.us-central1.run.app/
GET /: Returns a welcome message.POST /predict: Accepts a CSV file and returns predictions.- API Documentation
The CSV file should contain the following columns:
- Quick Ratio
- Fixed Assets to Assets
- Interest-bearing debt interest rate
- Total debt/Total net worth
- Borrowing dependency
- ROA(C) before interest and depreciation before interest
- Continuous Net Profit Growth Rate
- Research and development expense rate
- Allocation rate per person
- Revenue per person
- Cash/Current Liability
- Accounts Receivable Turnover
- Quick Assets/Total Assets
- Total income/Total expense
- Net Value Per Share (B)
- Cash Flow to Equity
- Non-industry income and expenditure/revenue
- After-tax Net Profit Growth Rate
- Inventory Turnover Rate (times)
- Total expense/Assets
- Net Value Growth Rate
- Operating Expense Rate
- Total Asset Growth Rate
- Cash Turnover Rate
- Current Liabilities/Liability
- Interest Expense Ratio
- Operating Profit Growth Rate
- Long-term fund suitability ratio (A)
- Cash Flow Per Share
- Average Collection Days
- Target users: Banks giving out loans, investors.
- Expected daily request volume: 5 requests per day.
- User requirements: Batch processing.
Below is a text diagram explaining how someone interacts with the API service:
- User uploads a CSV file to the FastAPI server via the
/predictendpoint. - FastAPI Server receives the CSV file and validates it for the required columns.
- If the CSV file is valid, the FastAPI Server inputs the data to the XGBoost Model for prediction.
- The XGBoost Model returns the predictions to the FastAPI Server.
- The FastAPI Server sends the predictions back to the User in JSON format.
- Response time:
- ~10s between sending API request and receiving predictions (with cold start).
- ~0.1s between sending API request and receiving predictions (no cold start).
- Memory consumption:
- Minimum: 0
- Maximum: 43% of 512 = 224MB
- Cloud monitoring dashboards:
- Number of expected requests: ~5 daily