File size: 2,529 Bytes
79e1719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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')