Spaces:
Runtime error
Runtime error
pipeline
Browse files- app.py +27 -2
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -1,4 +1,29 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
x = st.slider('Select a value')
|
| 4 |
-
st.write(x, 'squared is', x * x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import safetensors
|
| 3 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 4 |
|
| 5 |
+
# x = st.slider('Select a value')
|
| 6 |
+
# st.write(x, 'squared is', x * x)
|
| 7 |
+
|
| 8 |
+
name = 'KoalaAI/Text-Moderation'
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained(name, num_labels=1, ignore_mismatched_sizes=True)
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(name)
|
| 11 |
+
|
| 12 |
+
d = {}
|
| 13 |
+
with safetensors.safe_open("model.safetensors", framework="pt", device='cpu') as f:
|
| 14 |
+
for k in f.keys():
|
| 15 |
+
d[k] = f.get_tensor(k)
|
| 16 |
+
|
| 17 |
+
model.load_state_dict(d)
|
| 18 |
+
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer, device='cpu')
|
| 19 |
+
|
| 20 |
+
text = st.text_area("enter the text")
|
| 21 |
+
|
| 22 |
+
if text:
|
| 23 |
+
out = pipe(text)
|
| 24 |
+
score = out['score'] * 4 - 2
|
| 25 |
+
if score >= 0.5:
|
| 26 |
+
label = 'not OK'
|
| 27 |
+
else:
|
| 28 |
+
label = 'OK'
|
| 29 |
+
st.json({'label' : label, 'score' : score})
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
safetensors
|