mattikris's picture
Create app.py
24aafee
raw
history blame
1.24 kB
import streamlit as st
st.markdown(""" This is a Streamlit App """)
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import chardet
from pathlib import Path
from detect_delimiter import detect
label_dict = {
0: "Brandsøgning",
1: "Informational",
2: "Inspiration",
3: "Navigational",
4: "Transactional"
}
upload_file = st.file_uploader("Choose a file",type="csv" )
model = pickle.load(open("finalized_model.sav","rb"))
if upload_file is not None:
result = chardet.detect(upload_file.getvalue())
encoding_value = result["encoding"]
if encoding_value == "UTF-16":
white_space = True
else:
white_space = False
df = pd.read_csv((upload_file), on_bad_lines='skip', encoding=encoding_value, delim_whitespace=white_space)
print(df)
result = {}
result['Keyword'] = df['Keyword'][:5000]
result['volume'] =df['Volume'][:5000]
classes = [label_dict[model.predict(item)[0][0]] for item in df['Keyword'].values[:5000]]
result['Classes'] = classes
df = pd.DataFrame(result)
st.download_button(
label="Download CSV file",
data=df.to_csv().encode('utf-8'),
file_name='labbeled_data.csv',
mime='text/csv'
)