Bihari04/pet-poultry-disease-classifier
Pet Poultry Disease Classifier
This Hugging Face Space serves a trained PyTorch image classifier for pet and poultry disease detection.
What is in this folder
app.py- Flask backend and model loading logicbest_model.pth- trained checkpoint used for inferenceDockerfile- container build for Hugging Face Spacesrequirements.txt- runtime dependenciestemplates/index.html- frontend pagestatic/css/style-a.css- page stylesstatic/js/app-a.js- frontend interactivity.dockerignore- keeps the Docker build context small
What should be pushed
Push these to the Hugging Face Space repo and, if you want a backup copy, to GitHub too:
app.pyDockerfilerequirements.txtREADME.mdbest_model.pthtemplates/static/.dockerignore.gitattributes
What should not be pushed
Do not upload training-only or local-machine files to the Space:
.venv/__pycache__/- raw training datasets
- notebooks that are only for experimentation
- temporary logs, checkpoints, or export folders you do not use for inference
- local secrets, passwords, or tokens
One-time Hugging Face setup
- Create an account at https://huggingface.co/join
- Create a new Space
- Choose
Dockeras the SDK - Set the Space name you want, for example
pet-poultry-disease-classifier - Create a Write token at https://huggingface.co/settings/tokens
If you use Git from the terminal, log in once:
hf auth loginIf hf is not on PATH, run the full path to hf.exe or add the Hugging Face scripts folder to PATH.
Git remotes
This project can push to two places:
origin-> GitHubhf-> Hugging Face Space
Check them with:
git remote -vIf hf is missing, add it once:
git remote add hf https://huggingface.co/spaces/Bihari04/pet-poultry-disease-classifierNormal update workflow
When you change frontend, backend, or model code:
- Edit files in this
hf-spacefolder. - Verify the repo is clean enough to commit:
git status- Commit your changes:
git add .
git commit -m "Update Space"- Push to GitHub if you want to keep a backup copy there:
git push origin main- Push to Hugging Face so the live Space rebuilds:
git push hf mainIf the Space has changes on Hugging Face already
If Hugging Face rejects the push because the remote has new commits, sync first:
git pull hf main --rebase --allow-unrelated-histories
git push hf mainIf there are merge conflicts, resolve them, run git add ., then continue the rebase:
git rebase --continueDeployment steps
- Create or open the Hugging Face Space.
- Upload or push the contents of this folder.
- Make sure
best_model.pthis present in the Space repo. - Wait for the Docker build to finish.
- Open the Logs tab if the build fails.
- Refresh the App tab after the build succeeds.
If you change the model
If you retrain the model and get a new checkpoint, replace best_model.pth with the new file and push again.
This project is already configured to load the checkpoint directly, so no extra training code is needed in the Space.
Runtime settings
MODEL_PATH- Optional local path to the checkpoint inside the SpaceHF_MODEL_REPO- Repository to downloadbest_model.pthfrom when the local file is missingHF_MODEL_FILENAME- Model filename to download from the Hub. Defaults tobest_model.pth
Important note
The checkpoint must contain both model_state_dict and class_to_idx. The training script in this project already saves those keys, so the deployed model must come from that checkpoint format.
Troubleshooting
Authorization errorwhile pushing to Hugging Face usually means the token is missing or stale.non-fast-forwardmeans the Hugging Face remote has commits your local branch does not have. Pull with rebase first.No module named srcshould not happen in the current setup because the Space app no longer depends on a separatesrcpackage.- If the app fails to load images or static assets, verify that
templates/index.htmlandstatic/are still in the repo.
Suggested file layout
hf-space/
├─ app.py
├─ best_model.pth
├─ Dockerfile
├─ README.md
├─ requirements.txt
├─ .dockerignore
├─ .gitattributes
├─ static/
│ ├─ css/
│ │ └─ style-a.css
│ └─ js/
│ └─ app-a.js
└─ templates/
└─ index.htmlHugging Face Spaces reference
See the official configuration docs at https://huggingface.co/docs/hub/spaces-config-reference
