File size: 3,096 Bytes
d90fef6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# πŸ”§ Quick Fix for HuggingFace Deployment

## ❌ **Issue Identified**
The build failed due to **Pydantic v2 compatibility issues**:
- `BaseSettings` moved to `pydantic-settings` package
- `Config` class syntax changed to `model_config`
- `@validator` changed to `@field_validator`

## βœ… **Fixes Applied**

### 1. Updated requirements.txt
```diff
+ pydantic-settings
```

### 2. Fixed app/core/config.py
```diff
- from pydantic import BaseSettings, Field
+ from pydantic import Field
+ from pydantic_settings import BaseSettings

- class Config:
-     env_file = ".env"
-     case_sensitive = False
+ model_config = {
+     "env_file": ".env", 
+     "case_sensitive": False
+ }
```

### 3. Fixed app/models/schemas.py
```diff
- from pydantic import BaseModel, Field, validator
+ from pydantic import BaseModel, Field, field_validator, ConfigDict

- @validator('role')
- def validate_role(cls, v):
+ @field_validator('role')
+ @classmethod
+ def validate_role(cls, v):

- class Config:
-     json_schema_extra = {...}
+ model_config = ConfigDict(
+     json_schema_extra={...}
+ )
```

## πŸš€ **Quick Deployment Fix**

### Option 1: Update Your Existing Space
1. Go to your HuggingFace Space: https://huggingface.co/spaces/sematech/sema-chat
2. Click "Files" tab
3. Update these files with the fixed versions:
   - `requirements.txt`
   - `app/core/config.py` 
   - `app/models/schemas.py`

### Option 2: Re-run Setup Script
```bash
cd backend/sema-chat
./setup_huggingface.sh
```
Then push the updated files to your Space.

### Option 3: Manual Git Update
```bash
# Clone your space
git clone https://huggingface.co/spaces/sematech/sema-chat
cd sema-chat

# Copy fixed files
cp /path/to/sema/backend/sema-chat/requirements.txt .
cp /path/to/sema/backend/sema-chat/app/core/config.py app/core/
cp /path/to/sema/backend/sema-chat/app/models/schemas.py app/models/

# Commit and push
git add .
git commit -m "Fix Pydantic v2 compatibility issues

- Add pydantic-settings dependency
- Update BaseSettings import
- Fix Config class syntax
- Update validator decorators"
git push
```

## 🎯 **Environment Variables for Gemma**

Make sure these are set in your Space settings:
```
MODEL_TYPE=local
MODEL_NAME=google/gemma-2b-it
DEVICE=cpu
TEMPERATURE=0.7
MAX_NEW_TOKENS=256
DEBUG=false
ENVIRONMENT=production
```

**Alternative (API-based):**
```
MODEL_TYPE=google
MODEL_NAME=gemma-2-9b-it
GOOGLE_API_KEY=your_google_api_key_here
DEBUG=false
ENVIRONMENT=production
```

## πŸ§ͺ **Test After Fix**

Once the Space rebuilds successfully:
```bash
# Health check
curl https://sematech-sema-chat.hf.space/health

# Chat test
curl -X POST "https://sematech-sema-chat.hf.space/api/v1/chat" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello! Can you introduce yourself?", "session_id": "test"}'
```

## πŸ“‹ **Build Status**
- ❌ **Before**: Pydantic import errors
- βœ… **After**: Should build successfully with Pydantic v2

The fixes ensure compatibility with the latest Pydantic version while maintaining all functionality.

---

**Your Space should now deploy successfully! πŸš€**