Gregoryjr
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,23 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
st.title("Milestone #2 v2")
|
| 5 |
-
text = st.text_input("
|
| 6 |
|
| 7 |
-
options = ["zero-shot-classification", "cardiffnlp/twitter-roberta-base-offensive"
|
| 8 |
-
model = st.selectbox("Select
|
| 9 |
|
| 10 |
-
con = st.button("
|
| 11 |
if con:
|
| 12 |
if model == "zero-shot-classification":
|
| 13 |
classifier = pipeline(model)
|
| 14 |
res = classifier(text, candidate_labels=["offensive"])
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
if model == "cardiffnlp/twitter-roberta-base-offensive":
|
| 18 |
classifier = pipeline('text-classification', model='cardiffnlp/twitter-roberta-base-offensive', tokenizer='cardiffnlp/twitter-roberta-base-offensive')
|
| 19 |
result = classifier(text)
|
| 20 |
-
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
st.title("Milestone #2 v2")
|
| 5 |
+
text = st.text_input("Enter a statement")
|
| 6 |
|
| 7 |
+
options = ["zero-shot-classification", "cardiffnlp/twitter-roberta-base-offensive"]
|
| 8 |
+
model = st.selectbox("Select a model", options)
|
| 9 |
|
| 10 |
+
con = st.button("Submit")
|
| 11 |
if con:
|
| 12 |
if model == "zero-shot-classification":
|
| 13 |
classifier = pipeline(model)
|
| 14 |
res = classifier(text, candidate_labels=["offensive"])
|
| 15 |
+
label = res['labels'][0]
|
| 16 |
+
score = res['scores'][0]
|
| 17 |
+
st.write(f"Prediction: {label}, Score: {score:.2f}")
|
| 18 |
|
| 19 |
if model == "cardiffnlp/twitter-roberta-base-offensive":
|
| 20 |
classifier = pipeline('text-classification', model='cardiffnlp/twitter-roberta-base-offensive', tokenizer='cardiffnlp/twitter-roberta-base-offensive')
|
| 21 |
result = classifier(text)
|
| 22 |
+
label = result[0]['label']
|
| 23 |
+
score = result[0]['score']
|
| 24 |
+
st.write(f"Prediction: {label}, Score: {score:.2f}")
|