This is a submission for the Cloudflare AI Challenge.
What I Built
- Stonks is a beginner-friendly stock information app that provides an intuitive and user-friendly platform for accessing stock data and insights.
- It is a web-based application built on Streamlit, leveraging the power of serverless Cloudflare Workers and Workers AI to generate stock information from the polygon.io API.
Demo
STONKS APP ๐๐
Stonks app backend
My Code
The code for the Stonks App is available on GitHub:
-
Streamlit app https://github.com/rony0000013/stonks
rony0000013 / stonks
Stonks is a beginner-friendly ๐ stock information app that revolutionizes the way you access and understand stock data. Built on Streamlit ๐ป, it leverages serverless Cloudflare Workers โ๏ธ and Workers AI ๐ค to generate insightful stock summaries from polygon.io API ๐.
Stonks App ๐๐
Features
- Stock Summary: Get a comprehensive overview of stocks, including daily price charts and essential information.
- Multi-Language Support: Access stock information in multiple languages, ensuring accessibility for a global audience.
- News and Sentiment Analysis: Stay up-to-date with recent news related to stocks, accompanied by sentiment analysis for better decision-making.
- Customizable Date: Users can customize the date to obtain stock information tailored to their specific needs.
- LLM Model Selection: Choose from various Large Language Models (LLMs) to generate stock information based on individual preferences.
Getting Started
Prerequisites - Python and Poetry, Stonks-worker deployed or running locally
To run the Stonks App locally, follow these steps:
-
Clone the repository:
git clone https://github.com/rony0000013/stonks.git
-
Install the dependencies:
poetry install
-
Add stonks worker deployed link in
.streamlit/secrets.toml
url = "<your-deployment-link>
-
Run the app
poetry run streamlit run main.py
Contributing
Contributions to the Stonks App are welcomeโฆ
-
Cloudflare Worker https://github.com/rony0000013/stonks-worker
rony0000013 / stonks-worker
Stonks is a beginner-friendly ๐ stock information app that revolutionizes the way you access and understand stock data. Built on Streamlit ๐ป, it leverages serverless Cloudflare Workers โ๏ธ and Workers AI ๐ค to generate insightful stock summaries from polygon.io API ๐.
Stonks App Worker
Description
This repository contains the code for a Cloudflare Worker of the stonks app. stonks app is a beginner friendly app for getting stock information of various stocks.
Features
-
Stock Summary: Get a comprehensive overview of stocks, including daily price charts and essential information.
-
Multi-Language Support: Access stock information in multiple languages, ensuring accessibility for a global audience.
-
News and Sentiment Analysis: Stay up-to-date with recent news related to stocks, accompanied by sentiment analysis for better decision-making.
-
Customizable Date: Users can customize the date to obtain stock information tailored to their specific needs.
-
LLM Model Selection: Choose from various Large Language Models (LLMs) to generate stock information based on individual preferences.
Getting Started
To get started with this Cloudflare Worker, follow these steps:
-
Clone this repository:
git clone https://github.com/your-username/your-repo.git
-
Install the required dependencies:
npm install
-
Configure your Cloudflare account and obtain yourโฆ
-
Tech Stack -
- Streamlit - to build and deploy the app
- fuzzywuzzy - to search voice text to the ticker data
- Pytickersymbols - to get all stock tickers
- Plotly - do display the stock candlestick chart
- Poetry - to manage libraries and project
- Wrangler - to manage and deploy the worker
- hono - backend server to handle requests to the worker
- cloudflare workers ai - to run the ai models serverlessly
- cloudflare kv - to cache the worker requests
- cloudflare workers - to deploy and run the server
The repository includes a README file with installation instructions, as well as a LICENSE file for the project.
Journey
The development of the Stonks App was an exciting and challenging journey. I utilized various technologies and models to create this beginner-friendly stock information platform.
I was planning on building a easy way to view information about stocks since huge percent of indians are not stock investors. so th opportunity to build such an app with cloudflare was very intresting. But the only thing was that i saw that on 12/04/2024 with only 2 more days remaining !!
I started with the backend/worker. the start was pretty easy to my surprise thanks to the video from cloudflare Youtube Video ๐บ. Since my first time using Cloudflare Workers, Hono and Typecript (relatively more). So the start was easy.
I really liked the Wrangler CLI very intuitive to use. The workers AI models used pretty well and documentation was plenty. The Ploygon API also has clean docs with easy to use API. Cloudflare KV was very easy to implement the caching mechanism. I was not able to implement the swagger ui like the one in fastapi.
For the frontend It was my first time to use streamlit to build a website size app with complex logics. It was more or less okay.
The main trail to problems arised when I joined frontend and backend. both had to be changed several times to pass data correctly to each other and also the caching was implemented in multiple stages like in api routes, api calling, streamlit functions which ultimately prevented the potential problem of too many requests to use up my api limits.
I had an idea of generating the stock candlestick graph and stylize it with the image generation models. First problem was getiing the chart image. After searching various libraries
I came to a realization that was cloudflare workers is a serverless environment usual javascript libraries which call with DOM to generate charts did not work. After trying multiple times I ultimately decided that python's Plotly will do the chart creation.
Second problem arose when I tried to modify image using workers ai models. Here I realized that most except
stable-diffusion-v1-5-img2img
was not able to take input an image despite given in the docs input schema. The output of the only model which was able to stylize was very poor. So, I gave up on this Idea.Rest all models were easy to implement in the app and I ultimately was able to finish this in 2 days.
Looking ahead, I plan to improve the Stonks App by adding new features and exploring additional ways to leverage Workers AI. Some potential enhancements include implementing advanced stock analysis models, implementing a more fun and easy way to show stock charts.
Multiple Models and/or Triple Task Types
The Stonks App utilized multiple models from Workers AI to generate stock information, news analysis, and sentiment analysis.
-
Generating the stock information and chatting with stock data was done by
[ "@hf/thebloke/zephyr-7b-beta-awq", "@cf/qwen/qwen1.5-0.5b-chat", "@hf/nexusflow/starling-lm-7b-beta", "@hf/thebloke/llamaguard-7b-awq", "@hf/thebloke/neural-chat-7b-v3-1-awq", "@cf/meta/llama-2-7b-chat-fp16", "@cf/mistral/mistral-7b-instruct-v0.1", "@cf/tinyllama/tinyllama-1.1b-chat-v1.0", "@hf/mistral/mistral-7b-instruct-v0.2", "@hf/thebloke/codellama-7b-instruct-awq", "@hf/mistralai/mistral-7b-instruct-v0.2", "@cf/thebloke/discolm-german-7b-v1-awq", "@cf/meta/llama-2-7b-chat-int8", "@hf/thebloke/mistral-7b-instruct-v0.1-awq", "@hf/thebloke/openchat_3.5-awq", "@cf/qwen/qwen1.5-7b-chat-awq", "@hf/thebloke/llama-2-13b-chat-awq", "@hf/thebloke/openhermes-2.5-mistral-7b-awq", "@cf/tiiuae/falcon-7b-instruct", "@hf/nousresearch/hermes-2-pro-mistral-7b", "@cf/qwen/qwen1.5-1.8b-chat", "@cf/microsoft/phi-2", "@hf/google/gemma-7b-it", "@cf/qwen/qwen1.5-14b-chat-awq", "@cf/openchat/openchat-3.5-0106", "@cf/google/gemma-2b-it-lora", "@cf/google/gemma-7b-it-lora", ]
Summarizing the generated output was done by
@cf/facebook/bart-large-cnn
Translating the output was done by
@cf/meta/m2m100-1.2b
Generating Sentiments from the news articles was done by
@cf/huggingface/distilbert-sst-2-int8
Converting the voice input to text for ticker search was done by
@cf/openai/whisper
Top comments (0)