Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -322,10 +322,10 @@ with news_analysis:
|
|
| 322 |
figure = go.Figure(data=[line_stock], layout=layout)
|
| 323 |
figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
|
| 324 |
marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
|
| 325 |
-
customdata=plot_sub_pos['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
|
| 326 |
figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
|
| 327 |
marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
|
| 328 |
-
customdata=plot_sub_neg['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
|
| 329 |
figure.update_layout(
|
| 330 |
title={
|
| 331 |
'text': title,
|
|
@@ -356,31 +356,37 @@ with news_analysis:
|
|
| 356 |
figure.update_yaxes(fixedrange=False)
|
| 357 |
st.plotly_chart(figure)
|
| 358 |
|
| 359 |
-
|
|
|
|
| 360 |
|
| 361 |
-
pos_news = plot_sub_pos[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
|
| 362 |
-
neg_news = plot_sub_neg[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
|
| 363 |
|
| 364 |
cols = ['Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']
|
| 365 |
for col in cols:
|
| 366 |
-
|
| 367 |
-
|
|
|
|
| 368 |
# Extract only the date part
|
| 369 |
-
|
| 370 |
-
|
|
|
|
| 371 |
# Sort DataFrame based on the 'Date' column in descending order
|
| 372 |
-
|
| 373 |
-
|
|
|
|
| 374 |
|
| 375 |
# Reset index to reflect the new order
|
| 376 |
-
|
| 377 |
-
|
|
|
|
| 378 |
st.subheader("News Events")
|
| 379 |
# st.dataframe(news, hide_index=True)
|
| 380 |
# st.table(news)
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
|
|
|
| 384 |
dates = np.sort(dates)
|
| 385 |
# Reverse the array to have the latest date at index 0
|
| 386 |
dates = dates[::-1]
|
|
@@ -389,62 +395,87 @@ with news_analysis:
|
|
| 389 |
items_per_page = min(num_dates, 5)
|
| 390 |
for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='news_pages'):
|
| 391 |
st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
|
| 449 |
st.markdown("""
|
| 450 |
<div style='background-color:#b43c42; color:#ffffff; padding:8px; border-radius:3px; font-size:12px''>
|
|
@@ -687,10 +718,10 @@ with final_recs:
|
|
| 687 |
figure = go.Figure(data=[line_stock], layout=layout)
|
| 688 |
figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
|
| 689 |
marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
|
| 690 |
-
customdata=plot_sub_pos['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
|
| 691 |
figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
|
| 692 |
marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
|
| 693 |
-
customdata=plot_sub_neg['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
|
| 694 |
figure.update_layout(
|
| 695 |
title={
|
| 696 |
'text': title,
|
|
|
|
| 322 |
figure = go.Figure(data=[line_stock], layout=layout)
|
| 323 |
figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
|
| 324 |
marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
|
| 325 |
+
customdata=set(plot_sub_pos['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
|
| 326 |
figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
|
| 327 |
marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
|
| 328 |
+
customdata=set(plot_sub_neg['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
|
| 329 |
figure.update_layout(
|
| 330 |
title={
|
| 331 |
'text': title,
|
|
|
|
| 356 |
figure.update_yaxes(fixedrange=False)
|
| 357 |
st.plotly_chart(figure)
|
| 358 |
|
| 359 |
+
news = events[events['Date'].between(start_date, end_date, inclusive='both')]
|
| 360 |
+
news = news[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
|
| 361 |
|
| 362 |
+
# pos_news = plot_sub_pos[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
|
| 363 |
+
# neg_news = plot_sub_neg[['Date', 'Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']]
|
| 364 |
|
| 365 |
cols = ['Raw_Headline', 'Bold_KW', 'Feature', 'Raw_News', 'Sources', 'Urls']
|
| 366 |
for col in cols:
|
| 367 |
+
news[col] = news[col].apply(convert_str_to_list)
|
| 368 |
+
# pos_news[col] = pos_news[col].apply(convert_str_to_list)
|
| 369 |
+
# neg_news[col] = neg_news[col].apply(convert_str_to_list)
|
| 370 |
# Extract only the date part
|
| 371 |
+
news['Date'] = news['Date'].dt.date
|
| 372 |
+
# neg_news['Date'] = neg_news['Date'].dt.date
|
| 373 |
+
# pos_news['Date'] = pos_news['Date'].dt.date
|
| 374 |
# Sort DataFrame based on the 'Date' column in descending order
|
| 375 |
+
news = news.sort_values(by='Date', ascending=False)
|
| 376 |
+
# neg_news = neg_news.sort_values(by='Date', ascending=False)
|
| 377 |
+
# pos_news = pos_news.sort_values(by='Date', ascending=False)
|
| 378 |
|
| 379 |
# Reset index to reflect the new order
|
| 380 |
+
news.reset_index(drop=True, inplace=True)
|
| 381 |
+
# pos_news.reset_index(drop=True, inplace=True)
|
| 382 |
+
# neg_news.reset_index(drop=True, inplace=True)
|
| 383 |
st.subheader("News Events")
|
| 384 |
# st.dataframe(news, hide_index=True)
|
| 385 |
# st.table(news)
|
| 386 |
+
dates = list(news['Date'].unique())
|
| 387 |
+
# dates_neg = list(neg_news['Date'].unique())
|
| 388 |
+
# dates_pos = list(pos_news['Date'].unique())
|
| 389 |
+
# dates = dates_pos + dates_neg
|
| 390 |
dates = np.sort(dates)
|
| 391 |
# Reverse the array to have the latest date at index 0
|
| 392 |
dates = dates[::-1]
|
|
|
|
| 395 |
items_per_page = min(num_dates, 5)
|
| 396 |
for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='news_pages'):
|
| 397 |
st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
|
| 398 |
+
filtered_news = news[news['Date'] == date]
|
| 399 |
+
print(filtered_news.shape)
|
| 400 |
+
features = filtered_news['Feature'].sum()
|
| 401 |
+
headlines = filtered_news['Raw_Headline'].sum()
|
| 402 |
+
news_list = filtered_news['Raw_News'].sum()
|
| 403 |
+
sources = filtered_news['Sources'].sum()
|
| 404 |
+
urls = filtered_news['Urls'].sum()
|
| 405 |
+
|
| 406 |
+
main_container = st.container(height = 250, border=True)
|
| 407 |
+
# main_container.write(f"Date: {date}")
|
| 408 |
|
| 409 |
+
col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
|
| 410 |
+
|
| 411 |
+
# Merge lists of headlines into a single list
|
| 412 |
+
for index, headline in enumerate(headlines):
|
| 413 |
+
col1.page_link(urls[index], label=f"**:blue[{headline}]**")
|
| 414 |
+
# col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
|
| 415 |
+
col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
|
| 416 |
+
with col1:
|
| 417 |
+
with st.expander("Show Full Article"):
|
| 418 |
+
st.write(news_list[index])
|
| 419 |
+
|
| 420 |
+
with col2:
|
| 421 |
+
# st.divider()
|
| 422 |
+
with st.expander("Oil Sector Features"):
|
| 423 |
+
st.write(set(features))
|
| 424 |
+
# if date in dates_pos:
|
| 425 |
+
# filtered_news = pos_news[pos_news['Date'] == date]
|
| 426 |
+
# print(filtered_news.shape)
|
| 427 |
+
# features = filtered_news['Feature'].sum()
|
| 428 |
+
# headlines = filtered_news['Raw_Headline'].sum()
|
| 429 |
+
# news_list = filtered_news['Raw_News'].sum()
|
| 430 |
+
# sources = filtered_news['Sources'].sum()
|
| 431 |
+
# urls = filtered_news['Urls'].sum()
|
| 432 |
+
|
| 433 |
+
# main_container = st.container(height = 250, border=True)
|
| 434 |
+
# # main_container.write(f"Date: {date}")
|
| 435 |
|
| 436 |
+
# col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
|
| 437 |
+
|
| 438 |
+
# # Merge lists of headlines into a single list
|
| 439 |
+
# for index, headline in enumerate(headlines):
|
| 440 |
+
# col1.page_link(urls[index], label=f"**:blue[{headline}]**")
|
| 441 |
+
# # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
|
| 442 |
+
# col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
|
| 443 |
+
# with col1:
|
| 444 |
+
# with st.expander("Show Full Article"):
|
| 445 |
+
# st.write(news_list[index])
|
| 446 |
+
|
| 447 |
+
# with col2:
|
| 448 |
+
# # st.divider()
|
| 449 |
+
# with st.expander("Oil Sector Features"):
|
| 450 |
+
# st.write(set(features))
|
| 451 |
|
| 452 |
+
# if date in dates_neg:
|
| 453 |
+
# filtered_news = neg_news[neg_news['Date'] == date]
|
| 454 |
+
# print(filtered_news.shape)
|
| 455 |
+
# features = filtered_news['Feature'].sum()
|
| 456 |
+
# headlines = filtered_news['Raw_Headline'].sum()
|
| 457 |
+
# news_list = filtered_news['Raw_News'].sum()
|
| 458 |
+
# sources = filtered_news['Sources'].sum()
|
| 459 |
+
# urls = filtered_news['Urls'].sum()
|
| 460 |
+
|
| 461 |
+
# main_container = st.container(height = 250, border=True)
|
| 462 |
+
# # main_container.write(f"Date: {date}")
|
| 463 |
|
| 464 |
+
# col1, col2 = main_container.columns([0.7, 0.3], gap='medium')
|
| 465 |
+
|
| 466 |
+
# # Merge lists of headlines into a single list
|
| 467 |
+
# for index, headline in enumerate(headlines):
|
| 468 |
+
# col1.page_link(urls[index], label=f"**:blue[{headline}]**")
|
| 469 |
+
# # col1.write(f"<span style='font-size: large;'><b><u>{headline}</u></b></span>", unsafe_allow_html=True)
|
| 470 |
+
# col1.write(f"<span style='font-size: small;'>By {sources[index]}</span><br>", unsafe_allow_html=True)
|
| 471 |
+
# with col1:
|
| 472 |
+
# with st.expander("Show Full Article"):
|
| 473 |
+
# st.write(news_list[index])
|
| 474 |
+
|
| 475 |
+
# with col2:
|
| 476 |
+
# # st.divider()
|
| 477 |
+
# with st.expander("Oil Sector Features"):
|
| 478 |
+
# st.write(set(features))
|
| 479 |
|
| 480 |
st.markdown("""
|
| 481 |
<div style='background-color:#b43c42; color:#ffffff; padding:8px; border-radius:3px; font-size:12px''>
|
|
|
|
| 718 |
figure = go.Figure(data=[line_stock], layout=layout)
|
| 719 |
figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
|
| 720 |
marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
|
| 721 |
+
customdata=set(plot_sub_pos['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
|
| 722 |
figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
|
| 723 |
marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
|
| 724 |
+
customdata=set(plot_sub_neg['Feature']), hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
|
| 725 |
figure.update_layout(
|
| 726 |
title={
|
| 727 |
'text': title,
|