File size: 1,637 Bytes
5b0a40d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3306b9b
 
 
 
 
 
 
 
 
 
 
 
5b0a40d
 
 
 
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
import streamlit as st
from pyabsa import available_checkpoints
from pyabsa import ATEPCCheckpointManager

import os
#import tensorflow_hub as hub
import numpy as np
import pandas as pd
import json

checkpoint_map = available_checkpoints()

aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='english',
                                   auto_device=True  # False means load model on CPU
                                   )



def main():
    st.set_page_config(page_title="Aspect based sentiment Anslysis", page_icon=":smiley:", layout="wide")
    st.title("Aspect based sentiment Anslysis :smiley:")



    st.header("Aspect based sentiment Anslysis")
    st.write("Enter a review:")
    st.write("e.g. Purchased this for my device, it worked as advertised. You can never have too much phone memory, since I download a lot of stuff this was a no brainer for me.")
    input_string = st.text_input("")

    
    if st.button("Enter"):
        with st.spinner("Extracting aspects and sentiments..."):
            examples = []
            examples.append(input_string)
    
            inference_source = examples
            atepc_result = aspect_extractor.extract_aspect(inference_source=inference_source,  #
                                          pred_sentiment=True,  # Predict the sentiment of extracted aspect terms
                                          )
    
            st.write("Aspect and sentiment is:")
            for aspect, sentiment in zip(atepc_result[0]['aspect'], atepc_result[0]['sentiment']):
                st.write(aspect + ': ' + sentiment)


if __name__ == "__main__":
    main()