Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,81 +12,8 @@ from transformers import pipeline
|
|
12 |
import torch
|
13 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
14 |
|
15 |
-
# App title
|
16 |
-
st.markdown('''
|
17 |
-
# Sovrenn Market Sentiment Indicator App
|
18 |
-
Shown are the stock price data for the selected company!
|
19 |
-
**Credits**
|
20 |
-
- App built by SRL
|
21 |
-
''')
|
22 |
-
st.write('---')
|
23 |
-
|
24 |
-
# Sidebar
|
25 |
-
st.sidebar.subheader('Query parameters')
|
26 |
-
start_date = st.sidebar.date_input("Start date", datetime.date(2023,9, 20))
|
27 |
-
#start_date = start_date - datetime.timedelta(days=1)
|
28 |
-
end_date = start_date + datetime.timedelta(days=14)
|
29 |
-
|
30 |
-
# User input for the stock ticker symbol
|
31 |
-
tickerSymbol = st.sidebar.text_input('Enter Stock Ticker Symbol')
|
32 |
-
|
33 |
-
if tickerSymbol:
|
34 |
-
tickerData = yf.Ticker(tickerSymbol) # Get ticker data
|
35 |
-
tickerDf = tickerData.history(period='1d', start=start_date, end=end_date) # Get the historical prices for this ticker
|
36 |
-
|
37 |
-
string_name = tickerData.info.get('longName', 'Company Name Not Available')
|
38 |
-
st.header('**%s**' % string_name)
|
39 |
-
|
40 |
-
# Try to get the business summary, handle KeyError if not available
|
41 |
-
try:
|
42 |
-
string_summary = tickerData.info['longBusinessSummary']
|
43 |
-
st.info(string_summary)
|
44 |
-
except KeyError:
|
45 |
-
st.warning("Business summary not available for this company.")
|
46 |
-
|
47 |
-
# Ticker data
|
48 |
-
st.header('**Ticker data**')
|
49 |
-
st.write(tickerDf)
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
# Create a candlestick chart and volume bar chart
|
54 |
-
fig_candlestick = go.Figure(data=[go.Candlestick(x=tickerDf.index,
|
55 |
-
open=tickerDf['Open'],
|
56 |
-
high=tickerDf['High'],
|
57 |
-
low=tickerDf['Low'],
|
58 |
-
close=tickerDf['Close'])])
|
59 |
-
|
60 |
-
fig_volume = go.Figure(data=[go.Bar(x=tickerDf.index, y=tickerDf['Volume'])])
|
61 |
-
|
62 |
-
st.header('**Candlestick Chart**')
|
63 |
-
st.plotly_chart(fig_candlestick)
|
64 |
-
|
65 |
-
st.header('**Volume Bar Chart**')
|
66 |
-
st.plotly_chart(fig_volume)
|
67 |
-
|
68 |
-
|
69 |
-
st.write(start_date)
|
70 |
-
tickerDf = pd.DataFrame(tickerDf).reset_index()
|
71 |
-
|
72 |
-
# st.write(tickerDf)
|
73 |
-
|
74 |
-
#date = datetime.date(start_date)
|
75 |
-
date_str = start_date.strftime("%Y-%m-%d")
|
76 |
-
st.write(date_str)
|
77 |
-
df = tickerDf[tickerDf["Date"]==date_str]
|
78 |
-
st.write(df)
|
79 |
-
|
80 |
-
if (df["Close"][0] > df["Open"][0] ):
|
81 |
-
st.write("NSE has uptrend on " +date_str )
|
82 |
-
if (df["Close"][0] < df["Open"][0] ):
|
83 |
-
st.write(" NSE has downdtrend on " +date_str )
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
|
|
90 |
d0 = start_date
|
91 |
d1 = datetime.date(2008, 1, 1)
|
92 |
delta = d0 - d1
|
@@ -113,10 +40,91 @@ if tickerSymbol:
|
|
113 |
headlines.append(target_element.text)
|
114 |
except:
|
115 |
continue
|
|
|
116 |
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
|
|
120 |
index = [idx for idx, s in enumerate(headlines) if s=='Most Read' ][0]
|
121 |
del headlines[index:]
|
122 |
news = pd.DataFrame({"News": headlines})
|
|
|
12 |
import torch
|
13 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
def scrapper (start_date):
|
17 |
d0 = start_date
|
18 |
d1 = datetime.date(2008, 1, 1)
|
19 |
delta = d0 - d1
|
|
|
40 |
headlines.append(target_element.text)
|
41 |
except:
|
42 |
continue
|
43 |
+
return headlines
|
44 |
|
45 |
|
46 |
+
# App title
|
47 |
+
st.markdown('''
|
48 |
+
# Sovrenn Market Sentiment Indicator App
|
49 |
+
Shown are the stock price data for the selected company!
|
50 |
+
**Credits**
|
51 |
+
- App built by SRL
|
52 |
+
''')
|
53 |
+
st.write('---')
|
54 |
+
|
55 |
+
# Sidebar
|
56 |
+
st.sidebar.subheader('Query parameters')
|
57 |
+
start_date = st.sidebar.date_input("Start date", datetime.date(2023,9, 20))
|
58 |
+
#start_date = start_date - datetime.timedelta(days=1)
|
59 |
+
end_date = start_date + datetime.timedelta(days=14)
|
60 |
+
|
61 |
+
# User input for the stock ticker symbol
|
62 |
+
tickerSymbol = st.sidebar.text_input('Enter Stock Ticker Symbol')
|
63 |
|
64 |
+
if tickerSymbol:
|
65 |
+
try:
|
66 |
+
tickerData = yf.Ticker(tickerSymbol) # Get ticker data
|
67 |
+
tickerDf = tickerData.history(period='1d', start=start_date, end=end_date) # Get the historical prices for this ticker
|
68 |
+
|
69 |
+
string_name = tickerData.info.get('longName', 'Company Name Not Available')
|
70 |
+
st.header('**%s**' % string_name)
|
71 |
+
|
72 |
+
# Try to get the business summary, handle KeyError if not available
|
73 |
+
try:
|
74 |
+
string_summary = tickerData.info['longBusinessSummary']
|
75 |
+
st.info(string_summary)
|
76 |
+
except KeyError:
|
77 |
+
st.warning("Business summary not available for this company.")
|
78 |
+
|
79 |
+
# Ticker data
|
80 |
+
st.header('**Ticker data**')
|
81 |
+
st.write(tickerDf)
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
# Create a candlestick chart and volume bar chart
|
86 |
+
fig_candlestick = go.Figure(data=[go.Candlestick(x=tickerDf.index,
|
87 |
+
open=tickerDf['Open'],
|
88 |
+
high=tickerDf['High'],
|
89 |
+
low=tickerDf['Low'],
|
90 |
+
close=tickerDf['Close'])])
|
91 |
+
|
92 |
+
fig_volume = go.Figure(data=[go.Bar(x=tickerDf.index, y=tickerDf['Volume'])])
|
93 |
+
|
94 |
+
st.header('**Candlestick Chart**')
|
95 |
+
st.plotly_chart(fig_candlestick)
|
96 |
+
|
97 |
+
st.header('**Volume Bar Chart**')
|
98 |
+
st.plotly_chart(fig_volume)
|
99 |
+
|
100 |
+
|
101 |
+
st.write(start_date)
|
102 |
+
tickerDf = pd.DataFrame(tickerDf).reset_index()
|
103 |
+
|
104 |
+
# st.write(tickerDf)
|
105 |
+
|
106 |
+
#date = datetime.date(start_date)
|
107 |
+
date_str = start_date.strftime("%Y-%m-%d")
|
108 |
+
st.write(date_str)
|
109 |
+
df = tickerDf[tickerDf["Date"]==date_str]
|
110 |
+
st.write(df)
|
111 |
+
|
112 |
+
if (df["Close"][0] > df["Open"][0] ):
|
113 |
+
st.write("NSE has uptrend on " +date_str )
|
114 |
+
if (df["Close"][0] < df["Open"][0] ):
|
115 |
+
st.write(" NSE has downdtrend on " +date_str )
|
116 |
+
except:
|
117 |
+
st.write("Stock Data of this Index on the selected Date is not available \n")
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
|
127 |
+
headlines = scrapper(start_date)
|
128 |
index = [idx for idx, s in enumerate(headlines) if s=='Most Read' ][0]
|
129 |
del headlines[index:]
|
130 |
news = pd.DataFrame({"News": headlines})
|