Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
if "classifier" not in st.session_state:
|
5 |
+
st.session_state["classifier"] = pipeline("text-classification", "Intel/polite-guard")
|
6 |
+
|
7 |
+
st.text_input("Your text here:", key="name")
|
8 |
+
# st.session_state.name
|
9 |
+
|
10 |
+
if "result" not in st.session_state:
|
11 |
+
st.session_state["result"] = "No result yet"
|
12 |
+
|
13 |
+
def click_button():
|
14 |
+
output = st.session_state["classifier"](st.session_state.name)
|
15 |
+
print(output)
|
16 |
+
st.session_state["result"] = output[0]["label"]
|
17 |
+
|
18 |
+
st.button('Run', on_click=click_button)
|
19 |
+
|
20 |
+
text1 = st.text_area('Result: ', st.session_state["result"])
|