Skip to content

Commit

Permalink
Complete documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed Dec 24, 2024
1 parent c31eebc commit 1627003
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 61 deletions.
158 changes: 126 additions & 32 deletions README-zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,59 +254,153 @@

要在終端運行危險檢測系統,您需要在機器上安裝 Python。按照以下步驟來啟動系統:

1. 將存儲庫克隆到本地機器。
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```
### 1. 將專案複製至本機
使用以下指令將專案從 GitHub 複製到本機:

2. 進入克隆的目錄。
```bash
cd Construction-Hazard-Detection
```
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```

3. 安裝所需的軟體包:
```bash
pip install -r requirements.txt
```
---

### 2. 進入專案目錄
進入剛剛複製的專案目錄:

```bash
cd Construction-Hazard-Detection
```

---

4. 安裝並啟動 MySQL 服務:
### 3. 安裝所需的套件
執行以下指令安裝專案所需的套件:

Linux 使用者:
```bash
pip install -r requirements.txt
```

---

### 4. 安裝並啟動 MySQL 服務(如需要)

#### Ubuntu 系統使用者:

1. 開啟終端機,執行以下指令安裝 MySQL:
```bash
sudo apt update
sudo apt install mysql-server
```

2. 安裝完成後,啟動 MySQL 服務:
```bash
sudo systemctl start mysql.service
```

對於其他人,您可以在此[連結](https://dev.mysql.com/downloads/)下載並安裝適用於您的作業系統的MySQL。
#### 其他作業系統使用者:

請從 [MySQL 下載頁面](https://dev.mysql.com/downloads/)下載適合您作業系統的 MySQL 並完成安裝。

---

#### 初始化資料庫:

完成 MySQL 安裝後,執行初始化腳本來建立 `construction_hazard_detection` 資料庫及 `users` 資料表:

```bash
mysql -u root -p < scripts/init.sql
```

5. 設置用戶帳戶和密碼。使用以下命令啟動用戶管理 API:
執行指令後,系統會提示您輸入 MySQL 的 root 密碼。請確認 `scripts/init.sql` 檔案內已包含建立資料庫和資料表的 SQL 指令。

---

### 5. 設定 Redis 伺服器(僅限於 Streaming Web 功能)

Redis 僅在使用 **Streaming Web** 功能時需要。請依以下步驟安裝及設定 Redis:

#### Ubuntu 系統使用者:

1. **安裝 Redis**
執行以下指令安裝 Redis:
```bash
gunicorn -w 1 -b 0.0.0.0:8000 "examples.user_management.app:user-managements-app"
sudo apt update
sudo apt install redis-server
```
建議使用 Postman 應用程式與 API 進行互動。

6. 要運行物體檢測 API,使用以下命令:
2. **設定 Redis(可選)**
- 如果需要進一步設定,請編輯 Redis 設定檔案:
```bash
gunicorn -w 1 -b 0.0.0.0:8001 "examples.YOLO_server_api.app:YOLO-server-api-app"
sudo vim /etc/redis/redis.conf
```
- 如需啟用密碼保護,請找到以下行,取消註解並設置密碼:
```conf
requirepass YourStrongPassword
```
`YourStrongPassword` 替換為強密碼。

7. 使用特定的配置文件運行主應用程序,使用以下命令:
3. **啟動並設置 Redis 服務開機自動啟動**
- 啟動 Redis 服務:
```bash
python3 main.py --config config/configuration.json
sudo systemctl start redis.service
```
`config/configuration.json` 替換為您的配置文件的實際路徑。
- 設置開機自動啟動:
```bash
sudo systemctl enable redis.service
```

#### 其他作業系統使用者:

請參考官方文件:[Redis 安裝指南](https://redis.io/docs/getting-started/installation/)。

---

### 6. 啟動物件偵測 API
執行以下指令啟動物件偵測 API:

```bash
uvicorn examples.YOLO_server.backend.app:sio_app --host 0.0.0.0 --port 8001
```

---

### 7. 使用特定配置檔案執行主應用程式
執行以下指令啟動主應用程式,並指定配置檔案:

```bash
python3 main.py --config config/configuration.json
```

請將 `config/configuration.json` 替換為您的實際配置檔案路徑。

---

### 8. 啟動 Streaming Web 服務

#### 啟動後端服務

##### Linux 系統使用者:
執行以下指令啟動後端服務:

```bash
uvicorn examples.streaming_web.backend.app:sio_app --host 127.0.0.1 --port 8002
```

##### Windows 系統使用者:
使用以下 `waitress-serve` 指令啟動後端服務:

```cmd
waitress-serve --host=127.0.0.1 --port=8002 "examples.streaming_web.backend.app:streaming-web-app"
```

---

8. 要啟動串流 Web 服務,執行以下命令:
#### 設定前端服務

對於 Linux 使用者:
````bash
gunicorn -w 1 -k eventlet -b 127.0.0.1:8002 "examples.streaming_web.app:streaming-web-app"
````
請參考 `examples/YOLO_server_api/frontend/nginx.conf` 文件進行部署,並將靜態網頁檔案放置於以下目錄:

對於 Windows 使用者:
````
waitress-serve --host=127.0.0.1 --port=8002 "examples.streaming_web.app:streaming-web-app"
````
```plaintext
examples/YOLO_server_api/frontend/dist
```

</details>

Expand Down
168 changes: 139 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,59 +260,169 @@ Now, you could launch the hazard-detection system in Docker or Python env:
To run the hazard detection system with Python, follow these steps:
1. Clone the repository to your local machine:
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```
### **1. Clone the Repository to Your Local Machine**
2. Navigate to the cloned directory:
```bash
cd Construction-Hazard-Detection
```
Use the following command to clone the repository from GitHub:
3. Install required packages:
```bash
pip install -r requirements.txt
```
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```

---

### **2. Navigate to the Cloned Directory**

Change the directory to the newly cloned repository:

```bash
cd Construction-Hazard-Detection
```

---

### **3. Install Required Packages**

Run the following command to install the necessary Python packages:

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

4. Install and launch MySQL service (if required):
---

### **4. Install and Launch MySQL Service (if Required)**

#### **For Ubuntu Users**

1. Open the terminal and execute the following commands to install and start the MySQL server:

For Ubuntu users:
```bash
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql.service
```

For others, you can download and install MySQL that works in your operation system in this [link](https://dev.mysql.com/downloads/).
#### **For Other Operating Systems**

1. Download and install the appropriate version of MySQL for your operating system from the [MySQL Downloads](https://dev.mysql.com/downloads/) page.

---

#### **Initialise the Database**

After installing MySQL, use the following command to initialise the `construction_hazard_detection` database and create the `users` table:

```bash
mysql -u root -p < scripts/init.sql
```

You will be prompted to enter the MySQL root password. Ensure that the `scripts/init.sql` file contains the necessary SQL commands to set up the database and tables as described earlier.

---

### **5. Set Up Redis Server (Required Only for Streaming Web)**

Redis is needed only when using the **Streaming Web** functionality. Follow the steps below to set up Redis.

#### **For Ubuntu Users**

1. **Install Redis**

Open the terminal and run the following commands:

5. Start user management API:
```bash
gunicorn -w 1 -b 0.0.0.0:8000 "examples.user_management.app:user-managements-app"
sudo apt update
sudo apt install redis-server
```

6. Run object detection API:
2. **Configure Redis (Optional)**

If you need custom settings, edit the Redis configuration file:

```bash
uvicorn examples.YOLO_server.app:sio_app --host 0.0.0.0 --port 8001
sudo vim /etc/redis/redis.conf
```

7. Run the main application with a specific configuration file:
```bash
python3 main.py --config config/configuration.json
To enhance security, enable password protection by adding or modifying the following line:

```conf
requirepass YourStrongPassword
```
Replace `config/configuration.json` with the actual path to your configuration file.

8. Start the streaming web service:
Replace `YourStrongPassword` with a secure password.

3. **Start and Enable Redis Service**

Start the Redis service:

For linux users:
```bash
uvicorn examples.streaming_web.app:sio_app --host 0.0.0.0 --port 8002
sudo systemctl start redis.service
```

For windows users:
```
waitress-serve --host=127.0.0.1 --port=8002 "examples.streaming_web.app:streaming-web-app"
Enable Redis to start automatically on boot:

```bash
sudo systemctl enable redis.service
```

#### **For Other Operating Systems**

Refer to the official [Redis installation guide](https://redis.io/docs/getting-started/installation/) for instructions specific to your operating system.

---

### **6. Run the Object Detection API**

Start the object detection API with the following command:

```bash
uvicorn examples.YOLO_server.backend.app:sio_app --host 0.0.0.0 --port 8001
```

---

### **7. Run the Main Application with a Specific Configuration File**

Use the following command to run the main application and specify the configuration file:

```bash
python3 main.py --config config/configuration.json
```

Replace `config/configuration.json` with the actual path to your configuration file.

---

### **8. Start the Streaming Web Service**

#### **Launching the Backend**

##### **For Linux Users**

Run the following command to start the backend service on a Linux system:

```bash
uvicorn examples.streaming_web.backend.app:sio_app --host 127.0.0.1 --port 8002
```

##### **For Windows Users**

To start the backend service on a Windows system, use the following command:

```cmd
waitress-serve --host=127.0.0.1 --port=8002 "examples.streaming_web.backend.app:streaming-web-app"
```

---

#### **Setting Up the Frontend**

Refer to the `examples/YOLO_server_api/frontend/nginx.conf` file for deployment instructions. Place the static web files in the following directory:

```plaintext
examples/YOLO_server_api/frontend/dist
```

</details>

## Additional Information
Expand Down
Loading

0 comments on commit 1627003

Please sign in to comment.