File size: 909 Bytes
7f8de92
 
0934d02
21e7801
17bb76c
0f64e73
17bb76c
 
0f64e73
17bb76c
854d0de
a2a9b24
 
0934d02
17bb76c
 
 
a2a9b24
 
 
34b533c
17bb76c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import streamlit as st
from transformers import pipeline 

st.title("Milestone #2")
text = st.text_input("Enter a statement")

options = ["zero-shot-classification", "cardiffnlp/twitter-roberta-base-offensive"]
model = st.selectbox("Select a model", options)

con = st.button("Submit")
if con:
  if model == "zero-shot-classification":
    classifier = pipeline(model)
    res = classifier(text, candidate_labels=["offensive"])
    label = res['labels'][0]
    score = res['scores'][0]
    st.write(f"Prediction: {label}, Score: {score:.2f}")
  
  if model == "cardiffnlp/twitter-roberta-base-offensive":
    classifier = pipeline('text-classification', model='cardiffnlp/twitter-roberta-base-offensive', tokenizer='cardiffnlp/twitter-roberta-base-offensive')
    result = classifier(text)
    label = result[0]['label']
    score = result[0]['score']
    st.write(f"Prediction: {label}, Score: {score:.2f}")