Spaces:
Sleeping
Sleeping
swastik-kapture
commited on
Commit
•
f3d8f6a
0
Parent(s):
Application files
Browse files
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Model to load
|
6 |
+
MODEL_TO_LOAD = "swastik-kapture/offenseval-xlmr"
|
7 |
+
TOKENIZER = "xlm-roberta-base"
|
8 |
+
|
9 |
+
# create classification pipeline
|
10 |
+
trained_model = pipeline("text-classification", model=MODEL_TO_LOAD, tokenizer=TOKENIZER)
|
11 |
+
|
12 |
+
# Streamlit App
|
13 |
+
def main():
|
14 |
+
# create a session state for conversation history
|
15 |
+
if 'conversation_history' not in st.session_state:
|
16 |
+
st.session_state.conversation_history = []
|
17 |
+
# streamlit title
|
18 |
+
st.title("OffensEval: Profanity Detection")
|
19 |
+
# user message
|
20 |
+
user_message = st.chat_input("Say something")
|
21 |
+
# if user input is present try to predict the outcome
|
22 |
+
if user_message:
|
23 |
+
# append user message to history
|
24 |
+
st.session_state.conversation_history.append(('user', user_message, time.time()))
|
25 |
+
# get predicted output
|
26 |
+
output = trained_model.predict(user_message)
|
27 |
+
# get predictied label and score
|
28 |
+
label = output[0]['label']
|
29 |
+
score = output[0]['score']
|
30 |
+
# default color
|
31 |
+
color = "white"
|
32 |
+
# get the color based on label
|
33 |
+
if label == "LABEL_0":
|
34 |
+
color = "green"
|
35 |
+
label = "No Offense"
|
36 |
+
elif label == "LABEL_1":
|
37 |
+
color = "red"
|
38 |
+
label = "Offensive"
|
39 |
+
st.session_state.conversation_history.append(('assistant', f"<div style='background-color: {color}; width: auto; height: 50px;'>Label: {label}; Score: {score:.2f}</div>", time.time()))
|
40 |
+
# Display chat history
|
41 |
+
for sender, message, timestamp in st.session_state.conversation_history:
|
42 |
+
with st.chat_message(sender):
|
43 |
+
st.write(message, unsafe_allow_html=True)
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.1.2
|
2 |
+
attrs==23.1.0
|
3 |
+
blinker==1.6.3
|
4 |
+
cachetools==5.3.1
|
5 |
+
certifi==2023.7.22
|
6 |
+
charset-normalizer==3.3.1
|
7 |
+
click==8.1.7
|
8 |
+
filelock==3.12.4
|
9 |
+
fsspec==2023.10.0
|
10 |
+
gitdb==4.0.11
|
11 |
+
GitPython==3.1.40
|
12 |
+
huggingface-hub==0.17.3
|
13 |
+
idna==3.4
|
14 |
+
importlib-metadata==6.8.0
|
15 |
+
Jinja2==3.1.2
|
16 |
+
jsonschema==4.19.1
|
17 |
+
jsonschema-specifications==2023.7.1
|
18 |
+
markdown-it-py==3.0.0
|
19 |
+
MarkupSafe==2.1.3
|
20 |
+
mdurl==0.1.2
|
21 |
+
mpmath==1.3.0
|
22 |
+
networkx==3.2
|
23 |
+
numpy==1.26.1
|
24 |
+
nvidia-cublas-cu12==12.1.3.1
|
25 |
+
nvidia-cuda-cupti-cu12==12.1.105
|
26 |
+
nvidia-cuda-nvrtc-cu12==12.1.105
|
27 |
+
nvidia-cuda-runtime-cu12==12.1.105
|
28 |
+
nvidia-cudnn-cu12==8.9.2.26
|
29 |
+
nvidia-cufft-cu12==11.0.2.54
|
30 |
+
nvidia-curand-cu12==10.3.2.106
|
31 |
+
nvidia-cusolver-cu12==11.4.5.107
|
32 |
+
nvidia-cusparse-cu12==12.1.0.106
|
33 |
+
nvidia-nccl-cu12==2.18.1
|
34 |
+
nvidia-nvjitlink-cu12==12.3.52
|
35 |
+
nvidia-nvtx-cu12==12.1.105
|
36 |
+
packaging==23.2
|
37 |
+
pandas==2.1.1
|
38 |
+
Pillow==10.1.0
|
39 |
+
protobuf==4.24.4
|
40 |
+
pyarrow==13.0.0
|
41 |
+
pydeck==0.8.1b0
|
42 |
+
Pygments==2.16.1
|
43 |
+
python-dateutil==2.8.2
|
44 |
+
pytz==2023.3.post1
|
45 |
+
PyYAML==6.0.1
|
46 |
+
referencing==0.30.2
|
47 |
+
regex==2023.10.3
|
48 |
+
requests==2.31.0
|
49 |
+
rich==13.6.0
|
50 |
+
rpds-py==0.10.6
|
51 |
+
safetensors==0.4.0
|
52 |
+
six==1.16.0
|
53 |
+
smmap==5.0.1
|
54 |
+
streamlit==1.27.2
|
55 |
+
sympy==1.12
|
56 |
+
tenacity==8.2.3
|
57 |
+
tokenizers==0.14.1
|
58 |
+
toml==0.10.2
|
59 |
+
toolz==0.12.0
|
60 |
+
torch==2.1.0
|
61 |
+
tornado==6.3.3
|
62 |
+
tqdm==4.66.1
|
63 |
+
transformers==4.34.1
|
64 |
+
triton==2.1.0
|
65 |
+
typing_extensions==4.8.0
|
66 |
+
tzdata==2023.3
|
67 |
+
tzlocal==5.2
|
68 |
+
urllib3==2.0.7
|
69 |
+
validators==0.22.0
|
70 |
+
watchdog==3.0.0
|
71 |
+
zipp==3.17.0
|
setup.sh
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
echo "\
|
3 |
+
[server]\n\
|
4 |
+
headless = true\n\
|
5 |
+
port = $PORT\n\
|
6 |
+
enableCORS = false\n\
|
7 |
+
\n\
|
8 |
+
" > ~/.streamlit/config.toml
|