ZohaJaved's picture
Create app.py
520feef verified
import streamlit as st
import requests
st.set_page_config(page_title="Country Finder 🌍", page_icon="🌍")
st.title("🌍 Country Finder")
st.write("Type a country name to get info and see the flag!")
country_name = st.text_input("Enter a country")
if country_name:
url = f"https://restcountries.com/v3.1/name/{country_name}"
response = requests.get(url)
if response.status_code != 200:
st.error("Country not found. Try again! 😒")
else:
data = response.json()[0]
name = data.get("name", {}).get("common", "N/A")
capital = data.get("capital", ["N/A"])[0]
region = data.get("region", "N/A")
population = data.get("population", "N/A")
flag_url = data.get("flags", {}).get("png", "")
st.markdown(f"**Name:** {name}")
st.markdown(f"**Capital:** {capital}")
st.markdown(f"**Region:** {region}")
st.markdown(f"**Population:** {population:,}")
if flag_url:
st.image(flag_url, caption=f"{name} Flag")