Spaces:
Runtime error
Runtime error
Download scripts/predict_image.py from Aishrica/SmartPlate: direct link, hf CLI and curl.
- Browser
- Download file 764 Bytes
-
https://huggingface.co/spaces/Aishrica/SmartPlate/resolve/main/scripts/predict_image.py
- Command line
-
hf download hf://spaces/Aishrica/SmartPlate/scripts/predict_image.py
-
curl -L -o predict_image.py https://huggingface.co/spaces/Aishrica/SmartPlate/resolve/main/scripts/predict_image.py
764 Bytes
| import argparse | |
| from src.model_loader import load_food_classifier | |
| from src.nutrition import load_calorie_db | |
| from src.predict import predict_top_k | |
| from src.preprocessing import load_rgb_image | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description="Predict Indian food class for one image.") | |
| parser.add_argument("image", help="Path to an input image") | |
| parser.add_argument("--top-k", type=int, default=3, help="Number of predictions to show") | |
| args = parser.parse_args() | |
| processor, model = load_food_classifier() | |
| calorie_db = load_calorie_db() | |
| image = load_rgb_image(args.image) | |
| for item in predict_top_k(image, processor, model, calorie_db, top_k=args.top_k): | |
| print(item) | |
| if __name__ == "__main__": | |
| main() | |