diff --git a/thronetalk-game-of-thrones-summarizer/app.py b/thronetalk-game-of-thrones-summarizer/app.py index d4fd586..1ad097d 100644 --- a/thronetalk-game-of-thrones-summarizer/app.py +++ b/thronetalk-game-of-thrones-summarizer/app.py @@ -18,11 +18,9 @@ import time import streamlit as st import pandas as pd -#import numpy as np import matplotlib.pyplot as plt -#from wordcloud import WordCloud from utils.model import Model -from utils.visualization_generator import VisualizationGenerator +from utils.visualization_generator import VisualizationGenerator, read_dataframe from utils.data_analysis import DataAnalysis import altair as alt @@ -78,7 +76,7 @@ def remove_zeros(lst): season_to = int(season_to) to_ep_no = int(to_ep_no) if submitted: - cleaned_data = pd.read_csv(f'{current_directory}/data/ouput_dialogues.csv') + cleaned_data = read_dataframe('ouput_dialogues.csv') data_analysis = DataAnalysis(cleaned_data) top_3_characters = data_analysis.get_top_n_characters( from_season=int(season_from), @@ -104,8 +102,6 @@ def remove_zeros(lst): int(to_ep_no) ) line_chart = vg.sentiment_analysis_visualization(characters) - line_chart = vg.sentiment_analysis_visualization(characters) - print(characters) chart = alt.Chart(line_chart).transform_fold( characters, as_=["character name", "value"] ).mark_line( @@ -144,7 +140,7 @@ def remove_zeros(lst): st.subheader(characters[i].capitalize()) st.pyplot(plots[i]) st.write("\n") - episodes_metadata_for_img_df = pd.read_csv('data/episodes_metadata.csv') + episodes_metadata_for_img_df = read_dataframe('episodes_metadata.csv') st.subheader(out_text_temp) #Summarizer def spinner_loading_summary(): diff --git a/thronetalk-game-of-thrones-summarizer/utils/__init__.py b/thronetalk-game-of-thrones-summarizer/utils/__init__.py index c8fb582..37f1ff5 100644 --- a/thronetalk-game-of-thrones-summarizer/utils/__init__.py +++ b/thronetalk-game-of-thrones-summarizer/utils/__init__.py @@ -11,6 +11,6 @@ Use these functions within your Streamlit app to enhance its capabilities. """ -from .visualization_generator import VisualizationGenerator +from .visualization_generator import VisualizationGenerator, read_dataframe from .model import Model from .data_analysis import DataAnalysis diff --git a/thronetalk-game-of-thrones-summarizer/utils/visualization_generator.py b/thronetalk-game-of-thrones-summarizer/utils/visualization_generator.py index 92e69a5..f8fd290 100644 --- a/thronetalk-game-of-thrones-summarizer/utils/visualization_generator.py +++ b/thronetalk-game-of-thrones-summarizer/utils/visualization_generator.py @@ -37,13 +37,24 @@ from nltk.stem import WordNetLemmatizer from wordcloud import WordCloud, STOPWORDS from sklearn.feature_extraction.text import TfidfVectorizer + nltk.download('punkt') nltk.download('wordnet') nltk.download('vader_lexicon') nltk.download('stopwords') nltk.download('omw-1.4') -data = pd.read_csv("data/ouput_dialogues.csv") +def read_dataframe(file_name): + '''Function to read dataframe for different environments. Used for tests + and app.py''' + file_data = None + try: + file_data = pd.read_csv(f'data/{file_name}') + except FileNotFoundError: + file_data = pd.read_csv(f'./thronetalk-game-of-thrones-summarizer/data/{file_name}') + return file_data + +data = read_dataframe('ouput_dialogues.csv') class VisualizationGenerator: """