File size: 2,698 Bytes
581ef41
 
 
 
 
 
8937d8e
581ef41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---

title: Food Recognition API
emoji: πŸ•
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
license: mit
short_description: FastAPI food recognition service
---


# πŸ• Food Recognition API

A FastAPI web service that uses a Vision Transformer model to recognize 10 different types of food from images.

## 🎯 Features

- **FastAPI Backend** - RESTful API with comprehensive endpoints
- **Gradio Interface** - User-friendly web interface
- **Vision Transformer** - State-of-the-art image classification
- **Real-time Predictions** - Instant food recognition
- **Multiple Input Methods** - File upload and base64 support

## 🍽️ Supported Food Types

1. Apple Pie
2. Caesar Salad  
3. Chocolate Cake
4. Cup Cakes
5. Donuts
6. Hamburger
7. Ice Cream
8. Pancakes
9. Pizza
10. Waffles

## πŸ“‘ API Endpoints

- **`/`** - Gradio web interface
- **`/health`** - Health check and model status
- **`/classes`** - Get supported food classes
- **`/model-info`** - Detailed model information
- **`/docs`** - Interactive API documentation

## πŸš€ Usage

### Web Interface
Simply upload an image using the Gradio interface above!

### API Usage
```python

import requests



# Upload image file

with open('food_image.jpg', 'rb') as f:

    files = {'file': f}

    response = requests.post('https://your-space-url.hf.space/predict', files=files)

    result = response.json()

    print(result)

```

### Health Check
```bash

curl https://your-space-url.hf.space/health

```

## πŸ“Š Model Performance

- **Accuracy**: 68%
- **F1 Score**: 66.5%
- **Architecture**: Vision Transformer (ViT-Base)
- **Training Data**: Custom food dataset
- **Classes**: 10 food categories

## πŸ”§ Technical Details

- **Framework**: FastAPI + Gradio
- **Model**: Hugging Face Transformers
- **Backend**: PyTorch
- **Deployment**: Hugging Face Spaces

## πŸ“ Model Information

- **Model ID**: `BinhQuocNguyen/food-recognition-vit`
- **Model URL**: https://huggingface.co/BinhQuocNguyen/food-recognition-vit
- **Training Time**: ~84 minutes
- **Image Size**: 224x224 pixels

## πŸ› οΈ Local Development

```bash

# Clone the repository

git clone https://github.com/your-username/food-recognition-api



# Install dependencies

pip install -r requirements_spaces.txt



# Run locally

python app.py

```

## πŸ“„ License

MIT License - Feel free to use and modify for your projects.

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## πŸ“ž Support

If you encounter any issues or have questions, please open an issue on the repository.