File size: 6,118 Bytes
d80bf0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# πŸš€ Deployment Guide for Hugging Face Spaces

This guide explains how to deploy the updated Wildberries Analytics Dashboard to Hugging Face Spaces.

## πŸ“‹ Prerequisites

- Hugging Face account
- Wildberries API token (optional for demo mode)
- Git installed locally

## πŸ› οΈ Step-by-Step Deployment

### 1. Create a New Space

1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click **"Create new Space"**
3. Configure your space:
   - **Space name**: `wildberries-analytics` (or your preferred name)
   - **License**: MIT
   - **SDK**: **Gradio**
   - **Hardware**: CPU Basic (free tier)
   - **Visibility**: Public or Private

### 2. Clone Your Space

```bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/wildberries-analytics
cd wildberries-analytics
```

### 3. Add Project Files

Copy all the updated project files to your space directory:

```
wildberries-analytics/
β”œβ”€β”€ app.py                    # Main application
β”œβ”€β”€ requirements.txt          # Dependencies
β”œβ”€β”€ README.md                 # Space documentation
β”œβ”€β”€ config.py                 # Configuration management
β”œβ”€β”€ wildberries_client.py     # API client
β”œβ”€β”€ forecasting.py            # Forecasting algorithms
β”œβ”€β”€ dashboard.py              # Visualization components
β”œβ”€β”€ utils.py                  # Utilities and demo data
β”œβ”€β”€ .gitignore               # Git ignore patterns
└── examples/
    └── sample_data.json     # Sample data for demo
```

### 4. Configure Environment Variables (Optional)

If you have a Wildberries API token:

1. Go to your Space page
2. Click **Settings** tab
3. Scroll to **Repository secrets**
4. Add a new secret:
   - **Name**: `WILDBERRIES_API_TOKEN`
   - **Value**: Your Wildberries API token

### 5. Commit and Push

```bash
git add .
git commit -m "Initial deployment of Wildberries Analytics Dashboard"
git push
```

### 6. Wait for Build

- Hugging Face will automatically build your space
- Check the **Logs** tab to monitor the build process
- Build typically takes 2-5 minutes

## βš™οΈ Configuration Options

### Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `WILDBERRIES_API_TOKEN` | No | Your Wildberries API token for real data |
| `DEBUG` | No | Set to `true` for debug mode |
| `GRADIO_THEME` | No | Gradio theme (`soft`, `default`, etc.) |

### Wildberries API Token Setup

1. **Get your token**:
   - Log into your Wildberries seller account
   - Go to Settings β†’ Access to API
   - Generate token with permissions:
     - βœ… Analytics
     - βœ… Statistics
     - βœ… Marketplace

2. **Token permissions needed**:
   ```
   Bit 2: Access to Analytics
   Bit 5: Access to Statistics
   Bit 4: Access to Marketplace
   ```

## πŸ”§ Customization

### Changing the Theme

Edit `app.py` line with `gr.themes.Soft()`:

```python
# Available themes:
gr.themes.Default()
gr.themes.Soft()
gr.themes.Monochrome()
gr.themes.Glass()
```

### Adding More Languages

Update the `README.md` metadata:

```yaml
language:
- en
- ru
```

### Custom Domain (Pro Feature)

For custom domains, upgrade to a Pro space and configure in Settings.

## 🚨 Troubleshooting

### Common Issues

**1. Build Fails with Dependencies**
```bash
# Check requirements.txt for version conflicts
# Pin specific versions if needed
gradio==5.7.1
pandas>=2.0.3
```

**2. Import Errors**
```python
# Ensure all modules are in the same directory
# Check for typos in import statements
```

**3. API Connection Issues**
- Verify token is correctly set in Spaces secrets
- Check token permissions in Wildberries dashboard
- Review API rate limits (300 requests/minute)

**4. Demo Mode Not Working**
- Check if `utils.py` contains demo data functions
- Verify `examples/sample_data.json` exists

### Checking Logs

1. Go to your Space page
2. Click **Settings** tab
3. View **Container logs** for detailed error messages

### Performance Optimization

**For better performance**:
1. Upgrade to CPU Upgrade hardware ($0.03/hour)
2. Use persistent storage for data caching
3. Optimize data processing in batch operations

## πŸ“Š Monitoring Usage

### Space Analytics

- View usage statistics in Space settings
- Monitor monthly compute costs
- Track user interactions

### API Rate Limiting

The dashboard automatically handles Wildberries API rate limits:
- 300 requests per minute maximum
- Exponential backoff on 429 errors
- Graceful fallback to demo mode

## πŸ”„ Updates and Maintenance

### Updating the Application

1. Make changes locally
2. Test with demo mode
3. Commit and push to update Space:

```bash
git add .
git commit -m "Update: description of changes"
git push
```

### Monitoring API Changes

- Subscribe to Wildberries API updates
- Test regularly with your API token
- Update error handling as needed

## πŸ†˜ Support

### Getting Help

1. **Hugging Face Community**: [discuss.huggingface.co](https://discuss.huggingface.co)
2. **Gradio Documentation**: [gradio.app/docs](https://gradio.app/docs)
3. **Wildberries API Docs**: [dev.wildberries.ru](https://dev.wildberries.ru/en/openapi/api-information)

### Community Resources

- Example Spaces: Browse similar analytics dashboards
- Gradio Components: Explore advanced UI components
- API Integration Patterns: Study other marketplace integrations

## πŸ“ˆ Advanced Features

### Adding More Marketplaces

Extend the dashboard to support additional marketplaces:

1. Create new API client modules
2. Update configuration for multiple tokens
3. Add marketplace selection in UI

### Data Persistence

For storing historical data:

1. Upgrade to persistent storage
2. Implement database integration
3. Add data export features

### Real-time Updates

For live dashboard updates:

1. Implement WebSocket connections
2. Add auto-refresh functionality
3. Use Gradio's live update features

---

**πŸŽ‰ Congratulations!** Your Wildberries Analytics Dashboard is now live on Hugging Face Spaces!

Visit your space URL to start analyzing your marketplace data: `https://huggingface.co/spaces/YOUR_USERNAME/wildberries-analytics`