primenumbersam commited on
Commit
f46608b
·
0 Parent(s):

initial commit

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +2 -0
  2. README.md +68 -0
  3. app.py +209 -0
  4. assets/assets-logo/ Bristol-Myers Squibb.png +0 -0
  5. assets/assets-logo/AMD.png +0 -0
  6. assets/assets-logo/ASML.png +0 -0
  7. assets/assets-logo/AbbVie.png +0 -0
  8. assets/assets-logo/Abbott Laboratories.png +0 -0
  9. assets/assets-logo/Accenture.png +0 -0
  10. assets/assets-logo/Adobe.png +0 -0
  11. assets/assets-logo/Agricultural Bank of China.png +0 -0
  12. assets/assets-logo/Alibaba.png +0 -0
  13. assets/assets-logo/Alphabet (Google).png +0 -0
  14. assets/assets-logo/Amazon.png +0 -0
  15. assets/assets-logo/Amgen.png +0 -0
  16. assets/assets-logo/Apple.png +0 -0
  17. assets/assets-logo/Applied Materials.png +0 -0
  18. assets/assets-logo/AstraZeneca.png +0 -0
  19. assets/assets-logo/BHP Group.png +0 -0
  20. assets/assets-logo/Bank of America.png +0 -0
  21. assets/assets-logo/Bank of China.png +0 -0
  22. assets/assets-logo/Berkshire Hathaway.png +0 -0
  23. assets/assets-logo/Broadcom.png +0 -0
  24. assets/assets-logo/Caterpillar.png +0 -0
  25. assets/assets-logo/Chevron.png +0 -0
  26. assets/assets-logo/China Construction Bank.png +0 -0
  27. assets/assets-logo/China Life Insurance.png +0 -0
  28. assets/assets-logo/China Mobile.png +0 -0
  29. assets/assets-logo/Cisco.png +0 -0
  30. assets/assets-logo/Coca-Cola.png +0 -0
  31. assets/assets-logo/Comcast.png +0 -0
  32. assets/assets-logo/ConocoPhillips.png +0 -0
  33. assets/assets-logo/Costco.png +0 -0
  34. assets/assets-logo/Danaher.png +0 -0
  35. assets/assets-logo/Dior.png +0 -0
  36. assets/assets-logo/Eli Lilly.png +0 -0
  37. assets/assets-logo/Exxon Mobil.png +0 -0
  38. assets/assets-logo/General Electric.png +0 -0
  39. assets/assets-logo/HDFC Bank.png +0 -0
  40. assets/assets-logo/HSBC.png +0 -0
  41. assets/assets-logo/Herm/303/250s.png +0 -0
  42. assets/assets-logo/Home Depot.png +0 -0
  43. assets/assets-logo/Honeywell.png +0 -0
  44. assets/assets-logo/IBM.png +0 -0
  45. assets/assets-logo/ICBC.png +0 -0
  46. assets/assets-logo/Intel.png +0 -0
  47. assets/assets-logo/International Holding Company .png +0 -0
  48. assets/assets-logo/Intuit.png +0 -0
  49. assets/assets-logo/JPMorgan Chase.png +0 -0
  50. assets/assets-logo/Johnson & Johnson.png +0 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Virtual environments
2
+ .venv
README.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 🚀 Streamlit Multi-Page Lab
3
+ emoji: 🚀
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: streamlit
7
+ app_file: app.py
8
+ pinned: false
9
+ ---
10
+
11
+ # 🚀 Streamlit Multi-Page Lab
12
+
13
+ A comprehensive collection of Streamlit experiments, data dashboards, and AI-powered tools merged into a single multi-page application. This project is designed for rapid prototyping and testing various Streamlit features and open-source templates.
14
+
15
+ ## 🧪 Integrated Demos
16
+
17
+ 1. **Home**: Interactive Altair charts and selection-enabled dataframes.
18
+ 2. **🌍 Top Stocks**: A visual ranking. Derived from `companiesmarketcap.com` data and logos (provided in CSV). File: `1_us-stock-top-mktcap.py`
19
+ 3. **📈 US Top Stock Peers**: Comparative analysis. Fetches real-time market data using the `yfinance` package. File: `2_us-stock-top-compare.py`
20
+ 4. **🗺️ GDP Dashboard**: Historical GDP analysis. Visualizes pre-saved World Bank data (in CSV). File: `3_global-gdp-compare.py`
21
+ 5. **🤖 Gemini File Q&A**: RAG tool using Gemini 3.1 Flash Lite. File: `4_llm-gemini-rag.py`
22
+
23
+ ## 🏗️ Project Structure
24
+
25
+ ```text
26
+ lab-streamlit-start/
27
+ ├── assets/
28
+ │ └── assets-logo/ # Brand logos for the Top Companies demo
29
+ ├── data/
30
+ │ ├── data-gdp.csv # World Bank GDP dataset
31
+ │ └── data-stock-us.csv # Top companies market cap dataset
32
+ ├── pages/ # Multi-page implementation
33
+ │ ├── 1_us-stock-top-mktcap.py
34
+ │ ├── 2_us-stock-top-compare.py
35
+ │ ├── 3_global-gdp-compare.py
36
+ │ └── 4_llm-gemini-rag.py
37
+ ├── requirements.txt # Project dependencies
38
+ └── app.py # Main entry point & Landing page
39
+ ```
40
+
41
+ ## 🛠️ Setup & Execution
42
+
43
+ ### Prerequisites
44
+ - Python 3.11+
45
+ - [Google AI Studio API Key](https://aistudio.google.com/app/apikey) (for Gemini File Q&A)
46
+
47
+ ### Running Locally
48
+ 1. Install dependencies:
49
+ ```bash
50
+ pip install -r requirements.txt
51
+ ```
52
+ 2. Run the application:
53
+ ```bash
54
+ streamlit run app.py
55
+ ```
56
+
57
+ ## ⚙️ Configuration
58
+ The project is configured for seamless execution in **GitHub Codespaces**. Check `.devcontainer/devcontainer.json` for pre-configured environment settings.
59
+
60
+ ## 📚 References & Credits
61
+ This lab integrates and adapts features from the following open-source projects:
62
+ - **Top Companies Market Cap**: [bi-cnc/top_companies_market_cap](https://github.com/bi-cnc/top_companies_market_cap)
63
+ - **Stock Peer Analysis**: [streamlit/demo-stockpeers](https://github.com/streamlit/demo-stockpeers)
64
+ - **GDP Dashboard**: [streamlit/GDP-Dashboard](https://github.com/streamlit/GDP-Dashboard)
65
+ - **Gemini File Q&A Source**: Adapted from [streamlit/llm-examples](https://github.com/streamlit/llm-examples) (Original Anthropic version)
66
+
67
+ ---
68
+ *Built with ❤️ using Streamlit, Altair, and Google Gemini.*
app.py ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """streamlit_altair.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1KiJCGzPr79u2mN7nXBz-smug7tEclhJE
8
+ """
9
+ #!pip install -q streamlit
10
+ # streamlit and other required libraries should be written in requirements.txt in Github repo
11
+
12
+ import streamlit as st
13
+ import altair as alt
14
+ import numpy as np
15
+ import pandas as pd
16
+ from vega_datasets import data
17
+ from faker import Faker
18
+
19
+ # 1. Main Page Config
20
+ st.set_page_config(
21
+ page_title="Streamlit Multi-Page Demo",
22
+ page_icon="🚀",
23
+ layout="wide",
24
+ initial_sidebar_state="expanded",
25
+ )
26
+
27
+ # Sidebar Navigation Hint
28
+ st.sidebar.success("느좋 데이러 싸이언스")
29
+
30
+ # Landing Page Content (Kept as per user request for markdown additions)
31
+ st.title("🚀 Streamlit Multi-Page Lab")
32
+ st.markdown("""
33
+ Welcome to your integrated Streamlit workspace! This project combines multiple quickstart templates and interactive demos into a single multi-page application.
34
+
35
+ ### 🧪 Available Demos:
36
+ 1. **Home (This page)**: Current Altair and Interactive Dataframe demo.
37
+ 2. **🌍 [Top Stocks](./us-stock-top-mktcap)**: Ranking of the world's largest companies by market cap with logos.
38
+ 3. **📈 [US Top Stock Peers](./us-stock-top-compare)**: Comparative analysis of stock market peers using Yahoo Finance.
39
+ 4. **🗺️ [GDP Dashboard](./global-gdp-compare)**: Global GDP analysis from World Bank data.
40
+ 5. **🤖 [Gemini File Q&A](./llm-gemini-rag)**: Document answering using Google Gemini (PDF/TXT/MD support).
41
+
42
+ ---
43
+ """)
44
+
45
+ @st.cache_data # Streamlit will only download the data once since the data will be saved in a cache
46
+ def get_data():
47
+ source = data.stocks()
48
+ source = source[source.date.gt("2006-01-01")]
49
+ return source
50
+
51
+
52
+ def get_profile_dataset(number_of_items: int = 20, seed: int = 0) -> pd.DataFrame:
53
+ new_data = []
54
+
55
+ fake = Faker()
56
+ np.random.seed(seed)
57
+ Faker.seed(seed)
58
+
59
+ for i in range(number_of_items):
60
+ profile = fake.profile()
61
+ new_data.append(
62
+ {
63
+ "name": profile["name"],
64
+ "daily_activity": np.random.rand(25),
65
+ "activity": np.random.randint(2, 90, size=12),
66
+ }
67
+ )
68
+
69
+ profile_df = pd.DataFrame(new_data)
70
+ return profile_df
71
+
72
+
73
+ #######################################
74
+ st.title("Altair")
75
+ stock_data = get_data()
76
+
77
+ # Events in altair
78
+ # Note: selection_single is deprecated in Altair 5+, but we use selection_point for compatibility
79
+ # while maintaining the original logic functionality.
80
+ hover = alt.selection_point(
81
+ fields=["date"],
82
+ nearest=True,
83
+ on="mouseover",
84
+ empty=False,
85
+ )
86
+
87
+ lines = (
88
+ alt.Chart(stock_data, title="Evolution of stock prices")
89
+ .mark_line()
90
+ .encode(
91
+ x="date",
92
+ y="price",
93
+ color="symbol",
94
+ )
95
+ )
96
+
97
+ points = lines.transform_filter(hover).mark_circle(size=65)
98
+
99
+ tooltips = (
100
+ alt.Chart(stock_data)
101
+ .mark_rule()
102
+ .encode(
103
+ x="yearmonthdate(date)",
104
+ y="price",
105
+ opacity=alt.condition(hover, alt.value(0.3), alt.value(0)),
106
+ tooltip=[
107
+ alt.Tooltip("date", title="Date"),
108
+ alt.Tooltip("price", title="Price (USD)"),
109
+ ],
110
+ )
111
+ .add_params(hover)
112
+ )
113
+
114
+ # Combine the lines, points, and tooltips into a single chart.
115
+ data_layer = lines + points + tooltips
116
+
117
+ # Build the annotation layer
118
+ ANNOTATIONS = [
119
+ ("Sep 01, 2007", 450, "🙂", "Something's going well for GOOG & AAPL."),
120
+ ("Nov 01, 2008", 220, "🙂", "The market is recovering."),
121
+ ("Dec 01, 2007", 750, "😱", "Something's going wrong for GOOG & AAPL."),
122
+ ("Dec 01, 2009", 680, "😱", "A hiccup for GOOG."),
123
+ ]
124
+ annotations_df = pd.DataFrame(
125
+ ANNOTATIONS, columns=["date", "price", "marker", "description"]
126
+ )
127
+ annotations_df.date = pd.to_datetime(annotations_df.date)
128
+
129
+ annotation_layer = (
130
+ alt.Chart(annotations_df)
131
+ .mark_text(size=20, dx=-10, dy=0, align="left")
132
+ .encode(x="date:T", y=alt.Y("price:Q"), text="marker", tooltip="description")
133
+ )
134
+
135
+ # Define the combined chart.
136
+ combined_chart = data_layer + annotation_layer
137
+ # enable panning and zooming
138
+ # combined_chart = (data_layer + annotation_layer).interactive()
139
+
140
+ # Display the chart in Streamlit.
141
+ st.altair_chart(combined_chart, use_container_width=True)
142
+
143
+
144
+ #######################################
145
+ st.title("Get dataframe row-selections")
146
+
147
+ column_configuration = {
148
+ "name": st.column_config.TextColumn(
149
+ "Name", help="The name of the user", max_chars=100, width="medium"
150
+ ),
151
+ "activity": st.column_config.LineChartColumn(
152
+ "Activity (1 year)",
153
+ help="The user's activity over the last 1 year",
154
+ width="large",
155
+ y_min=0,
156
+ y_max=100,
157
+ ),
158
+ "daily_activity": st.column_config.BarChartColumn(
159
+ "Activity (daily)",
160
+ help="The user's activity in the last 25 days",
161
+ width="medium",
162
+ y_min=0,
163
+ y_max=1,
164
+ ),
165
+ }
166
+
167
+ select, compare = st.tabs(["Select members", "Compare selected"])
168
+
169
+ with select:
170
+ st.header("All members")
171
+
172
+ df = get_profile_dataset()
173
+
174
+ event = st.dataframe(
175
+ df,
176
+ column_config=column_configuration,
177
+ use_container_width=True,
178
+ hide_index=True,
179
+ on_select="rerun",
180
+ selection_mode="multi-row",
181
+ )
182
+
183
+ st.header("Selected members")
184
+ people = event.selection.rows
185
+ filtered_df = df.iloc[people]
186
+ st.dataframe(
187
+ filtered_df,
188
+ column_config=column_configuration,
189
+ use_container_width=True,
190
+ )
191
+
192
+ with compare:
193
+ activity_df = {}
194
+ for person in people:
195
+ activity_df[df.iloc[person]["name"]] = df.iloc[person]["activity"]
196
+ activity_df = pd.DataFrame(activity_df)
197
+
198
+ daily_activity_df = {}
199
+ for person in people:
200
+ daily_activity_df[df.iloc[person]["name"]] = df.iloc[person]["daily_activity"]
201
+ daily_activity_df = pd.DataFrame(daily_activity_df)
202
+
203
+ if len(people) > 0:
204
+ st.header("Daily activity comparison")
205
+ st.bar_chart(daily_activity_df)
206
+ st.header("Yearly activity comparison")
207
+ st.line_chart(activity_df)
208
+ else:
209
+ st.markdown("No members selected.")
assets/assets-logo/ Bristol-Myers Squibb.png ADDED
assets/assets-logo/AMD.png ADDED
assets/assets-logo/ASML.png ADDED
assets/assets-logo/AbbVie.png ADDED
assets/assets-logo/Abbott Laboratories.png ADDED
assets/assets-logo/Accenture.png ADDED
assets/assets-logo/Adobe.png ADDED
assets/assets-logo/Agricultural Bank of China.png ADDED
assets/assets-logo/Alibaba.png ADDED
assets/assets-logo/Alphabet (Google).png ADDED
assets/assets-logo/Amazon.png ADDED
assets/assets-logo/Amgen.png ADDED
assets/assets-logo/Apple.png ADDED
assets/assets-logo/Applied Materials.png ADDED
assets/assets-logo/AstraZeneca.png ADDED
assets/assets-logo/BHP Group.png ADDED
assets/assets-logo/Bank of America.png ADDED
assets/assets-logo/Bank of China.png ADDED
assets/assets-logo/Berkshire Hathaway.png ADDED
assets/assets-logo/Broadcom.png ADDED
assets/assets-logo/Caterpillar.png ADDED
assets/assets-logo/Chevron.png ADDED
assets/assets-logo/China Construction Bank.png ADDED
assets/assets-logo/China Life Insurance.png ADDED
assets/assets-logo/China Mobile.png ADDED
assets/assets-logo/Cisco.png ADDED
assets/assets-logo/Coca-Cola.png ADDED
assets/assets-logo/Comcast.png ADDED
assets/assets-logo/ConocoPhillips.png ADDED
assets/assets-logo/Costco.png ADDED
assets/assets-logo/Danaher.png ADDED
assets/assets-logo/Dior.png ADDED
assets/assets-logo/Eli Lilly.png ADDED
assets/assets-logo/Exxon Mobil.png ADDED
assets/assets-logo/General Electric.png ADDED
assets/assets-logo/HDFC Bank.png ADDED
assets/assets-logo/HSBC.png ADDED
assets/assets-logo/Herm/303/250s.png ADDED
assets/assets-logo/Home Depot.png ADDED
assets/assets-logo/Honeywell.png ADDED
assets/assets-logo/IBM.png ADDED
assets/assets-logo/ICBC.png ADDED
assets/assets-logo/Intel.png ADDED
assets/assets-logo/International Holding Company .png ADDED
assets/assets-logo/Intuit.png ADDED
assets/assets-logo/JPMorgan Chase.png ADDED
assets/assets-logo/Johnson & Johnson.png ADDED