awacke1 commited on
Commit
df82aa0
Β·
verified Β·
1 Parent(s): 60f796c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -137
app.py CHANGED
@@ -2,83 +2,88 @@ import streamlit as st
2
  import pandas as pd
3
  import folium
4
  from streamlit_folium import folium_static
5
- from streamlit_components import html
6
 
7
- # Set page config
 
 
8
  st.set_page_config(page_title="Wild Bill vs Buffalo Bill", page_icon="🀠", layout="wide")
9
 
10
- # Define the stories
11
- wild_bill_story = """
12
- # πŸ”« Wild Bill Hickok: The Legendary Gunslinger
13
-
14
- ## 1. 🌟 Early Life
15
- - 🍼 Born James Butler Hickok on May 27, 1837, in Homer, Illinois
16
- - 🌾 Grew up on a farm, developing skills in shooting and horseback riding
17
- - 🏞️ Left home at 18 to become a stagecoach driver on the Santa Fe Trail
18
-
19
- ... # (The rest of the Wild Bill story remains the same)
20
- """
21
-
22
- buffalo_bill_story = """
23
- # 🦬 Buffalo Bill Cody: The Showman of the West
24
-
25
- ## 1. 🌟 Early Life
26
- - 🍼 Born William Frederick Cody on February 26, 1846, in Le Claire, Iowa
27
- - 🐎 Began riding horses at a young age
28
- - πŸš‚ Worked as a Pony Express rider at age 14
29
-
30
- ... # (The rest of the Buffalo Bill story remains the same)
31
- """
32
-
33
- # Sidebar
34
- st.sidebar.title("πŸ“ Key Locations & Events")
35
-
36
- st.sidebar.markdown("""
37
- ## Wild Bill Hickok
38
- - 🏑 Homer, Illinois (Birth)
39
- - 🌽 Rock Creek Station, Nebraska
40
- - πŸ„ Abilene, Kansas
41
- - 🏜️ Cheyenne, Wyoming
42
- - πŸͺ™ Deadwood, South Dakota (Death)
43
-
44
- ## Buffalo Bill Cody
45
- - 🏑 Le Claire, Iowa (Birth)
46
- - 🌽 North Platte, Nebraska
47
- - πŸ”οΈ Cody, Wyoming
48
- - πŸŒ„ Denver, Colorado
49
- - πŸ›οΈ Denver, Colorado (Death)
50
- """)
51
 
52
- # Main content
53
- st.title("🀠 Wild Bill Hickok vs Buffalo Bill Cody: A Tale of Two Western Legends")
54
 
55
- col1, col2 = st.columns(2)
 
 
 
56
 
57
- with col1:
 
 
 
 
 
 
 
58
  st.markdown(wild_bill_story)
59
 
60
- with col2:
 
 
61
  st.markdown(buffalo_bill_story)
62
 
63
- # Map
64
- st.subheader("πŸ—ΊοΈ Journey Through the Wild West")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- # Create a base map
 
 
 
 
 
 
 
 
67
  m = folium.Map(location=[41, -100], zoom_start=4)
68
 
69
- # Add markers for key locations
70
  locations = [
71
- ("Homer, IL", 40.0356, -87.9506, "Wild Bill Hickok's Birthplace"),
72
- ("Rock Creek Station, NE", 40.1116, -97.0564, "McCanles Massacre Site"),
73
- ("Abilene, KS", 38.9172, -97.2137, "Wild Bill served as Marshal"),
74
- ("Cheyenne, WY", 41.1400, -104.8202, "Wild Bill's brief stint as sheriff"),
75
- ("Deadwood, SD", 44.3767, -103.7296, "Wild Bill's final days and resting place"),
76
- ("Le Claire, IA", 41.5978, -90.3485, "Buffalo Bill's Birthplace"),
77
- ("North Platte, NE", 41.1239, -100.7654, "Buffalo Bill's Scout's Rest Ranch"),
78
- ("Cody, WY", 44.5263, -109.0565, "Town founded by Buffalo Bill"),
79
- ("Denver, CO", 39.7392, -104.9903, "Buffalo Bill's home and final resting place")
80
  ]
81
 
 
82
  for name, lat, lon, desc in locations:
83
  folium.Marker(
84
  [lat, lon],
@@ -86,98 +91,44 @@ for name, lat, lon, desc in locations:
86
  tooltip=name
87
  ).add_to(m)
88
 
89
- # Display the map
90
  folium_static(m)
91
 
92
- # Add React component for animated timeline
93
- st.subheader("⏳ Animated Timeline")
94
-
95
- timeline_component = """
96
- import React, { useState, useEffect } from 'react';
97
-
98
- const Timeline = () => {
99
- const [year, setYear] = useState(1837);
100
- const [event, setEvent] = useState('');
101
-
102
- const events = {
103
- 1837: "Wild Bill Hickok born",
104
- 1846: "Buffalo Bill Cody born",
105
- 1861: "Wild Bill involved in McCanles Massacre",
106
- 1867: "Buffalo Bill begins hunting buffalo for Kansas Pacific Railroad",
107
- 1871: "Wild Bill becomes marshal of Abilene, Kansas",
108
- 1872: "Buffalo Bill awarded Medal of Honor",
109
- 1876: "Wild Bill assassinated in Deadwood",
110
- 1883: "Buffalo Bill's Wild West show debuts",
111
- 1893: "Buffalo Bill performs at Chicago World's Fair",
112
- 1917: "Buffalo Bill dies in Denver"
113
- };
114
-
115
- useEffect(() => {
116
- const timer = setInterval(() => {
117
- setYear(prevYear => {
118
- const newYear = prevYear + 1;
119
- if (newYear > 1917) return 1837;
120
- return newYear;
121
- });
122
- }, 1000);
123
-
124
- return () => clearInterval(timer);
125
- }, []);
126
-
127
- useEffect(() => {
128
- setEvent(events[year] || '');
129
- }, [year]);
130
-
131
- return (
132
- <div className="timeline">
133
- <h2 className="text-2xl font-bold mb-4">Year: {year}</h2>
134
- <p className="text-lg">{event}</p>
135
- </div>
136
- );
137
- };
138
-
139
- export default Timeline;
140
- """
141
-
142
- # Use the html component to render the React Timeline
143
- html(
144
- f"""
145
- <div id="react-root"></div>
146
- <script src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
147
- <script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
148
- <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
149
- <script type="text/babel">
150
- {timeline_component}
151
- ReactDOM.render(<Timeline />, document.getElementById('react-root'));
152
- </script>
153
- """
154
- )
155
-
156
- # Comparison table
157
  st.subheader("πŸ“Š Side-by-Side Comparison")
158
-
159
  comparison_data = {
160
  "Aspect": ["Birth Year", "Death Year", "Nickname Origin", "Primary Occupation", "Famous For", "Colorado Connection", "South Dakota Connection"],
161
- "Wild Bill Hickok": ["1837", "1876", "Unclear, possibly due to his nose", "Lawman, Gunfighter", "Marksmanship, Gunfights", "Visited during travels", "Died in Deadwood"],
162
- "Buffalo Bill Cody": ["1846", "1917", "Buffalo hunting skills", "Showman, Scout", "Wild West Show", "Home in Denver", "Performed shows in the state"]
163
  }
164
 
 
165
  df = pd.DataFrame(comparison_data)
166
  st.table(df)
167
 
168
- # Conclusion
 
 
 
 
 
169
  st.markdown("""
170
  ## πŸŒ… Conclusion: Legends of the West
171
 
172
- Both Wild Bill Hickok and Buffalo Bill Cody played significant roles in shaping the mythology and reality of the American West. While their paths diverged in many ways, both men left an indelible mark on American history and popular culture.
 
 
 
 
 
 
173
 
174
- - πŸ”« **Wild Bill Hickok** embodied the image of the fearless lawman and skilled gunfighter, his life and death becoming the stuff of legend.
175
- - πŸŽͺ **Buffalo Bill Cody** transformed his real-life adventures into grand spectacles, sharing his vision of the West with audiences around the world.
176
 
177
- Their stories, intertwined with the development of Colorado and South Dakota, continue to captivate our imaginations and remind us of a bygone era in American history.
178
  """)
179
 
180
- # Run the Streamlit app
181
  if __name__ == "__main__":
182
  st.sidebar.markdown("---")
183
- st.sidebar.markdown("Created with ❀️ using Streamlit")
 
2
  import pandas as pd
3
  import folium
4
  from streamlit_folium import folium_static
5
+ import extra_streamlit_components as stx
6
 
7
+ # 🀠 Howdy, partner! Welcome to the Wild West of coding! 🌡
8
+
9
+ # 🎭 Set the stage for our grand performance
10
  st.set_page_config(page_title="Wild Bill vs Buffalo Bill", page_icon="🀠", layout="wide")
11
 
12
+ # 🧠 Initialize our app's memory (it's not whiskey, I promise!)
13
+ if 'page' not in st.session_state:
14
+ st.session_state.page = 'home'
15
+
16
+ # πŸͺ Cookie Manager: Because even cowboys need snacks
17
+ @st.cache_resource
18
+ def get_manager():
19
+ return stx.CookieManager()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ cookie_manager = get_manager()
 
22
 
23
+ # πŸš‚ All aboard the Router Express! Next stop: Destination Page
24
+ @st.cache_resource(hash_funcs={"_thread.RLock": lambda _: None})
25
+ def init_router():
26
+ return stx.Router({"/home": home, "/wild-bill": wild_bill, "/buffalo-bill": buffalo_bill})
27
 
28
+ # 🏑 Home on the range
29
+ def home():
30
+ st.title("🀠 Wild Bill Hickok vs Buffalo Bill Cody: A Tale of Two Western Legends")
31
+ st.write("Welcome to our interactive dime novel! Choose a character to explore their story.")
32
+
33
+ # πŸ”« Wild Bill's saloon (careful, he's a quick draw!)
34
+ def wild_bill():
35
+ st.title("πŸ”« Wild Bill Hickok: The Legendary Gunslinger")
36
  st.markdown(wild_bill_story)
37
 
38
+ # πŸŽͺ Step right up to Buffalo Bill's Wild West Show!
39
+ def buffalo_bill():
40
+ st.title("🦬 Buffalo Bill Cody: The Showman of the West")
41
  st.markdown(buffalo_bill_story)
42
 
43
+ # πŸš‰ All aboard! The Router is leaving the station!
44
+ router = init_router()
45
+
46
+ # 🧭 Navigation: Don't get lost in the prairie!
47
+ chosen_id = stx.tab_bar(data=[
48
+ stx.TabBarItemData(id="home", title="Home", description="Start here"),
49
+ stx.TabBarItemData(id="wild-bill", title="Wild Bill", description="Explore Wild Bill's story"),
50
+ stx.TabBarItemData(id="buffalo-bill", title="Buffalo Bill", description="Discover Buffalo Bill's adventures"),
51
+ ], default="home")
52
+
53
+ # 🐎 Giddy up to the chosen page!
54
+ router.route(f"/{chosen_id}")
55
+
56
+ # πŸ—ΊοΈ You are here (in case you got lost in a saloon)
57
+ router.show_route_view()
58
+
59
+ # πŸ•°οΈ Remember the last saloon... err, page you visited
60
+ cookie_manager.set("last_page", chosen_id)
61
 
62
+ # πŸ“œ Reveal the secrets of your past (visits)
63
+ st.sidebar.write(f"Last visited: {cookie_manager.get('last_page')}")
64
+
65
+ # πŸ‘’ Put your boots on, we're going on a story adventure!
66
+ story_progress = stx.stepper_bar(steps=["Early Life", "Rise to Fame", "Notable Feats", "Legacy"])
67
+ st.sidebar.info(f"Story Progress: Phase #{story_progress}")
68
+
69
+ # πŸ—ΊοΈ Map: Because even legends need GPS sometimes
70
+ st.subheader("πŸ—ΊοΈ Journey Through the Wild West")
71
  m = folium.Map(location=[41, -100], zoom_start=4)
72
 
73
+ # πŸ“ Mark the spots where our legends left their boot prints
74
  locations = [
75
+ ("Homer, IL", 40.0356, -87.9506, "Wild Bill's first rodeo (birthplace)"),
76
+ ("Rock Creek Station, NE", 40.1116, -97.0564, "Wild Bill's wild time (McCanles Massacre)"),
77
+ ("Abilene, KS", 38.9172, -97.2137, "Wild Bill's badge-wearing days"),
78
+ ("Cheyenne, WY", 41.1400, -104.8202, "Wild Bill's brief sheriff showdown"),
79
+ ("Deadwood, SD", 44.3767, -103.7296, "Wild Bill's last poker game 😒"),
80
+ ("Le Claire, IA", 41.5978, -90.3485, "Buffalo Bill's first 'Yee-haw!' (birthplace)"),
81
+ ("North Platte, NE", 41.1239, -100.7654, "Buffalo Bill's home on the range"),
82
+ ("Cody, WY", 44.5263, -109.0565, "Buffalo Bill's namesake town (no buffaloes were harmed)"),
83
+ ("Denver, CO", 39.7392, -104.9903, "Buffalo Bill's final bow 🎭")
84
  ]
85
 
86
+ # 🎨 Paint the town red... or at least mark it on the map
87
  for name, lat, lon, desc in locations:
88
  folium.Marker(
89
  [lat, lon],
 
91
  tooltip=name
92
  ).add_to(m)
93
 
94
+ # 🌟 Showcase our masterpiece map
95
  folium_static(m)
96
 
97
+ # πŸ“Š Compare our legends (no gunslingers were harmed in the making of this table)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  st.subheader("πŸ“Š Side-by-Side Comparison")
 
99
  comparison_data = {
100
  "Aspect": ["Birth Year", "Death Year", "Nickname Origin", "Primary Occupation", "Famous For", "Colorado Connection", "South Dakota Connection"],
101
+ "Wild Bill Hickok": ["1837", "1876", "Unclear, possibly his wild nose πŸ‘ƒ", "Lawman, Gunfighter", "Quick Draw McGraw IRL", "Visited (probably for the beer 🍺)", "Died in Deadwood (worst poker game ever)"],
102
+ "Buffalo Bill Cody": ["1846", "1917", "Buffalo hunting (not actual buffaloes)", "Showman, Scout", "Wild West Show (wilder than spring break)", "Home in Denver (loved the mountains)", "Performed shows (to rival Deadwood's saloons)"]
103
  }
104
 
105
+ # 🎭 Let the comparison show begin!
106
  df = pd.DataFrame(comparison_data)
107
  st.table(df)
108
 
109
+ # πŸ–ΌοΈ A picture's worth a thousand yeehaws!
110
+ st.subheader("Wild West Imagery")
111
+ image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Wild_Bill_Hickok_1869.jpg/800px-Wild_Bill_Hickok_1869.jpg"
112
+ stx.bouncing_image(image_source=image_url, animate=True, animation_time=1500, height=300, width=200)
113
+
114
+ # πŸŒ… Ride off into the sunset with our conclusion
115
  st.markdown("""
116
  ## πŸŒ… Conclusion: Legends of the West
117
 
118
+ Yeehaw! We've corralled the tales of two of the wildest cowboys to ever roam the American frontier! 🀠
119
+
120
+ - πŸ”« **Wild Bill Hickok**: The man, the myth, the mustache! He lived fast, died young, and left a good-looking corpse (with a really bad poker hand).
121
+
122
+ - πŸŽͺ **Buffalo Bill Cody**: The original showman who put the 'wild' in Wild West! He turned frontier life into a circus... literally!
123
+
124
+ These two buckaroos shaped the West faster than a tumbleweek 🌿 rollin' in a tornado! Their legacy is as enduring as the smell of a cowboy's boots after a long cattle drive. πŸ„πŸ’¨
125
 
126
+ So next time you're sipping sarsaparilla πŸ₯€ in a saloon, tip your hat 🀠 to Wild Bill and Buffalo Bill - the OG influencers of the American West!
 
127
 
128
+ Remember, in the words of the great philosopher Woody from Toy Story: "There's a snake in my boot!" πŸπŸ‘’ (Okay, maybe that's not relevant, but it's still a great quote!)
129
  """)
130
 
131
+ # 🎬 That's all, folks!
132
  if __name__ == "__main__":
133
  st.sidebar.markdown("---")
134
+ st.sidebar.markdown("Created with ❀️ and a lot of 🀠 using Streamlit")