From 5908db97c53b5b09f1e949fcc9578d5c5b8c1ef3 Mon Sep 17 00:00:00 2001 From: wleong1 Date: Sun, 7 Apr 2024 19:19:59 +0100 Subject: [PATCH] Testing streamlit deploy --- requirements.txt | 42 +++++++++++++++++++++++++++++++++++++++++- streamlit_app.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) mode change 100644 => 100755 requirements.txt create mode 100644 streamlit_app.py diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 index 41bb6e1..1a291d9 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,40 @@ +altair==5.3.0 appdirs==1.4.4 asgiref==3.7.2 +attrs==23.2.0 beautifulsoup4==4.12.3 +blinker==1.7.0 +cachetools==5.3.3 certifi==2023.5.7 charset-normalizer==3.1.0 +click==8.1.7 +contourpy==1.2.0 coverage==7.4.3 +cycler==0.12.1 Django==4.1.12 django-admin-volt==1.0.10 exceptiongroup==1.1.1 +Flask==3.0.2 +fonttools==4.50.0 frozendict==2.4.0 +gitdb==4.0.11 +GitPython==3.1.43 gunicorn==21.2.0 html5lib==1.1 idna==3.4 iniconfig==2.0.0 install==1.3.5 +itsdangerous==2.1.2 +Jinja2==3.1.3 jmespath==1.0.1 +jsonschema==4.21.1 +jsonschema-specifications==2023.12.1 +kiwisolver==1.4.5 lxml==4.9.3 +markdown-it-py==3.0.0 +MarkupSafe==2.1.5 +matplotlib==3.8.3 +mdurl==0.1.2 multitasking==0.0.11 mypy==1.8.0 mypy-extensions==1.0.0 @@ -22,21 +42,39 @@ numpy==1.26.4 packaging==23.1 pandas==2.2.1 pandas-stubs==2.2.0.240218 +patsy==0.5.6 peewee==3.17.1 +pillow==10.2.0 +plotly==5.20.0 pluggy==1.0.0 -psycopg2==2.9.9 +protobuf==4.25.3 psycopg2-binary==2.9.9 +pyarrow==15.0.2 +pydeck==0.8.1b0 +Pygments==2.17.2 +pyparsing==3.1.2 pytest==7.3.1 pytest-cov==4.1.0 python-dateutil==2.8.2 python-dotenv==1.0.0 pytz==2023.3 +referencing==0.34.0 requests==2.31.0 +rich==13.7.1 +rpds-py==0.18.0 ruff==0.3.0 +scipy==1.13.0 six==1.16.0 +smmap==5.0.1 soupsieve==2.5 sqlparse==0.4.4 +statsmodels==0.14.1 +streamlit==1.33.0 +tenacity==8.2.3 +toml==0.10.2 tomli==2.0.1 +toolz==0.12.1 +tornado==6.4 types-openpyxl==3.1.0.20240301 types-psycopg2==2.9.21.20240311 types-pytz==2024.1.0.20240203 @@ -45,6 +83,8 @@ typing_extensions==4.8.0 tzdata==2023.3 urllib3==2.0.2 utils==1.0.1 +watchdog==4.0.0 webencodings==0.5.1 +Werkzeug==3.0.2 whitenoise==6.5.0 yfinance==0.2.37 diff --git a/streamlit_app.py b/streamlit_app.py new file mode 100644 index 0000000..42bcb0d --- /dev/null +++ b/streamlit_app.py @@ -0,0 +1,46 @@ +"""This module configures the streamlit web app.""" +import json +import requests +import plotly.express as px # type: ignore[import-untyped] # pylint: disable=E0401 +import pandas as pd +import streamlit as st # type: ignore[import-untyped] # pylint: disable=E0401 + + +company_list_response: requests.Response = requests.get( + "http://core-modules:5000/model/generate_company_list" + ) +company_list: list = company_list_response.json() +st.write("Hello, let's learn more about a company together!") +company = st.selectbox("Pick a company", [None] + company_list) +st.write("You selected:", company) + +if company: + payload: dict = {"company": company} + update_response: requests.Response = requests.post( + "http://core-modules:5000/update_data", json=payload + ) + price: float = update_response.json()["price"] + news: list = update_response.json()["news"] + st.sidebar.write(f"{company}'s most recent price: {price}") + + news_container = st.sidebar.container() + for article in news: + news_container.markdown(f"- [{article['title']}]({article['url']})") + + chart_data: dict = json.loads(update_response.json()["graph"]) + date: dict + close: dict + date, close = chart_data["date"].values(), chart_data["close"].values() + df = pd.DataFrame(close, date) + + fig = px.line(df) + + fig.update_layout( + title=company, + xaxis_title='Date', + yaxis_title='Close', + width=800, + height=600 + ) + + st.plotly_chart(fig)