File size: 4,883 Bytes
c922f8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Hugging Face Deployment Guide for GAIA Agent

This guide provides detailed instructions for deploying the GAIA agent to Hugging Face Spaces. It covers cleaning the existing space, preparing the deployment package, uploading to Hugging Face, and verifying the deployment.

## Prerequisites

Before you begin, make sure you have the following:

1. A Hugging Face account
2. The Hugging Face CLI installed and configured
3. Access to the GAIA project repository
4. Python 3.8+ installed

## Installation of Required Tools

Install the Hugging Face CLI tool:

```bash
pip install huggingface_hub
```

Login to Hugging Face:

```bash
huggingface-cli login
```

## Deployment Process

### Step 1: Prepare the Deployment Package

The `prepare_hf_deployment.py` script helps you create a clean deployment package with only the necessary files. You can run it with different options depending on your needs.

#### List Files That Would Be Included

To see which files would be included in the deployment package without actually creating it:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --list-only
```

#### Create a Deployment Package

To create a deployment package (ZIP file) with all essential files:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package
```

By default, this will create a package in a `deployment` directory. You can customize the output directory and package name:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package --output-dir custom_dir --package-name custom_package.zip
```

### Step 2: Clean the Existing Hugging Face Space

Before uploading new files, you can clean the existing space to remove old files:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --clean-remote
```

This will prompt for confirmation before deleting files. Use the `--force` flag to skip confirmation:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --clean-remote --force
```

### Step 3: Upload to Hugging Face

To upload the prepared package to Hugging Face:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --upload
```

You need to create a package first. You can combine the steps:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package --upload
```

Or perform the complete deployment process in one command:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package --clean-remote --upload
```

### Step 4: Verify the Deployment

After uploading, verify that the deployment was successful:

1. Visit your Hugging Face Space at `https://huggingface.co/spaces/JoachimVC/Final_Assignment_GAIAAgent`
2. Check that the app loads correctly and all essential functionality works
3. Test the main features to ensure they're working as expected

## Customizing File Selection

The script uses default inclusion and exclusion patterns, but you can customize them.

### Using Custom Pattern Files

Create a file with patterns of files to include:

```
# include_patterns.txt
src/gaia/agent/**/*.py
src/gaia/config/**/*.py
src/gaia/tools/**/*.py
```

Create a file with patterns of files to exclude:

```
# exclude_patterns.txt
**/__pycache__/**
**/*.log
```

Then use these files with the script:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package --include-file include_patterns.txt --exclude-file exclude_patterns.txt
```

## Deployment to a Different Space

By default, the script deploys to the `JoachimVC/Final_Assignment_GAIAAgent` space. To deploy to a different space:

```bash
python src/gaia/scripts/prepare_hf_deployment.py --create-package --upload --space-id your-username/your-space-name
```

## Troubleshooting

### Authorization Issues

If you encounter authorization issues:

1. Ensure you're logged in with `huggingface-cli login`
2. Verify you have write access to the Space
3. Check your token hasn't expired (re-login if necessary)

### File Size Limitations

If your deployment package is too large:

1. Review the included files with `--list-only`
2. Add more exclusion patterns for large files
3. Consider splitting the deployment into multiple steps

### API Errors

If you encounter API errors:

1. Check your internet connection
2. Verify the Hugging Face API is operational
3. Retry the operation after a few minutes

## Best Practices

1. **Version your deployments**: Add version tags or timestamps to your packages
2. **Test locally first**: Ensure your app works locally before deploying
3. **Keep secrets out**: Never include API keys or sensitive information in the deployment
4. **Use the .huggingnorefile**: This helps exclude unnecessary files
5. **Regular cleanup**: Periodically clean old files from your Space

## Additional Resources

- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Hugging Face CLI Reference](https://huggingface.co/docs/huggingface_hub/guides/cli)