Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import yfinance as yf
|
|
@@ -38,8 +39,20 @@ def print_sentiment(stock_info):
|
|
| 38 |
df = get_sentiment_data(stock_info)
|
| 39 |
st.write("Market Sentiment")
|
| 40 |
st.dataframe(df, hide_index =True )
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def print_stock_info(stock_info):
|
| 45 |
stock_info_html = get_stock_info_from_html(stock_info.info)
|
|
@@ -52,7 +65,7 @@ def print_stock_info(stock_info):
|
|
| 52 |
with col2:
|
| 53 |
tf = st.radio(
|
| 54 |
"Select Time Frame",
|
| 55 |
-
["1Y", "3Y", "5Y"], index=2,
|
| 56 |
key="chart_time_frame",
|
| 57 |
)
|
| 58 |
|
|
@@ -73,7 +86,7 @@ def plot_graph(stock_info):
|
|
| 73 |
plt.title(f"{name} Stock Price")
|
| 74 |
return plt
|
| 75 |
|
| 76 |
-
st.title('
|
| 77 |
par1 = "It allows users to stay informed about the latest market trends and make informed decisions about their investments."
|
| 78 |
par2 = "To get started, simply select whether you want information on currencies or stocks:<br> "\
|
| 79 |
"<ul><li><strong>Currencies</strong><br>Choose from a wide range of currencies to view the latest exchange rates, historical data, and charts.</li>"\
|
|
@@ -89,7 +102,7 @@ if 'data_available' not in st.session_state:
|
|
| 89 |
st.session_state['data_available'] = False
|
| 90 |
|
| 91 |
|
| 92 |
-
option =
|
| 93 |
|
| 94 |
if option == "Currencies":
|
| 95 |
input_text = "Enter currency pair"
|
|
@@ -100,16 +113,16 @@ else:
|
|
| 100 |
text_box: str = None
|
| 101 |
btn_get_data = None
|
| 102 |
|
| 103 |
-
|
| 104 |
-
if option:
|
| 105 |
text_box = st.text_input(input_text)
|
| 106 |
-
|
| 107 |
with st.spinner('Wait for it...'):
|
| 108 |
if text_box:
|
| 109 |
ticker = text_box.upper()
|
| 110 |
try:
|
| 111 |
stock_info = yf.Ticker(ticker)
|
| 112 |
-
stock_info.info['longName']
|
|
|
|
| 113 |
except:
|
| 114 |
st.error('Ticker not found', icon="馃毃")
|
| 115 |
st.session_state['data_available'] = False
|
|
@@ -117,5 +130,7 @@ with st.spinner('Wait for it...'):
|
|
| 117 |
|
| 118 |
st.session_state['data_available'] = True
|
| 119 |
print_stock_info(stock_info)
|
| 120 |
-
print_sentiment(stock_info)
|
|
|
|
|
|
|
| 121 |
|
|
|
|
| 1 |
+
import time
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import yfinance as yf
|
|
|
|
| 39 |
df = get_sentiment_data(stock_info)
|
| 40 |
st.write("Market Sentiment")
|
| 41 |
st.dataframe(df, hide_index =True )
|
| 42 |
+
return df
|
| 43 |
|
| 44 |
+
def print_sentiment_summery(df) :
|
| 45 |
+
column_name = "sentiment"
|
| 46 |
+
category_counts = df[column_name].value_counts()
|
| 47 |
+
df_sentiment = pd.DataFrame({
|
| 48 |
+
"Sentiment": category_counts.index,
|
| 49 |
+
"Count": category_counts.values
|
| 50 |
+
})
|
| 51 |
+
st.dataframe(df_sentiment, hide_index =True )
|
| 52 |
+
return df_sentiment
|
| 53 |
+
|
| 54 |
+
# 讛爪讙转 DataFrame 讛讞讚砖
|
| 55 |
+
print(df_new.to_string())
|
| 56 |
|
| 57 |
def print_stock_info(stock_info):
|
| 58 |
stock_info_html = get_stock_info_from_html(stock_info.info)
|
|
|
|
| 65 |
with col2:
|
| 66 |
tf = st.radio(
|
| 67 |
"Select Time Frame",
|
| 68 |
+
["1Y", "3Y", "5Y", "10Y"], index=2,
|
| 69 |
key="chart_time_frame",
|
| 70 |
)
|
| 71 |
|
|
|
|
| 86 |
plt.title(f"{name} Stock Price")
|
| 87 |
return plt
|
| 88 |
|
| 89 |
+
st.title('_SentySense_') #PriceProphet, Sentyment, Trendsetter Bullseye
|
| 90 |
par1 = "It allows users to stay informed about the latest market trends and make informed decisions about their investments."
|
| 91 |
par2 = "To get started, simply select whether you want information on currencies or stocks:<br> "\
|
| 92 |
"<ul><li><strong>Currencies</strong><br>Choose from a wide range of currencies to view the latest exchange rates, historical data, and charts.</li>"\
|
|
|
|
| 102 |
st.session_state['data_available'] = False
|
| 103 |
|
| 104 |
|
| 105 |
+
option = 'Stocks' #st.selectbox("select", ["", "Currencies", "Stocks"], placeholder="Choose an option", label_visibility = "hidden")
|
| 106 |
|
| 107 |
if option == "Currencies":
|
| 108 |
input_text = "Enter currency pair"
|
|
|
|
| 113 |
text_box: str = None
|
| 114 |
btn_get_data = None
|
| 115 |
|
| 116 |
+
if option:
|
|
|
|
| 117 |
text_box = st.text_input(input_text)
|
| 118 |
+
|
| 119 |
with st.spinner('Wait for it...'):
|
| 120 |
if text_box:
|
| 121 |
ticker = text_box.upper()
|
| 122 |
try:
|
| 123 |
stock_info = yf.Ticker(ticker)
|
| 124 |
+
long_name = stock_info.info['longName']
|
| 125 |
+
st.write(f"<H4>{long_name}</H4>", unsafe_allow_html=True)
|
| 126 |
except:
|
| 127 |
st.error('Ticker not found', icon="馃毃")
|
| 128 |
st.session_state['data_available'] = False
|
|
|
|
| 130 |
|
| 131 |
st.session_state['data_available'] = True
|
| 132 |
print_stock_info(stock_info)
|
| 133 |
+
df = print_sentiment(stock_info)
|
| 134 |
+
st.write('Sentiment summery')
|
| 135 |
+
print_sentiment_summery(df)
|
| 136 |
|