mphycx commited on
Commit
be6dbc5
·
1 Parent(s): 4556539

Fix secret, run in one command

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -12
  2. app.py +5 -19
  3. docker-compose.yaml +0 -15
Dockerfile CHANGED
@@ -1,28 +1,27 @@
1
- FROM python:3.9-slim-bullseye as langchain-serve-img
2
 
 
 
 
 
 
3
  COPY requirements_pytorch.txt requirements_pytorch.txt
4
  COPY requirements_api.txt requirements_api.txt
 
 
5
  RUN pip3 install -r requirements_pytorch.txt
6
  RUN pip3 install -r requirements_api.txt
7
-
8
- COPY api.py api.py
9
-
10
- EXPOSE 8080
11
-
12
- ENTRYPOINT [ "lc-serve", "deploy", "local", "api.py" ]
13
-
14
- FROM python:3.9-slim-bullseye as pdfgpt-chat-img
15
-
16
- COPY requirements_app.txt requirements_app.txt
17
  RUN pip3 install -r requirements_app.txt
18
 
19
  WORKDIR /app
20
 
21
  COPY intfloat /app/intfloat
22
  COPY app.py app.py
 
23
 
24
  EXPOSE 7860
 
25
 
26
  HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
27
 
28
- ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=7860"]
 
1
+ FROM python:3.9-slim-bullseye as pdfgpt-chat-img
2
 
3
+ # Expose the secret OPENAI_API_KEY at buildtime and use its value as git remote URL
4
+ RUN --mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=true \
5
+ git init && \
6
+ git remote add origin $(cat /run/secrets/OPENAI_API_KEY)
7
+
8
  COPY requirements_pytorch.txt requirements_pytorch.txt
9
  COPY requirements_api.txt requirements_api.txt
10
+ COPY requirements_app.txt requirements_app.txt
11
+
12
  RUN pip3 install -r requirements_pytorch.txt
13
  RUN pip3 install -r requirements_api.txt
 
 
 
 
 
 
 
 
 
 
14
  RUN pip3 install -r requirements_app.txt
15
 
16
  WORKDIR /app
17
 
18
  COPY intfloat /app/intfloat
19
  COPY app.py app.py
20
+ COPY api.py api.py
21
 
22
  EXPOSE 7860
23
+ EXPOSE 8080
24
 
25
  HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
26
 
27
+ CMD ["lc-serve", "deploy", "local", "api.py", "&&", "streamlit", "run", "app.py", "--server.port=7860"]
app.py CHANGED
@@ -22,7 +22,7 @@ def main():
22
  @st.cache_data
23
  def convert_df(df):
24
  return df.to_csv(index=False).encode("utf-8")
25
-
26
  def pdf_change():
27
  st.session_state["pdf_change"] = True
28
 
@@ -62,7 +62,7 @@ def main():
62
  "embedding_model": embedding_model,
63
  "gpt_model": gpt_model,
64
  "envs": {
65
- "OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY"),
66
  }
67
  },
68
  )
@@ -73,7 +73,7 @@ def main():
73
  "embedding_model": embedding_model,
74
  "gpt_model": gpt_model,
75
  "envs": {
76
- "OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY"),
77
  }
78
  }
79
 
@@ -116,7 +116,6 @@ def main():
116
  url: str,
117
  file: _TemporaryFileWrapper,
118
  question: str,
119
- openai_key: str,
120
  ) -> dict:
121
  if question.strip() == "":
122
  return "[ERROR]: Question field is empty"
@@ -127,7 +126,7 @@ def main():
127
  "embedding_model": embedding_model,
128
  "gpt_model": gpt_model,
129
  "envs": {
130
- "OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY"),
131
  },
132
  }
133
 
@@ -209,6 +208,7 @@ def main():
209
  "gpt-4": "GPT-4 (smarter, costlier)",
210
  }
211
  LCSERVE_HOST = "http://localhost:8080"
 
212
  PDFGPT_URL = "https://github.com/bhaskatripathi/pdfGPT"
213
  SIGNATURE = """<style>
214
  .footer {
@@ -273,19 +273,6 @@ color:darkgray'>Developed with ❤ by asyafiqe</p>
273
  # sidebar
274
  with input_details:
275
  # sidebar
276
- st.title("Input details")
277
- OPENAI_URL = "https://platform.openai.com/account/api-keys"
278
- openai_key = st.text_input(
279
- ":key: Enter your OpenAI API key here",
280
- type="password",
281
- help="Get your Open AI API key [here](%s)" % OPENAI_URL,
282
- )
283
- colored_header(
284
- label="",
285
- description="",
286
- color_name="blue-40",
287
- )
288
-
289
  pdf_url = st.text_input(
290
  ":globe_with_meridians: Enter PDF URL here", on_change=pdf_change
291
  )
@@ -323,7 +310,6 @@ color:darkgray'>Developed with ❤ by asyafiqe</p>
323
  pdf_url,
324
  file,
325
  user_input,
326
- os.environ.get("OPENAI_API_KEY"),
327
  )
328
  st.session_state.past.append(user_input)
329
  st.session_state.generated.append(response["answer"])
 
22
  @st.cache_data
23
  def convert_df(df):
24
  return df.to_csv(index=False).encode("utf-8")
25
+
26
  def pdf_change():
27
  st.session_state["pdf_change"] = True
28
 
 
62
  "embedding_model": embedding_model,
63
  "gpt_model": gpt_model,
64
  "envs": {
65
+ "OPENAI_API_KEY": OPENAI_API_KEY,
66
  }
67
  },
68
  )
 
73
  "embedding_model": embedding_model,
74
  "gpt_model": gpt_model,
75
  "envs": {
76
+ "OPENAI_API_KEY": OPENAI_API_KEY,
77
  }
78
  }
79
 
 
116
  url: str,
117
  file: _TemporaryFileWrapper,
118
  question: str,
 
119
  ) -> dict:
120
  if question.strip() == "":
121
  return "[ERROR]: Question field is empty"
 
126
  "embedding_model": embedding_model,
127
  "gpt_model": gpt_model,
128
  "envs": {
129
+ "OPENAI_API_KEY": OPENAI_API_KEY,
130
  },
131
  }
132
 
 
208
  "gpt-4": "GPT-4 (smarter, costlier)",
209
  }
210
  LCSERVE_HOST = "http://localhost:8080"
211
+ OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
212
  PDFGPT_URL = "https://github.com/bhaskatripathi/pdfGPT"
213
  SIGNATURE = """<style>
214
  .footer {
 
273
  # sidebar
274
  with input_details:
275
  # sidebar
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  pdf_url = st.text_input(
277
  ":globe_with_meridians: Enter PDF URL here", on_change=pdf_change
278
  )
 
310
  pdf_url,
311
  file,
312
  user_input,
 
313
  )
314
  st.session_state.past.append(user_input)
315
  st.session_state.generated.append(response["answer"])
docker-compose.yaml DELETED
@@ -1,15 +0,0 @@
1
- version: '3'
2
-
3
- services:
4
- langchain-serve:
5
- build:
6
- context: .
7
- target: langchain-serve-img
8
- ports:
9
- - '8080:8080'
10
- pdf-gpt:
11
- build:
12
- context: .
13
- target: pdf-gpt-img
14
- ports:
15
- - '7860:7860'