|
import streamlit as st |
|
import requests |
|
|
|
st.set_page_config(page_title="Country History App", layout="centered") |
|
|
|
st.title("π Country History Explorer") |
|
st.write("Select a country below to learn about its history.") |
|
|
|
|
|
country = st.selectbox( |
|
"Choose a country:", |
|
[ |
|
"Pakistan", "India", "China", "United States", "United Kingdom", |
|
"Germany", "France", "Japan", "Brazil", "Russia", "Saudi Arabia", |
|
"Canada", "Australia", "Italy", "Turkey" |
|
] |
|
) |
|
|
|
|
|
def get_country_history(country_name): |
|
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/History_of_{country_name.replace(' ', '_')}" |
|
response = requests.get(url) |
|
if response.status_code == 200: |
|
data = response.json() |
|
return data.get("extract") |
|
else: |
|
return "Sorry, no historical information was found for this country." |
|
|
|
|
|
if st.button("Show History"): |
|
with st.spinner("Fetching history..."): |
|
history = get_country_history(country) |
|
st.subheader(f"History of {country}") |
|
st.write(history) |