File size: 1,124 Bytes
31828f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 selection box
country = st.selectbox(
    "Choose a country:",
    [
        "Pakistan", "India", "China", "United States", "United Kingdom",
        "Germany", "France", "Japan", "Brazil", "Russia", "Saudi Arabia",
        "Canada", "Australia", "Italy", "Turkey"
    ]
)

# Function to get history from Wikipedia API
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."

# Show result
if st.button("Show History"):
    with st.spinner("Fetching history..."):
        history = get_country_history(country)
        st.subheader(f"History of {country}")
        st.write(history)