Spaces:
Sleeping
Sleeping
| # Renaming main.py to app.py for Hugging Face compatibility | |
| import streamlit as st | |
| import plotly.graph_objects as go | |
| import yfinance as yf | |
| import pandas as pd | |
| from datetime import datetime, timedelta | |
| from data_fetcher import get_stock_data, get_company_info | |
| from visualization import create_stock_chart, create_metrics_table | |
| import styles | |
| def main(): | |
| # Apply custom styles | |
| styles.apply_custom_styles() | |
| st.title("π Stock Analysis Terminal") | |
| # Stock Symbol Input | |
| symbol = st.text_input("Enter Stock Symbol (e.g., AAPL)", "").upper() | |
| if symbol: | |
| try: | |
| # Fetch stock data | |
| stock_data = get_stock_data(symbol) | |
| company_info = get_company_info(symbol) | |
| # Display company info | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader(company_info.get('longName', symbol)) | |
| st.write(f"Sector: {company_info.get('sector', 'N/A')}") | |
| with col2: | |
| st.metric( | |
| "Current Price", | |
| f"${stock_data['Close'].iloc[-1]:.2f}", | |
| f"{((stock_data['Close'].iloc[-1] / stock_data['Close'].iloc[-2]) - 1) * 100:.2f}%" | |
| ) | |
| # Stock Chart | |
| st.plotly_chart(create_stock_chart(stock_data, symbol), use_container_width=True) | |
| # Financial Metrics Table | |
| metrics_df = create_metrics_table(company_info) | |
| st.dataframe(metrics_df, use_container_width=True) | |
| # Download button for CSV | |
| csv = stock_data.to_csv(index=True) | |
| st.download_button( | |
| label="Download Data as CSV", | |
| data=csv, | |
| file_name=f"{symbol}_stock_data.csv", | |
| mime="text/csv" | |
| ) | |
| except Exception as e: | |
| st.error(f"Error retrieving data for {symbol}: {str(e)}") | |
| if __name__ == "__main__": | |
| main() | |