Spaces:
Runtime error
Runtime error
| 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() |