Upload 6 files
Browse files- Dockerfile +7 -0
- app.py +42 -0
- app.yaml +11 -0
- requirements.txt +7 -0
- trained_model/config.json +31 -0
- trained_model/pytorch_model.bin +3 -0
Dockerfile
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.8
|
2 |
+
WORKDIR /app
|
3 |
+
COPY requirements.txt ./requirements.txt
|
4 |
+
RUN pip3 install -r requirements.txt
|
5 |
+
EXPOSE 8080
|
6 |
+
COPY . /app
|
7 |
+
CMD streamlit run --server.port 8080 --server.enableCORS false app.py
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from aitextgen import aitextgen
|
3 |
+
from PIL import Image
|
4 |
+
import pybase64
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
|
9 |
+
def set_png_as_page_bg(png_file):
|
10 |
+
bin_str = get_base64_of_bin_file(png_file)
|
11 |
+
page_bg_img = '''
|
12 |
+
<style>
|
13 |
+
body {
|
14 |
+
background-image: url("data:image/png;base64,%s");
|
15 |
+
background-size: cover;
|
16 |
+
}
|
17 |
+
</style>
|
18 |
+
''' % bin_str
|
19 |
+
|
20 |
+
st.markdown(page_bg_img, unsafe_allow_html=True)
|
21 |
+
return
|
22 |
+
|
23 |
+
@st.cache(allow_output_mutation=True)
|
24 |
+
def get_base64_of_bin_file(bin_file):
|
25 |
+
with open(bin_file, 'rb') as f:
|
26 |
+
data = f.read()
|
27 |
+
return pybase64.b64encode(data).decode()
|
28 |
+
|
29 |
+
ai = aitextgen('trained_model/pytorch_model.bin', config = 'trained_model/config.json')
|
30 |
+
set_png_as_page_bg('plato2.jpg')
|
31 |
+
st.header("What are you thinking?")
|
32 |
+
prompt_text = st.text_input(label = 'Ask Plato')
|
33 |
+
st.subheader("What do you think love is?")
|
34 |
+
st.subheader("Love is good. Love is fun and great. It is vast. It is vast. It is big. Love and life are realative but the truth is bitter."
|
35 |
+
"Sadly no one loves you. Some people don't get it.")
|
36 |
+
st.subheader(ai.generate_one(prompt = prompt_text, top_p = 0.9 ))
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == '__main__':
|
42 |
+
main()
|
app.yaml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
runtime: custom
|
2 |
+
env: flex
|
3 |
+
|
4 |
+
entrypoint: find ${VIRTUAL_ENV}/lib/python3.8/site-packages/streamlit -type f \( -iname \*.py -o -iname \*.js \) -print0 | xargs -0 sed -i 's/healthz/health-check/g' && streamlit run app.py --server.port $PORT --server.enableCORS=false
|
5 |
+
|
6 |
+
automatic_scaling:
|
7 |
+
min_num_instances : 1
|
8 |
+
max_num_instances : 7
|
9 |
+
|
10 |
+
network:
|
11 |
+
session_affinity: true
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==0.73.0
|
2 |
+
pytorch-lightning==1.1.6
|
3 |
+
torch==1.7.1
|
4 |
+
torchvision==0.8.2
|
5 |
+
aitextgen==0.3.0
|
6 |
+
Pillow==7.2.0
|
7 |
+
pybase64==1.1.3
|
trained_model/config.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "aitextgen/pytorch_model_124M.bin",
|
3 |
+
"activation_function": "gelu_new",
|
4 |
+
"architectures": [
|
5 |
+
"GPT2LMHeadModel"
|
6 |
+
],
|
7 |
+
"attn_pdrop": 0.1,
|
8 |
+
"bos_token_id": 50256,
|
9 |
+
"embd_pdrop": 0.1,
|
10 |
+
"eos_token_id": 50256,
|
11 |
+
"gradient_checkpointing": false,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"layer_norm_epsilon": 1e-05,
|
14 |
+
"model_type": "gpt2",
|
15 |
+
"n_ctx": 1024,
|
16 |
+
"n_embd": 768,
|
17 |
+
"n_head": 12,
|
18 |
+
"n_inner": null,
|
19 |
+
"n_layer": 12,
|
20 |
+
"n_positions": 1024,
|
21 |
+
"n_vocab": 50257,
|
22 |
+
"resid_pdrop": 0.1,
|
23 |
+
"summary_activation": null,
|
24 |
+
"summary_first_dropout": 0.1,
|
25 |
+
"summary_proj_to_labels": true,
|
26 |
+
"summary_type": "cls_index",
|
27 |
+
"summary_use_proj": true,
|
28 |
+
"transformers_version": "4.2.2",
|
29 |
+
"use_cache": true,
|
30 |
+
"vocab_size": 50257
|
31 |
+
}
|
trained_model/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bee3ae3528f9a67d6c4688445f5c4bca194041f5a6d9471681ea3b3043f30a66
|
3 |
+
size 510406247
|