Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,116 +10,3 @@ pinned: false
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 13 |
-
|
| 14 |
-
# Deploying a Streamlit App on AWS EC2
|
| 15 |
-
|
| 16 |
-
This guide will walk you through the steps to deploy your Streamlit application on an AWS EC2 instance.
|
| 17 |
-
|
| 18 |
-
## Prerequisites
|
| 19 |
-
|
| 20 |
-
1. A Streamlit app designed and tested locally with the following structure:
|
| 21 |
-
- `requirements.txt`
|
| 22 |
-
- `app.py`
|
| 23 |
-
2. An AWS account.
|
| 24 |
-
|
| 25 |
-
## Steps to Deploy
|
| 26 |
-
|
| 27 |
-
### 1. Launch an EC2 Instance
|
| 28 |
-
|
| 29 |
-
1. Log in to your AWS account.
|
| 30 |
-
2. Navigate to the EC2 Dashboard.
|
| 31 |
-
3. Click on "Launch Instance."
|
| 32 |
-
4. Name your instance `streamlit-test`.
|
| 33 |
-
5. Choose an Amazon Machine Image (AMI). You can use the default Amazon Linux 2 AMI.
|
| 34 |
-
6. Select an instance type (e.g., t2.micro for free tier eligibility).
|
| 35 |
-
7. Configure the instance details as required.
|
| 36 |
-
8. Add storage if necessary.
|
| 37 |
-
9. Add tags if desired.
|
| 38 |
-
10. Configure the security group:
|
| 39 |
-
- Click on "Add Rule."
|
| 40 |
-
- Set the "Type" to "Custom TCP."
|
| 41 |
-
- Set the "Port Range" to `8501` (Streamlit's default port).
|
| 42 |
-
- Set "Source" to `Anywhere` to allow access from any IP (or restrict to your IP for security).
|
| 43 |
-
- Click "Save rules."
|
| 44 |
-
|
| 45 |
-
### 2. Create and Download the Key Pair
|
| 46 |
-
|
| 47 |
-
1. When prompted, create a new key pair.
|
| 48 |
-
2. Name the key pair `streamlit-test-key`.
|
| 49 |
-
3. Download the `.pem` file and save it in a directory of your choice.
|
| 50 |
-
|
| 51 |
-
### 3. Connect to the EC2 Instance
|
| 52 |
-
|
| 53 |
-
1. In the EC2 Dashboard, go to "Instances."
|
| 54 |
-
2. Click on the `Instance ID` of your newly created instance.
|
| 55 |
-
3. Click on "Connect."
|
| 56 |
-
4. Follow the instructions to connect using SSH. The command should look like this:
|
| 57 |
-
|
| 58 |
-
```sh
|
| 59 |
-
ssh -i "streamlit-test-key.pem" ec2-user@<your-ec2-public-dns>
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
Replace `<your-ec2-public-dns>` with your instance's public DNS.
|
| 63 |
-
|
| 64 |
-
### 4. Copy Local Files to the EC2 Instance
|
| 65 |
-
|
| 66 |
-
1. Open another terminal window.
|
| 67 |
-
2. Navigate to the directory containing your `.pem` key file and Streamlit app.
|
| 68 |
-
3. Use `scp` to copy your local files to the EC2 instance:
|
| 69 |
-
|
| 70 |
-
```sh
|
| 71 |
-
scp -i "streamlit-test-key.pem" -r ./meta-llama3-full-stack/* ec2-user@<your-ec2-public-dns>:/home/ec2-user/
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
Replace `<your-ec2-public-dns>` with your instance's public DNS.
|
| 75 |
-
|
| 76 |
-
### 5. Set Up the EC2 Environment
|
| 77 |
-
|
| 78 |
-
1. Once connected to the EC2 instance via SSH, create a virtual environment:
|
| 79 |
-
|
| 80 |
-
```sh
|
| 81 |
-
python3 -m venv venv
|
| 82 |
-
source venv/bin/activate
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
2. Navigate to the project directory and install the required packages:
|
| 86 |
-
|
| 87 |
-
```sh
|
| 88 |
-
cd /home/ec2-user/meta-llama3-full-stack
|
| 89 |
-
pip install -r requirements.txt
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
### 6. Run the Streamlit App
|
| 93 |
-
|
| 94 |
-
1. For a temporary run, simply execute:
|
| 95 |
-
|
| 96 |
-
```sh
|
| 97 |
-
streamlit run app.py
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
2. For a persistent run, use `nohup`:
|
| 101 |
-
|
| 102 |
-
```sh
|
| 103 |
-
nohup streamlit run app.py &
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
### 7. Access the Streamlit App
|
| 107 |
-
|
| 108 |
-
1. Open your web browser and navigate to:
|
| 109 |
-
|
| 110 |
-
```sh
|
| 111 |
-
http://<your-ec2-public-dns>:8501
|
| 112 |
-
```
|
| 113 |
-
|
| 114 |
-
Replace `<your-ec2-public-dns>` with your instance's public DNS.
|
| 115 |
-
|
| 116 |
-
### Code Reference
|
| 117 |
-
|
| 118 |
-
The code for the Streamlit app can be found here: [Meta Llama 3 Full Stack](https://huggingface.co/spaces/eagle0504/meta-llama3-full-stack)
|
| 119 |
-
|
| 120 |
-
### Notes
|
| 121 |
-
|
| 122 |
-
- Ensure that your security group rules are correctly configured to allow inbound traffic on port 8501.
|
| 123 |
-
- Keep your `.pem` file secure and do not share it.
|
| 124 |
-
|
| 125 |
-
Following these steps will help you successfully deploy your Streamlit app on an AWS EC2 instance.
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|