Farhannr28/code-authorship-demo-space
Code Authorship Attribution
Standalone Gradio deployment of the thesis Phase-B model. It provides a technical UI and named /preprocess and /infer Gradio endpoints.
Configuration
Set these Space variables/secrets before startup:
MODEL_REPO_ID: private Hugging Face Model repository ID.MODEL_REVISION: immutable commit SHA for that model repository.HF_TOKEN: read token with access to the private repository, stored as a Space secret.
The runtime downloads the selected snapshot through huggingface_hub and uses its normal cache. The two public base encoders are resolved from the adapter metadata. For a reproducible production deployment, each encoder entry in the model manifest should also provide its training-time base_revision. No submitted source is written to disk or logged.
The NLTK resources punkt_tab and averaged_perceptron_tagger_eng are downloaded to /tmp/nltk_data once when missing. The model, calibration, UMAP reducers, and visualization arrays are loaded once per application process.
Local development
From this directory:
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements-dev.txt
cp .env.example .env
python app.pyExport the three values from .env into the process environment before starting the app. The application does not parse .env itself.
Run focused tests with:
python3 -m pytest -qSet MODEL_ARTIFACT_DIR to a local exported snapshot to enable the artifact integration test. Full prediction parity requires golden outputs produced with the selected private checkpoint.
Deployment
Use this directory as the root of the Gradio Space and select ZeroGPU in the Space hardware settings. Private repositories cannot use the Space preload_from_hub build option, so the snapshot is fetched during application startup.
The /infer result keeps calibrated probabilities, threshold-adjusted scores, and the final Human-Shield-aware decision separate. Its UMAP coordinates are for visualization only; ArcFace cosines and logits are computed in 768 dimensions.
