Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
6.9.0
metadata
title: FoodClassifier-ViT
emoji: π
colorFrom: indigo
colorTo: pink
sdk: gradio
app_file: app.py
pinned: false
FoodViT - Food Classification Application
A production-ready food classification application using Vision Transformer (ViT) that can classify images into three categories: pizza, steak, and sushi.
π Features
- Web Interface: Beautiful Gradio web interface for easy image upload and classification
- Command Line Tool: Batch prediction capabilities for processing multiple images
- High Accuracy: Trained Vision Transformer model with excellent performance
- Production Ready: Modular, well-structured codebase with proper error handling
- Dynamic Example Images: Example images are randomly selected from
assets/samples/at each app launch - Easy Deployment: Simple setup and configuration
- Model weights hosted on Hugging Face Hub: The model file is not included in this repository; it is automatically downloaded from the Hugging Face Model Hub at runtime.
π Project Structure
FoodViT/
βββ app.py # Main application entry point
βββ predict.py # Command-line prediction script
βββ config.py # Configuration settings
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ INSTALLATION.md # Installation and troubleshooting guide
βββ utils/
β βββ model_loader.py # Model loading utilities
β βββ image_processor.py # Image preprocessing
β βββ predictor.py # Prediction logic
βββ interface/
β βββ gradio_app.py # Gradio web interface
βββ assets/
βββ samples/ # Example images for Gradio interface
π Quick Start
1. Installation
# Clone the repository
git clone <repository-url>
cd FoodViT
# Install dependencies
pip install -r requirements.txt
2. Run the Web Interface
# Start the Gradio web interface
python app.py
The interface will be available at http://localhost:7860
3. Command Line Usage
# Predict a single image
python predict.py path/to/image.jpg
# Predict all images in a directory
python predict.py path/to/image/directory
# Get detailed prediction information
python predict.py path/to/image.jpg --detailed
# Save results to JSON file
python predict.py path/to/image/directory --output results.json
π― Usage Examples
Web Interface
- Open your browser and go to
http://localhost:7860 - Upload an image of pizza, steak, or sushi
- View the prediction results with confidence scores
- Try the example images provided (randomly selected from
assets/samples/)
Command Line
# Single image prediction
python predict.py pizza.jpg
# Output: β
pizza.jpg: Pizza (95.23%)
# Batch prediction with details
python predict.py test_images/ --detailed --output results.json
βοΈ Configuration
Edit config.py to customize:
- Model settings: Model path, device, image size
- Class configuration: Class names and mappings
- Gradio interface: Title, description, theme
- Application settings: Host, port, debug mode
π§ Advanced Usage
Custom Model Loading
from utils.model_loader import ModelLoader
# Load custom model
loader = ModelLoader()
loader.load_model()
model = loader.get_model()
Image Preprocessing
from utils.image_processor import ImageProcessor
# Preprocess custom image
processor = ImageProcessor()
tensor = processor.preprocess_image("path/to/image.jpg")
Direct Prediction
from utils.predictor import FoodPredictor
# Initialize and predict
predictor = FoodPredictor()
predictor.initialize()
result = predictor.predict("path/to/image.jpg")
print(f"Predicted: {result['class']} ({result['confidence']:.2%})")
π Model Information
- Architecture: Vision Transformer (ViT-Base)
- Input Size: 224x224 pixels
- Classes: 3 (pizza, steak, sushi)
- Training Data: Pizza-Steak-Sushi dataset
- Framework: PyTorch with Transformers
- Model weights: Downloaded automatically from the Hugging Face Model Hub (see model repo)
π οΈ Development
Project Structure
utils/: Core utilities for model loading, image processing, and predictioninterface/: Web interface componentsassets/samples/: Example images and static assets
Adding New Features
- New Model: Update
config.pyandutils/model_loader.py - New Classes: Modify
config.pyCLASS_CONFIG - New Interface: Create new files in
interface/ - New Utilities: Add to
utils/directory
π§Ή Project Cleanliness & GitHub Readiness
- All unnecessary files and caches have been removed
- Example images are dynamically loaded
- No test or debug files in the repo
- Model weights are not included in the repo (downloaded from the Hub)
- Ready for production and version control
π Troubleshooting
See INSTALLATION.md for detailed troubleshooting, dependency, and environment tips.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
π Support
For questions and support:
- Open an issue on GitHub
- Check the troubleshooting section
- Review the configuration options
Enjoy classifying your food images! ππ₯©π£