CoolFace
Apppublic

amoldwalunj/aspect_based_sentiment_analysis

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py47 linesDownload Raw Back to root
1import streamlit as st2from pyabsa import available_checkpoints3from pyabsa import ATEPCCheckpointManager4 5import os6#import tensorflow_hub as hub7import numpy as np8import pandas as pd9import json10 11checkpoint_map = available_checkpoints()12 13aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='english',14                                   auto_device=True  # False means load model on CPU15                                   )16 17 18 19def main():20    st.set_page_config(page_title="Aspect based sentiment Anslysis", page_icon=":smiley:", layout="wide")21    st.title("Aspect based sentiment Anslysis :smiley:")22 23 24 25    st.header("Aspect based sentiment Anslysis")26    st.write("Enter a review:")27    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.")28    input_string = st.text_input("")29 30    31    if st.button("Enter"):32        with st.spinner("Extracting aspects and sentiments..."):33            examples = []34            examples.append(input_string)35    36            inference_source = examples37            atepc_result = aspect_extractor.extract_aspect(inference_source=inference_source,  #38                                          pred_sentiment=True,  # Predict the sentiment of extracted aspect terms39                                          )40    41            st.write("Aspect and sentiment is:")42            for aspect, sentiment in zip(atepc_result[0]['aspect'], atepc_result[0]['sentiment']):43                st.write(aspect + ': ' + sentiment)44 45 46if __name__ == "__main__":47    main()