poc / page_1.py
ryanrahmadifa
Added files
79e1719
raw
history blame
2.53 kB
import streamlit as st
import pandas as pd
from modules.data_preparation import prepare_df, plot_3dgraph
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
from modules.semantic import generateChartBar, generateWordCloud, filterPlace
st.title('Semantic Analysis for Price Trend Prediction - Crude Oil Futures')
st.header('Filter news based on categories and country/region')
# st.header(f'Data based on News Data')
# st.subheader(f'{datetime.now()}')
date_filter = st.slider(
"Date Filter",
value=(datetime(2024, 8, 4), datetime(2024,8,9)),
format="MM/DD/YY",
)
col1, col2 = st.columns(2)
with col1:
news_categories = st.multiselect("Select desired news categories",
["Macroeconomic & Geopolitics", "Crude Oil", "Light Ends", "Middle Distillates", "Heavy Distillates", "Other"],
["Macroeconomic & Geopolitics", "Crude Oil"])
with col2:
news_location = st.selectbox("Select desired mentioned location",
["North America","United States", "Russia", "Asia", "Europe"])
st.subheader('Tabular Data')
latest_news = prepare_df(pd.read_excel('evaluation.xlsx'), news_categories, date_filter)
df_news = pd.concat([latest_news], ignore_index=True).drop_duplicates(['headline'])
df_news = filterPlace(df_news, news_location)
df_mean = pd.DataFrame({
'headline' : ['MEAN OF SELECTED NEWS'],
'negative_score' : [df_news['negative_score'].mean()],
'neutral_score' : [df_news['neutral_score'].mean()],
'positive_score' : [df_news['positive_score'].mean()],
'topic_verification' : ['']
})
df_news_final = pd.concat([df_news, df_mean])
df_news_final.index = np.arange(1, len(df_news_final) + 1)
st.dataframe(df_news_final.iloc[:, : 9])
try:
st.plotly_chart(plot_3dgraph(df_news_final), use_container_width=True)
except:
st.subheader('Select news categories to plot 3D graph')
st.markdown('---')
viz1, viz2 = st.columns(2)
st.subheader('Top Word Frequency - Bar Chart')
bar_chart = generateChartBar(data=df_news,search_word='n', body=True)
st.plotly_chart(bar_chart)
st.markdown('---')
st.subheader('Top Word Frequency - Word Cloud')
wordcloud = generateWordCloud(data=df_news)
# Display the generated image:
fig, ax = plt.subplots()
ax.imshow(wordcloud, interpolation='bilinear')
ax.axis("off")
st.pyplot(fig)
st.markdown('---')
st.subheader('Other possible use cases:')
st.markdown('- Sentiments towards a company, country, or individual')