File size: 3,623 Bytes
4fe6054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Deploying Your Personal AI Assistant to Hugging Face Spaces

This guide provides detailed instructions for deploying your Personal AI Assistant with RAG to Hugging Face Spaces.

## Prerequisites

Before you start, make sure you have:

1. **A Hugging Face Account**: Sign up at [https://huggingface.co/join](https://huggingface.co/join) if you don't have one
2. **Hugging Face API Token**: Create a token at [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
3. **Git**: Installed and configured on your machine
4. **Python 3.8+**: With pip for installing packages

## Step 1: Install Dependencies

First, install all required packages:

```bash
pip install -r requirements.txt
```

Make sure you have the huggingface_hub package installed:

```bash
pip install huggingface_hub
```

## Step 2: Check Your Git Configuration

Run the check script to ensure your Git is properly configured:

```bash
python check_git_status.py
```

This will:
- Verify Git is installed
- Check your Git configuration
- Confirm your repository status
- Verify Hugging Face configuration

Follow any prompts to fix issues that are detected.

## Step 3: Deploy to Hugging Face Spaces

Run the deployment script:

```bash
python deploy_to_hf.py
```

You will be prompted to enter:
1. Your Hugging Face username
2. Your Hugging Face API token
3. A name for your Space (or accept the default: personal-rag-assistant)

The script will:
- Configure your environment
- Create a new Hugging Face Space
- Set up Git for pushing to Hugging Face
- Push your code to the Space

## Step 4: Monitor the Deployment

After pushing your code:

1. Visit [https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME](https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME)
2. You'll see a "Building" status while Hugging Face builds your Docker container
3. This may take 5-10 minutes for the first build

## Step 5: Using Your Deployed Assistant

Once deployment is complete:

1. Your app will be accessible at [https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME](https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME)
2. Upload documents through the sidebar
3. Start asking questions about your documents
4. The application automatically saves your conversation history

## Troubleshooting

### Authentication Issues

If you encounter Git authentication issues:

```
remote: HTTP Basic: Access denied
```

This usually means:
- Your Hugging Face token is invalid or expired
- You haven't configured Git to use your token

Solution: Re-run the deployment script to update your credentials.

### Build Failures

If your Space shows a build failure:

1. Check the build logs in the Hugging Face Space UI
2. Common issues include:
   - Missing dependencies in requirements.txt
   - Issues with the Dockerfile
   - Errors in your Python code

### Space Creation Errors

If the Space creation fails:

1. Try creating the Space manually in the Hugging Face UI
2. Then run the deployment script again, which will detect the existing Space

## Managing Your Space

After deployment, you can:

- **Update Your App**: Make changes locally, then run `python deploy_to_hf.py` again
- **Change Hardware**: Upgrade to a more powerful instance in the Hugging Face UI
- **Monitor Usage**: View usage statistics in the Hugging Face UI
- **Share Your App**: Share the URL with others to use your assistant

## Additional Resources

- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Streamlit Documentation](https://docs.streamlit.io/)
- [LangChain Documentation](https://python.langchain.com/docs/)