File size: 690 Bytes
ea55b65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from joblib import load

st.title("Tabular Data Sentiment Analysis")

model = load('random_forest_model.joblib')

df = pd.DataFrame(
    [{'product_id': 30,
  'Review_Length': 252,
  'Rating': 4,
  'Avg_Word_Length': 5,
  'Times_purchased': 13,
  'unique_words': 40}])

edited_df = st.data_editor(df, num_rows="dynamic")

if st.button("Predict Sentiment", type="primary"):
    output = model.predict(edited_df)
    edited_df['predicted sentiment'] = output
    edited_df['predicted sentiment'].replace({0:"Positive", 1:"Negative"}, inplace=True)
    st.text(edited_df)