File size: 2,088 Bytes
9b2f5f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50

import streamlit as st 
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
from transformers import pipeline


def multilingualmodel():
    st.markdown("# multilingual model 🎈")
    st.sidebar.markdown("# nlptown/bert-base-multilingual-uncased-sentiment🎈")
    st.write("This classifier can now deal with texts in English, French, but also Dutch, German, Italian and Spanish!")
    classifier = pipeline('sentiment-analysis')
    model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
    model = TFAutoModelForSequenceClassification.from_pretrained(model_name, from_pt=True)
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
    user_input = st.text_area('Enter Text to Analyze')
    button = st.button("Analyze")
    if user_input and button :
      tt = classifier(user_input)
      st.write(tt)
      for result in tt:
        st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}")


def engdistilbertmod():
    st.markdown("distilbert base finetuned english ❄️")
    st.sidebar.markdown("# distilbert-base-uncased-finetuned-sst-2-english ❄️")
    model_name = "distilbert-base-uncased-finetuned-sst-2-english"
    tf_model = TFAutoModelForSequenceClassification.from_pretrained(model_name)
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    classifier = pipeline('sentiment-analysis', model=tf_model, tokenizer=tokenizer)

    user_input = st.text_area('Enter Text to Analyze With distilbert ', key= "distilbert_input")
    button = st.button("Analyze", key= "distilbert_button")

    if user_input and button :
        tt = classifier(user_input)
        for result in tt:
            st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}")


page_names_to_funcs = {
    "Bert-base-Multilingual": multilingualmodel,
    "Distilbert base": engdistilbertmod,
}

selected_page = st.sidebar.selectbox("Select a page", page_names_to_funcs.keys())
page_names_to_funcs[selected_page]()