Chuan Hu commited on
Commit
0fb897b
·
unverified ·
2 Parent(s): 0def5d5 24d50bd

Merge pull request #7 from iskoldt-X/main

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +11 -3
  2. Dockerfile +13 -0
  3. README.md +20 -0
ChuanhuChatbot.py CHANGED
@@ -1,12 +1,20 @@
1
  import gradio as gr
2
  import openai
 
 
3
  # import markdown
4
 
5
-
6
- 我的API密钥 = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 在这里输入你的 API 密钥
7
  initial_prompt = "You are a helpful assistant."
8
 
9
- openai.api_key = 我的API密钥
 
 
 
 
 
 
 
10
 
11
  def parse_text(text):
12
  lines = text.split("\n")
 
1
  import gradio as gr
2
  import openai
3
+ import os
4
+ import sys
5
  # import markdown
6
 
7
+ my_api_key = "" # 在这里输入你的 API 密钥
 
8
  initial_prompt = "You are a helpful assistant."
9
 
10
+ if my_api_key == "":
11
+ my_api_key = os.environ.get('my_api_key')
12
+
13
+ if my_api_key == "empty":
14
+ print("Please give a api key!")
15
+ sys.exit(1)
16
+
17
+ openai.api_key = my_api_key
18
 
19
  def parse_text(text):
20
  lines = text.split("\n")
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9 as builder
2
+ RUN apt-get update && apt-get install -y build-essential
3
+ COPY requirements.txt .
4
+ RUN pip install --user -r requirements.txt
5
+
6
+ FROM python:3.9
7
+ MAINTAINER iskoldt
8
+ COPY --from=builder /root/.local /root/.local
9
+ 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"]
README.md CHANGED
@@ -42,6 +42,26 @@ python3 ChuanhuChatbot.py
42
 
43
  如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  ## 使用技巧
46
 
47
  - 使用System Prompt可以很有效地设定前提条件
 
42
 
43
  如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
44
 
45
+ ## 使用Docker 安装与运行
46
+
47
+ 构建镜像
48
+ ```
49
+ docker build -t chuanhuchatgpt:latest .
50
+ ```
51
+
52
+ 一键运行
53
+ ```
54
+ docker run -d --name chatgpt -e my_api_key="替换成API" --network host chuanhuchatgpt:latest
55
+ ```
56
+
57
+ 查看本地访问地址
58
+ ```
59
+ docker logs chatgpt
60
+ ```
61
+
62
+
63
+
64
+
65
  ## 使用技巧
66
 
67
  - 使用System Prompt可以很有效地设定前提条件