Spaces:
Sleeping
Sleeping
iskoldt-X
commited on
Tune the Docker image (#52)
Browse files* Docker guide
* docker flag
* Running in Docker with user and password
* 谁把import openai 注释了?
* Update requirements.txt
* Deal with Docker api conflict
* Update README.md
* # import openai
* # import openai
- ChuanhuChatbot.py +31 -9
- Dockerfile +1 -0
- README.md +13 -10
ChuanhuChatbot.py
CHANGED
|
@@ -9,15 +9,28 @@ import requests
|
|
| 9 |
|
| 10 |
my_api_key = "" # 在这里输入你的 API 密钥
|
| 11 |
initial_prompt = "You are a helpful assistant."
|
| 12 |
-
|
| 13 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
| 14 |
|
| 15 |
-
if my_api_key == "":
|
| 16 |
-
my_api_key = os.environ.get('my_api_key')
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def parse_text(text):
|
|
@@ -266,6 +279,15 @@ with gr.Blocks() as demo:
|
|
| 266 |
print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
|
| 267 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|
| 268 |
demo.title = "川虎ChatGPT 🚀"
|
| 269 |
-
|
| 270 |
-
#
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
my_api_key = "" # 在这里输入你的 API 密钥
|
| 11 |
initial_prompt = "You are a helpful assistant."
|
|
|
|
| 12 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
|
| 16 |
+
#if we are running in Docker
|
| 17 |
+
if os.environ.get('dockerrun') == 'yes':
|
| 18 |
+
dockerflag = True
|
| 19 |
+
else:
|
| 20 |
+
dockerflag = False
|
| 21 |
+
|
| 22 |
+
if dockerflag:
|
| 23 |
+
my_api_key = os.environ.get('my_api_key')
|
| 24 |
+
if my_api_key == "empty":
|
| 25 |
+
print("Please give a api key!")
|
| 26 |
+
sys.exit(1)
|
| 27 |
+
#auth
|
| 28 |
+
username = os.environ.get('USERNAME')
|
| 29 |
+
password = os.environ.get('PASSWORD')
|
| 30 |
+
if isinstance(username, type(None)) or isinstance(password, type(None)):
|
| 31 |
+
authflag = False
|
| 32 |
+
else:
|
| 33 |
+
authflag = True
|
| 34 |
|
| 35 |
|
| 36 |
def parse_text(text):
|
|
|
|
| 279 |
print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
|
| 280 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|
| 281 |
demo.title = "川虎ChatGPT 🚀"
|
| 282 |
+
|
| 283 |
+
#if running in Docker
|
| 284 |
+
if dockerflag:
|
| 285 |
+
if authflag:
|
| 286 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860,auth=(username, password))
|
| 287 |
+
else:
|
| 288 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False)
|
| 289 |
+
#if not running in Docker
|
| 290 |
+
else:
|
| 291 |
+
demo.queue().launch(server_name = "0.0.0.0", share=False) # 改为 share=True 可以创建公开分享链接
|
| 292 |
+
#demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
|
| 293 |
+
#demo.queue().launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码
|
Dockerfile
CHANGED
|
@@ -10,4 +10,5 @@ ENV PATH=/root/.local/bin:$PATH
|
|
| 10 |
COPY . /app
|
| 11 |
WORKDIR /app
|
| 12 |
ENV my_api_key empty
|
|
|
|
| 13 |
CMD ["python3", "-u", "ChuanhuChatbot.py", "2>&1", "|", "tee", "/var/log/application.log"]
|
|
|
|
| 10 |
COPY . /app
|
| 11 |
WORKDIR /app
|
| 12 |
ENV my_api_key empty
|
| 13 |
+
ENV dockerrun yes
|
| 14 |
CMD ["python3", "-u", "ChuanhuChatbot.py", "2>&1", "|", "tee", "/var/log/application.log"]
|
README.md
CHANGED
|
@@ -83,29 +83,32 @@ python3 ChuanhuChatbot.py
|
|
| 83 |
|
| 84 |
如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
|
| 85 |
|
| 86 |
-
## 或者,使用Docker
|
| 87 |
|
| 88 |
-
###
|
| 89 |
-
|
| 90 |
-
从本项目的[Packages](https://github.com/GaiZhenbiao/ChuanhuChatGPT/pkgs/container/chuanhuchatgpt)页面拉取Docker镜像,使用Github Actions自动创建。也可以去本项目的[Dockerhub页面](https://hub.docker.com/r/tuchuanhuhuhu/chuanhuchatgpt)拉取。
|
| 91 |
-
|
| 92 |
-
### 手动构建镜像
|
| 93 |
|
| 94 |
```
|
| 95 |
-
docker
|
| 96 |
```
|
| 97 |
|
| 98 |
-
运行
|
| 99 |
|
| 100 |
```
|
| 101 |
-
docker run -d --name chatgpt -e my_api_key="替换成API"
|
| 102 |
```
|
| 103 |
|
| 104 |
-
###
|
| 105 |
```
|
| 106 |
docker logs chatgpt
|
| 107 |
```
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
## 部署相关
|
| 110 |
|
| 111 |
### 部署到公网服务器
|
|
|
|
| 83 |
|
| 84 |
如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
|
| 85 |
|
| 86 |
+
## 或者,使用Docker 运行
|
| 87 |
|
| 88 |
+
### 拉取镜像
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
```
|
| 91 |
+
docker pull tuchuanhuhuhu/chuanhuchatgpt:latest
|
| 92 |
```
|
| 93 |
|
| 94 |
+
### 运行
|
| 95 |
|
| 96 |
```
|
| 97 |
+
docker run -d --name chatgpt -e my_api_key="替换成API" -p 7860:7860 tuchuanhuhuhu/chuanhuchatgpt:latest
|
| 98 |
```
|
| 99 |
|
| 100 |
+
### 查看运行状态
|
| 101 |
```
|
| 102 |
docker logs chatgpt
|
| 103 |
```
|
| 104 |
|
| 105 |
+
### 也可修改脚本后手动构建镜像
|
| 106 |
+
|
| 107 |
+
```
|
| 108 |
+
docker build -t chuanhuchatgpt:latest .
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
|
| 112 |
## 部署相关
|
| 113 |
|
| 114 |
### 部署到公网服务器
|