forked from sunday004/ai4all_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (47 loc) · 1.49 KB
/
app.py
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
import math
import streamlit as st
import pandas as pd
import numpy as np
import joblib
from scraping import get_headlines
from prediction import headlines_to_input, predict
N_HEADLINES = 25
LINE_BREAK_COUNT = 3
PREDICTION_TEXTS = ("The market is not doing well today", "The market is doing well today")
def display_heading():
"""Start page content"""
st.title("Market sentiment for today")
st.markdown("""
Model that can provide stock market sentiment based on top news headlines
""")
st.header("News Headlines for today")
def display_headlines():
"""Display the scraped headlines"""
count = 0
headlines = get_headlines(N_HEADLINES)
columns = st.columns(N_HEADLINES)
headlines_display = headlines.copy()
while headlines_display:
columns = st.columns(2)
for col in columns:
if not headlines_display:
return headlines
with col:
st.text(headlines_display.pop())
return headlines
def display_prediction_button(headlines):
"""Event handler for prediction button"""
if st.button("Generate stock overview"):
# Get Vectorized input
data = headlines_to_input(headlines)
result = predict(data) # 0/1
# Display the result text
st.text(PREDICTION_TEXTS[result])
# Set the page title
st.set_page_config(page_title="Stock market sentiment")
display_heading()
st.text("")
headlines = display_headlines()
st.text("")
display_prediction_button(headlines)
st.text("")