Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,129 +1,91 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
-
from
|
| 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 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
fig2.add_trace(go.Bar(x=df_billions.index.year, y=df_billions['Free Cash Flow'], name='Free CF', marker_color='#EF553B'))
|
| 93 |
-
# Updated Y-axis title
|
| 94 |
-
fig2.update_layout(barmode='group', yaxis_title=f"{curr} (in Billions)")
|
| 95 |
-
st.plotly_chart(fig2, use_container_width=True)
|
| 96 |
-
else:
|
| 97 |
-
st.warning("Financial history is unavailable for this ticker. Check if the ticker is correct.")
|
| 98 |
-
|
| 99 |
-
with tab2:
|
| 100 |
-
c1, c2 = st.columns(2)
|
| 101 |
-
with c1:
|
| 102 |
-
st.subheader("Key Health Flags")
|
| 103 |
-
flags = analyzer.check_red_flags()
|
| 104 |
-
if flags:
|
| 105 |
-
for f in flags:
|
| 106 |
-
if f['type'] == 'danger': st.error(f"β {f['msg']}")
|
| 107 |
-
elif f['type'] == 'warning': st.warning(f"β οΈ {f['msg']}")
|
| 108 |
-
else: st.success(f"β
{f['msg']}")
|
| 109 |
-
else:
|
| 110 |
-
st.info("No flags calculated (insufficient data).")
|
| 111 |
-
|
| 112 |
-
with c2:
|
| 113 |
-
st.subheader("Piotroski F-Score (9-Point Check)")
|
| 114 |
-
score, details = analyzer.calculate_piotroski_score()
|
| 115 |
-
color = "red" if score < 4 else "green" if score > 6 else "orange"
|
| 116 |
-
st.markdown(f"<h1 style='color:{color}'>{score}/9</h1>", unsafe_allow_html=True)
|
| 117 |
-
with st.expander("Score Breakdown (F1-F9)"):
|
| 118 |
-
for d in details: st.write(d)
|
| 119 |
-
|
| 120 |
-
with tab3:
|
| 121 |
-
st.subheader(f"About {analyzer.info.get('shortName', ticker_input)}")
|
| 122 |
-
st.write(summary['summary'])
|
| 123 |
-
st.markdown(f"**Website:** [Visit Company Site]({summary['website']})")
|
| 124 |
-
|
| 125 |
-
except Exception as e:
|
| 126 |
-
# Catch connection and broader Streamlit exceptions
|
| 127 |
-
st.error(f"A critical error occurred while processing the data: {str(e)}. Please check your network connection or try a different ticker.")
|
| 128 |
-
|
| 129 |
-
# End of app.py
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
+
from utils import fetch_financials, clean_financials
|
| 4 |
+
|
| 5 |
+
def plot_income(income_df, ticker_symbol):
|
| 6 |
+
fig = go.Figure()
|
| 7 |
+
|
| 8 |
+
# List of metrics we want to plot β change as per availability
|
| 9 |
+
metrics = [
|
| 10 |
+
"Total Revenue",
|
| 11 |
+
"Net Income Available to Common Shares"
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
for m in metrics:
|
| 15 |
+
if m in income_df.columns:
|
| 16 |
+
fig.add_trace(go.Bar(
|
| 17 |
+
x=income_df.index,
|
| 18 |
+
y=income_df[m] / 1e9, # convert to billions
|
| 19 |
+
name=m
|
| 20 |
+
))
|
| 21 |
+
|
| 22 |
+
fig.update_layout(
|
| 23 |
+
title=f"{ticker_symbol} Income Statement",
|
| 24 |
+
xaxis_title="Date",
|
| 25 |
+
yaxis_title="Value (in billions)",
|
| 26 |
+
barmode='group'
|
| 27 |
+
)
|
| 28 |
+
return fig
|
| 29 |
+
|
| 30 |
+
def plot_cashflow(cash_df, ticker_symbol):
|
| 31 |
+
fig = go.Figure()
|
| 32 |
+
|
| 33 |
+
metrics = [
|
| 34 |
+
"Total Cash From Operating Activities",
|
| 35 |
+
"Capital Expenditures",
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
for m in metrics:
|
| 39 |
+
if m in cash_df.columns:
|
| 40 |
+
vals = cash_df[m]
|
| 41 |
+
# If CapEx, often negative -> make positive for bar
|
| 42 |
+
if "Capital Expenditures" in m:
|
| 43 |
+
vals = -vals
|
| 44 |
+
fig.add_trace(go.Bar(
|
| 45 |
+
x=cash_df.index,
|
| 46 |
+
y=vals / 1e9,
|
| 47 |
+
name=m
|
| 48 |
+
))
|
| 49 |
+
|
| 50 |
+
fig.update_layout(
|
| 51 |
+
title=f"{ticker_symbol} Cash Flow Statement",
|
| 52 |
+
xaxis_title="Date",
|
| 53 |
+
yaxis_title="Value (in billions)",
|
| 54 |
+
barmode='group'
|
| 55 |
+
)
|
| 56 |
+
return fig
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def main():
|
| 60 |
+
st.title("Financial Dashboard")
|
| 61 |
+
|
| 62 |
+
ticker_symbol = st.text_input("Ticker Symbol", "AAPL")
|
| 63 |
+
|
| 64 |
+
if st.button("Refresh Data"):
|
| 65 |
+
with st.spinner("Fetching data..."):
|
| 66 |
+
income, cash = fetch_financials(ticker_symbol, freq="annual")
|
| 67 |
+
|
| 68 |
+
if income.empty and cash.empty:
|
| 69 |
+
st.error("No financial data returned. Check ticker or try again.")
|
| 70 |
+
return
|
| 71 |
+
|
| 72 |
+
income_clean = clean_financials(income)
|
| 73 |
+
cash_clean = clean_financials(cash)
|
| 74 |
+
|
| 75 |
+
st.subheader("Income Statement")
|
| 76 |
+
fig_income = plot_income(income_clean, ticker_symbol)
|
| 77 |
+
st.plotly_chart(fig_income, use_container_width=True)
|
| 78 |
+
|
| 79 |
+
st.subheader("Cash Flow")
|
| 80 |
+
fig_cash = plot_cashflow(cash_clean, ticker_symbol)
|
| 81 |
+
st.plotly_chart(fig_cash, use_container_width=True)
|
| 82 |
+
|
| 83 |
+
st.write("### Raw Data β Income Statement")
|
| 84 |
+
st.dataframe(income_clean)
|
| 85 |
+
|
| 86 |
+
st.write("### Raw Data β Cash Flow")
|
| 87 |
+
st.dataframe(cash_clean)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|