File size: 4,660 Bytes
21446aa
0c5e4ac
 
4cf6c84
21446aa
 
0c5e4ac
 
 
21446aa
 
0c5e4ac
21446aa
5828539
21446aa
5828539
21446aa
5828539
 
 
 
 
 
 
21446aa
5828539
21446aa
5828539
 
 
 
 
 
21446aa
5828539
21446aa
5828539
21446aa
5828539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21446aa
5828539
 
 
 
 
 
21446aa
 
5828539
21446aa
5828539
21446aa
5828539
21446aa
5828539
21446aa
 
5828539
 
 
 
 
 
 
 
 
 
 
 
 
21446aa
 
 
5828539
21446aa
 
5828539
 
 
 
 
 
 
 
 
21446aa
 
 
5828539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: Cooking Tutor
emoji: 👨‍🍳
colorFrom: yellow
colorTo: red
sdk: docker
sdk_version: latest
license: apache-2.0
short_description: CookTut with WebSearch, Memory, Multilingual
---

# Cooking Tutor Backend

An intelligent cooking assistant that provides personalized recipe guidance, cooking techniques, and culinary tips with multilingual support (English, Vietnamese, Chinese).

## 🚀 Features

- **Smart Recipe Recommendations**: Get personalized recipes based on available ingredients
- **Multilingual Support**: English, Vietnamese (Tiếng Việt), and Chinese (中文)
- **Cooking Techniques**: Step-by-step guidance for various cooking methods
- **Ingredient Substitutions**: Smart suggestions for ingredient alternatives
- **Dietary Accommodations**: Support for various dietary preferences and restrictions
- **Web Search Integration**: Real-time cooking information from trusted sources
- **Memory System**: Contextual conversation continuity

## 🛠️ Technical Stack

- **Backend**: FastAPI with Python 3.9+
- **AI Models**: Google Gemini Flash API
- **Memory**: FAISS + Sentence Transformers for semantic search
- **Translation**: HuggingFace Transformers (VietAI/envit5-translation, Helsinki-NLP/opus-mt-zh-en)
- **Web Search**: DuckDuckGo + specialized cooking engines
- **Deployment**: Docker container on HuggingFace Spaces

## 🏃‍♂️ Quick Start

The API is automatically deployed and running on HuggingFace Spaces. You can interact with it through the web interface or API endpoints.

### API Endpoints

- `GET /` - Health check
- `POST /chat` - Main chat endpoint
- `GET /health` - System health status

### Example Usage

```python
import requests

# Chat with the cooking tutor
response = requests.post("https://your-space-url.hf.space/chat", json={
    "user_id": "user123",
    "query": "How do I make perfect pasta?",
    "lang": "EN"
})

print(response.json())
```

## 🌍 Multilingual Support

The cooking tutor supports three languages:

- **English (EN)**: Full feature support
- **Vietnamese (VI)**: Complete Vietnamese language support
- **Chinese (ZH)**: Simplified Chinese support

## 🔧 Environment Variables

Required environment variables for deployment:

```bash
FlashAPI=your_gemini_api_key
```

## 📚 API Documentation

### Chat Endpoint

**POST** `/chat`

Request body:
```json
{
    "user_id": "string",
    "query": "string",
    "lang": "EN|VI|ZH",
    "search_mode": true,
    "video_mode": false,
    "servings": 4,
    "dietary": ["vegetarian"],
    "allergens": ["nuts"],
    "equipment": ["oven", "stovetop"],
    "time_limit_minutes": 30,
    "skill_level": "beginner|intermediate|advanced",
    "cuisine": "italian",
    "structured": false
}
```

Response:
```json
{
    "response": "string",
    "videos": [
        {
            "title": "string",
            "url": "string",
            "thumbnail": "string",
            "source": "string"
        }
    ]
}
```

## 🏗️ Architecture

```
┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   Frontend      │    │   FastAPI        │    │   AI Models     │
│   (Vercel)      │◄──►│   Backend        │◄──►│   (Gemini)      │
└─────────────────┘    └──────────────────┘    └─────────────────┘


                       ┌──────────────────┐
                       │   Search &       │
                       │   Memory         │
                       │   Systems        │
                       └──────────────────┘
```

## 🔍 Search & Memory

- **Web Search**: Real-time cooking information from multiple sources
- **Memory Management**: Short-term and long-term memory for conversation context
- **Content Processing**: Advanced content extraction and summarization
- **Citation System**: Proper source attribution with inline citations

## 🚀 Deployment

This space is configured for Docker deployment on HuggingFace Spaces:

- **Port**: 7860
- **Base Image**: Python 3.9
- **Auto-deploy**: Enabled on push to main branch

## 📄 License

MIT License - see LICENSE file for details.

## 🤝 Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

## 📞 Support

For support or questions, please open an issue in the repository.