Teslim Olunlade commited on
Commit
639b99e
·
1 Parent(s): 10a61c2

Use of model in application

Browse files
.dockerignore → app/.dockerignore RENAMED
File without changes
Dockerfile → app/Dockerfile RENAMED
@@ -1,27 +1,27 @@
1
- # For more information, please refer to https://aka.ms/vscode-docker-python
2
- FROM python:3.10-slim
3
- WORKDIR /usr/src/app
4
-
5
- # Keeps Python from generating .pyc files in the container
6
- ENV PYTHONDONTWRITEBYTECODE=1
7
-
8
- # Turns off buffering for easier container logging
9
- ENV PYTHONUNBUFFERED=1
10
-
11
- # Install pip requirements
12
- COPY requirements.txt .
13
- RUN python -m pip install -r requirements.txt
14
-
15
- COPY . .
16
-
17
- # Creates a non-root user with an explicit UID and adds permission to access the /app folder
18
- # For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
19
- RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /usr/src/app
20
- USER appuser
21
-
22
- EXPOSE 8501
23
-
24
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
25
-
26
- # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
27
- ENTRYPOINT ["streamlit", "run", "app/main.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # For more information, please refer to https://aka.ms/vscode-docker-python
2
+ FROM python:3.10-slim
3
+ WORKDIR /usr/src/app
4
+
5
+ # Keeps Python from generating .pyc files in the container
6
+ ENV PYTHONDONTWRITEBYTECODE=1
7
+
8
+ # Turns off buffering for easier container logging
9
+ ENV PYTHONUNBUFFERED=1
10
+
11
+ # Install pip requirements
12
+ COPY requirements.txt .
13
+ RUN python -m pip install -r requirements.txt
14
+
15
+ COPY . .
16
+
17
+ # Creates a non-root user with an explicit UID and adds permission to access the /app folder
18
+ # For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
19
+ RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /usr/src/app
20
+ USER appuser
21
+
22
+ EXPOSE 8501
23
+
24
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
25
+
26
+ # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
27
+ ENTRYPOINT ["streamlit", "run", "main.py", "--server.port=8501", "--server.address=0.0.0.0"]
app/main.py CHANGED
@@ -16,8 +16,7 @@ text = st.text_area("Input text", demo, height=275)
16
  model_name = st.selectbox(
17
  "Select the model you want to use below.",
18
  (
19
- "distilbert-base-uncased-finetuned-sst-2-english",
20
- "roberta-large-mnli",
21
  ),
22
  )
23
 
@@ -31,6 +30,7 @@ input = tokenizer(text, return_tensors="tf")
31
 
32
  if st.button("Submit", type="primary"):
33
  results = clf(text)[0]
 
34
  classes = dict(d.values() for d in results)
35
  # st.write(f"The sentiment is {results}.")
36
  st.bar_chart(classes)
 
16
  model_name = st.selectbox(
17
  "Select the model you want to use below.",
18
  (
19
+ "ogtega/tweet-toxicity-classifier",
 
20
  ),
21
  )
22
 
 
30
 
31
  if st.button("Submit", type="primary"):
32
  results = clf(text)[0]
33
+ print(results)
34
  classes = dict(d.values() for d in results)
35
  # st.write(f"The sentiment is {results}.")
36
  st.bar_chart(classes)
requirements.txt → app/requirements.txt RENAMED
File without changes
app/train.py CHANGED
@@ -4,8 +4,13 @@ import numpy as np
4
  import tensorflow as tf
5
  from datasets import load_dataset
6
  from tensorflow.keras.optimizers import Adam
7
- from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
 
 
 
 
8
 
 
9
  checkpoint_path = "out/cp.ckpt"
10
 
11
  labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
@@ -53,6 +58,11 @@ cp_callback = tf.keras.callbacks.ModelCheckpoint(
53
  filepath=checkpoint_path, save_weights_only=True, verbose=1
54
  )
55
 
 
 
 
 
 
 
56
  model.compile(optimizer=Adam(3e-5), loss="categorical_crossentropy")
57
- model.fit(tf_dataset, callbacks=[cp_callback])
58
- model.save('out/model')
 
4
  import tensorflow as tf
5
  from datasets import load_dataset
6
  from tensorflow.keras.optimizers import Adam
7
+ from transformers import (
8
+ AutoTokenizer,
9
+ PushToHubCallback,
10
+ TFAutoModelForSequenceClassification,
11
+ )
12
 
13
+ output_dir = "out/model"
14
  checkpoint_path = "out/cp.ckpt"
15
 
16
  labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
 
58
  filepath=checkpoint_path, save_weights_only=True, verbose=1
59
  )
60
 
61
+ push_to_hub_callback = PushToHubCallback(
62
+ output_dir=output_dir,
63
+ tokenizer=tokenizer,
64
+ hub_model_id="ogtega/tweet-toxicity-classifier",
65
+ )
66
+
67
  model.compile(optimizer=Adam(3e-5), loss="categorical_crossentropy")
68
+ model.fit(tf_dataset, callbacks=[cp_callback, push_to_hub_callback])
 
tflow ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mkdir -p $HOME/dockerx/app
2
+ cp app $HOME/dockerx -r
3
+ sudo docker run \
4
+ -it \
5
+ --network=host \
6
+ --device=/dev/kfd \
7
+ --device=/dev/dri \
8
+ --ipc=host \
9
+ --shm-size 16G \
10
+ --group-add video \
11
+ --cap-add=SYS_PTRACE \
12
+ --security-opt seccomp=unconfined \
13
+ -v $HOME/dockerx:/dockerx \
14
+ rocm/tensorflow:latest