Spaces:
Runtime error
Runtime error
# import s3fs | |
import pandas as pd | |
import numpy as np | |
from numpy import arange | |
from colour import Color | |
import plotly.graph_objects as go | |
from nltk import tokenize | |
from IPython.display import Markdown | |
from PIL import ImageColor | |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer | |
import nltk | |
nltk.download('punkt') | |
from io import StringIO | |
from scipy import spatial | |
import re | |
import pytorch_lightning as pl | |
from bs4 import BeautifulSoup | |
import ipywidgets as widgets | |
from ipywidgets import FileUpload | |
from urlextract import URLExtract | |
from transformers import BertTokenizerFast as BertTokenizer, BertModel, BertConfig | |
import torch.nn as nn | |
import torch | |
from ipywidgets import interact, Dropdown | |
import boto3 | |
# from sagemaker import get_execution_role | |
from scipy import spatial | |
from bokeh.models.widgets import Div | |
import streamlit as st | |
def get_files_from_aws(bucket,prefix): | |
""" | |
get files from aws s3 bucket | |
bucket (STRING): bucket name | |
prefix (STRING): file location in s3 bucket | |
""" | |
s3_client = boto3.client('s3', | |
aws_access_key_id = st.secrets["aws_id"], | |
aws_secret_access_key = st.secrets["aws_key"]) | |
file_obj = s3_client.get_object(Bucket=bucket,Key=prefix) | |
body = file_obj['Body'] | |
string = body.read().decode('utf-8') | |
df = pd.read_csv(StringIO(string)) | |
return df | |
def url_button(button_name,url): | |
if st.button(button_name): | |
js = """window.open('{url}')""".format(url=url) # New tab or window | |
html = '<img src onerror="{}">'.format(js) | |
div = Div(text=html) | |
st.bokeh_chart(div) | |
PARAMS={ | |
'BATCH_SIZE': 8, | |
'MAX_TOKEN_COUNT':100, | |
'BERT_MODEL_NAME':'google/bert_uncased_L-2_H-128_A-2' , | |
'N_EPOCHS': 10, | |
'n_classes':8, | |
'LABEL_COLUMNS': ['label_analytical', 'label_casual', 'label_confident', 'label_friendly', | |
'label_joyful', 'label_opstimistic', 'label_respectful', | |
'label_urgent'], | |
'TEXTCOL': 'text', | |
'rf_labels':['label_analytical', 'label_casual', 'label_confident', | |
'label_friendly', 'label_joyful', 'label_opstimistic', | |
'label_respectful', 'label_urgent', | |
'industry_Academic and Education', 'industry_Energy', | |
'industry_Entertainment', 'industry_Finance and Banking', | |
'industry_Healthcare', 'industry_Hospitality', 'industry_Real Estate', | |
'industry_Retail', 'industry_Software and Technology', | |
'campaign_type_Abandoned_Cart', 'campaign_type_Engagement', | |
'campaign_type_Newsletter', 'campaign_type_Product_Announcement', | |
'campaign_type_Promotional', 'campaign_type_Review_Request', | |
'campaign_type_Survey', 'campaign_type_Transactional', | |
'campaign_type_Usage_and_Consumption', 'campaign_type_Webinar'] | |
} | |