Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import folium | |
| from streamlit_folium import folium_static | |
| import extra_streamlit_components as stx | |
| # π€ Howdy, partner! Welcome to the Wild West of coding! π΅ | |
| # π Set the stage for our grand performance | |
| st.set_page_config(page_title="Wild Bill vs Buffalo Bill", page_icon="π€ ", layout="wide") | |
| # π§ Initialize our app's memory (it's not whiskey, I promise!) | |
| if 'page' not in st.session_state: | |
| st.session_state.page = 'home' | |
| # πͺ Cookie Manager: Because even cowboys need snacks | |
| def get_manager(): | |
| return stx.CookieManager() | |
| cookie_manager = get_manager() | |
| # π All aboard the Router Express! Next stop: Destination Page | |
| def init_router(): | |
| return stx.Router({"/home": home, "/wild-bill": wild_bill, "/buffalo-bill": buffalo_bill}) | |
| # π‘ Home on the range | |
| def home(): | |
| st.title("π€ Wild Bill Hickok vs Buffalo Bill Cody: A Tale of Two Western Legends") | |
| st.write("Welcome to our interactive dime novel! Choose a character to explore their story.") | |
| # π« Wild Bill's saloon (careful, he's a quick draw!) | |
| def wild_bill(): | |
| st.title("π« Wild Bill Hickok: The Legendary Gunslinger") | |
| st.markdown(wild_bill_story) | |
| # πͺ Step right up to Buffalo Bill's Wild West Show! | |
| def buffalo_bill(): | |
| st.title("𦬠Buffalo Bill Cody: The Showman of the West") | |
| st.markdown(buffalo_bill_story) | |
| # π All aboard! The Router is leaving the station! | |
| router = init_router() | |
| # π§ Navigation: Don't get lost in the prairie! | |
| chosen_id = stx.tab_bar(data=[ | |
| stx.TabBarItemData(id="home", title="Home", description="Start here"), | |
| stx.TabBarItemData(id="wild-bill", title="Wild Bill", description="Explore Wild Bill's story"), | |
| stx.TabBarItemData(id="buffalo-bill", title="Buffalo Bill", description="Discover Buffalo Bill's adventures"), | |
| ], default="home") | |
| # π Giddy up to the chosen page! | |
| router.route(f"/{chosen_id}") | |
| # πΊοΈ You are here (in case you got lost in a saloon) | |
| router.show_route_view() | |
| # π°οΈ Remember the last saloon... err, page you visited | |
| cookie_manager.set("last_page", chosen_id) | |
| # π Reveal the secrets of your past (visits) | |
| st.sidebar.write(f"Last visited: {cookie_manager.get('last_page')}") | |
| # π’ Put your boots on, we're going on a story adventure! | |
| story_progress = stx.stepper_bar(steps=["Early Life", "Rise to Fame", "Notable Feats", "Legacy"]) | |
| st.sidebar.info(f"Story Progress: Phase #{story_progress}") | |
| # πΊοΈ Map: Because even legends need GPS sometimes | |
| st.subheader("πΊοΈ Journey Through the Wild West") | |
| m = folium.Map(location=[41, -100], zoom_start=4) | |
| # π Mark the spots where our legends left their boot prints | |
| locations = [ | |
| ("Homer, IL", 40.0356, -87.9506, "Wild Bill's first rodeo (birthplace)"), | |
| ("Rock Creek Station, NE", 40.1116, -97.0564, "Wild Bill's wild time (McCanles Massacre)"), | |
| ("Abilene, KS", 38.9172, -97.2137, "Wild Bill's badge-wearing days"), | |
| ("Cheyenne, WY", 41.1400, -104.8202, "Wild Bill's brief sheriff showdown"), | |
| ("Deadwood, SD", 44.3767, -103.7296, "Wild Bill's last poker game π’"), | |
| ("Le Claire, IA", 41.5978, -90.3485, "Buffalo Bill's first 'Yee-haw!' (birthplace)"), | |
| ("North Platte, NE", 41.1239, -100.7654, "Buffalo Bill's home on the range"), | |
| ("Cody, WY", 44.5263, -109.0565, "Buffalo Bill's namesake town (no buffaloes were harmed)"), | |
| ("Denver, CO", 39.7392, -104.9903, "Buffalo Bill's final bow π") | |
| ] | |
| # π¨ Paint the town red... or at least mark it on the map | |
| for name, lat, lon, desc in locations: | |
| folium.Marker( | |
| [lat, lon], | |
| popup=f"{name}: {desc}", | |
| tooltip=name | |
| ).add_to(m) | |
| # π Showcase our masterpiece map | |
| folium_static(m) | |
| # π Compare our legends (no gunslingers were harmed in the making of this table) | |
| st.subheader("π Side-by-Side Comparison") | |
| comparison_data = { | |
| "Aspect": ["Birth Year", "Death Year", "Nickname Origin", "Primary Occupation", "Famous For", "Colorado Connection", "South Dakota Connection"], | |
| "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)"], | |
| "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)"] | |
| } | |
| # π Let the comparison show begin! | |
| df = pd.DataFrame(comparison_data) | |
| st.table(df) | |
| # πΌοΈ A picture's worth a thousand yeehaws! | |
| st.subheader("Wild West Imagery") | |
| image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Wild_Bill_Hickok_1869.jpg/800px-Wild_Bill_Hickok_1869.jpg" | |
| stx.bouncing_image(image_source=image_url, animate=True, animation_time=1500, height=300, width=200) | |
| # π Ride off into the sunset with our conclusion | |
| st.markdown(""" | |
| ## π Conclusion: Legends of the West | |
| Yeehaw! We've corralled the tales of two of the wildest cowboys to ever roam the American frontier! π€ | |
| - π« **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). | |
| - πͺ **Buffalo Bill Cody**: The original showman who put the 'wild' in Wild West! He turned frontier life into a circus... literally! | |
| 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. ππ¨ | |
| 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! | |
| 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!) | |
| """) | |
| # π¬ That's all, folks! | |
| if __name__ == "__main__": | |
| st.sidebar.markdown("---") | |
| st.sidebar.markdown("Created with β€οΈ and a lot of π€ using Streamlit") |