File size: 1,241 Bytes
6cae882
d0231e4
6cae882
 
 
 
 
 
 
ebd52bf
6cae882
 
 
 
 
 
 
 
d7f8b52
6cae882
 
93bb550
6cae882
836b7a1
6cae882
 
d7f8b52
 
 
 
 
 
 
 
 
 
 
 
 
 
5b3d7f1
d0231e4
d7f8b52
 
5b3d7f1
da35522
d7f8b52
da35522
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
from snscrape.modules.twitter import TwitterProfileScraper
import pandas as pd
from Predict import *
from Scraper import *
from transformers import pipeline

# Model and pipeline
MODEL_PATH = 'danielcd99/multilanguage-toxicity-classifier'

def load_pipeline():
    pipe=pipeline(
    "text-classification",
    model=MODEL_PATH
    )
    return pipe

pipe = load_pipeline()


# Title and subtitle
st.title("Toxicity Detector")
st.subheader("This is an app for detecting toxicity in tweets written in portuguese. "
          "Write the username (without @) and select the number of tweets you want to check.")


# User information
with st.form(key='forms'):
    st.markdown(
        """#### Tweets are classified in:
- 0: Harmless
- 1: Toxic
        """)
    username = st.text_input(label='Username:')
    number_of_tweets = st.selectbox(
        'How many tweets do you want to check?',
        (5, 10, 20, 30))
    submit_button = st.form_submit_button(label='Analyze')

if submit_button:

    scraper = TwitterProfileScraper(username)
    tweets = get_tweets(scraper, number_of_tweets)
    predictions = get_predictions(tweets, pipe)
    
    
    st.table(pd.DataFrame({'tweet': tweets, 'toxic':predictions}))