ZohaJaved commited on
Commit
520feef
Β·
verified Β·
1 Parent(s): 89e4a46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ st.set_page_config(page_title="Country Finder 🌍", page_icon="🌍")
5
+
6
+ st.title("🌍 Country Finder")
7
+ st.write("Type a country name to get info and see the flag!")
8
+
9
+ country_name = st.text_input("Enter a country")
10
+
11
+ if country_name:
12
+ url = f"https://restcountries.com/v3.1/name/{country_name}"
13
+ response = requests.get(url)
14
+
15
+ if response.status_code != 200:
16
+ st.error("Country not found. Try again! 😒")
17
+ else:
18
+ data = response.json()[0]
19
+ name = data.get("name", {}).get("common", "N/A")
20
+ capital = data.get("capital", ["N/A"])[0]
21
+ region = data.get("region", "N/A")
22
+ population = data.get("population", "N/A")
23
+ flag_url = data.get("flags", {}).get("png", "")
24
+
25
+ st.markdown(f"**Name:** {name}")
26
+ st.markdown(f"**Capital:** {capital}")
27
+ st.markdown(f"**Region:** {region}")
28
+ st.markdown(f"**Population:** {population:,}")
29
+
30
+ if flag_url:
31
+ st.image(flag_url, caption=f"{name} Flag")
32
+