The application is organized as a FastAPI service that serves both the static interface and analysis responses. This keeps the user flow and inference in one deployment and avoids placing language-provider credentials in the browser. The input contract limits messages to 800 characters and rejects empty entries. A lexical check requires a recognizable reference to Bitcoin or the crypto market before analysis begins.
Text preparation lowercases the input, removes links, mentions, and ticker symbols, preserves useful punctuation, and reduces repeated characters and whitespace. Consistent cleaning matters because the classifier works on a representation derived from text, not on market variables. Sentence Transformers generates the semantic embedding; LightGBM classifiers operate on that representation. Instead of one multiclass label, inference chains two ensembles. If the negative-class probability is below its threshold, the result is “Do not invest”; if it reaches the threshold, the neutral ensemble is evaluated. In that second stage, a neutral probability equal to or above its threshold yields “Invest”; otherwise the result is also “Do not invest.”
The explanation is a layer after classification; it does not determine the orientation. When OpenAI is configured, it receives the original text as untrusted data together with the model label and is instructed to explain the result without inventing probabilities or promising returns. If the call fails or no key is available, the system generates a local explanation. This means the external provider does not have to be available for the user to receive a result. The response also makes the uncertainty of the analysis clear.
For packaging, Docker prepares the model artifacts and embedding model during the build, and the service loads them in offline mode at startup. A single worker is used to limit duplicated model memory. FastAPI exposes health checks; the application also includes a request limit, security headers, and a generic response to internal errors. These decisions address operational concerns and credential protection.
The project also preserves a separate binary sentiment-classification iteration—positive or negative—with another API flow and threshold tuning on validation data. It is distinct from the sequential web application, and its results do not describe the latter’s performance.