Maiawen's picture
Upload app.py
15e5199 verified
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# Checking directory
import os
# 获取当前文件的绝对路径
current_file_path = os.path.abspath(__file__)
# 获取当前文件所在目录
current_directory = os.path.dirname(current_file_path)
# 设置为工作路径
os.chdir(current_directory)
import streamlit as st
st.title('Huayra- Restaurant Comment app')
st.title("Introduction about the Dataset")
st.write("A dataset of restaurant reviews with 10000 rows and 8 columns.")
st.write("The dataset has 10000 rows and 8 columns.")
st.write("Try to perform NLP by using the 'Review' and 'Rating' columns.")
st.write("Try sentiment analysis by considering rating above 3 as 'Positive' and below 3 as 'Negative'.")
st.write("Source: https://github.com/manthanpatel98/Restaurant-Review-Sentiment-Analysis/tree/master")
# 读取数据
df=pd.read_csv("data.csv")
# 创建图表
fig, ax = plt.subplots(figsize=(6, 4))
df['Rating'].hist(bins=50, ax=ax)
# 添加标题
ax.set_title('Histogram of Rating')
# 添加 X 轴标签
ax.set_xlabel('Rating')
# 添加 Y 轴标签
ax.set_ylabel('Frequency')
# 在 streamlit 中显示图表
st.pyplot(fig)
# 执行数据处理步骤
data = df.copy()
df = df[['Review', 'Rating']].copy()
df = df.rename(columns={'Review': 'text', 'Rating': 'label'})
st.title('Data Overview')
# 在 streamlit 中展示表格
st.dataframe(df)
st.title('Table Selection')
# 选择标签的下拉列表
selected_label = st.selectbox('Choose label', df['label'].unique())
# 根据选择的标签过滤数据并显示表格
filtered_df = df[df['label'] == selected_label]
st.table(filtered_df.head(3))
# This function returns sentiment value based on:
# label <= 3.0 -> Negative
# label > 3.0 -> Positive
df=pd.read_csv("label.csv")
st.title("Wordcloud")
image_path = "wordclouds.png"
st.image(image_path)
result=pd.read_csv("result.csv")
st.write("The prediction result of the classifiers are as follows:")
st.table(result)
st.title("LDA Analysis")
st.write("The visualization of the theme of the positive reviews")
image_path = "lda_positive.png"
st.image(image_path)
st.write("Hierarchical Clustering of the positive reviews")
image_path = "hc_positive.png"
st.image(image_path)
st.write("Similarity Matrix of the positive reviews")
image_path = "similarity_positive.png"
st.image(image_path)
st.write("The visualization of the theme of the negative reviews")
image_path = "lda_negative.png"
st.image(image_path)
st.write("Hierarchical Clustering of the negative reviews")
image_path = "hc_negative.png"
st.image(image_path)
st.write("Similarity Matrix of the negative reviews")
image_path = "similarity_negative.png"
st.image(image_path)