Sebastien Peytrignet
commited on
Commit
•
98ec026
1
Parent(s):
f10fcad
upload app env and requirements
Browse files- .env +1 -0
- app.py +91 -0
- requirements.txt +15 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
EUROPEANA_API_KEY="snetrourst"
|
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import folium
|
4 |
+
from streamlit_folium import folium_static
|
5 |
+
from pyeuropeana import apis
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
import os
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Ensure that the API key is set
|
13 |
+
if 'EUROPEANA_API_KEY' not in os.environ:
|
14 |
+
st.error("EUROPEANA_API_KEY is not set in the environment variables. Please set it and restart the app.")
|
15 |
+
st.stop()
|
16 |
+
|
17 |
+
def get_provider_data(provider_name, rows=1000):
|
18 |
+
myquery = apis.search(
|
19 |
+
query='pl_wgs84_pos_lat:(*)',
|
20 |
+
qf=f'DATA_PROVIDER:"{provider_name}"',
|
21 |
+
rows=rows
|
22 |
+
)
|
23 |
+
|
24 |
+
myquery_df = pd.DataFrame(myquery["items"], columns=['edmPlaceLatitude', 'edmPlaceLongitude', 'id', 'country', 'dataProvider', 'dcCreator'])
|
25 |
+
|
26 |
+
def extract_single(x):
|
27 |
+
return x[0] if isinstance(x, list) and len(x) > 0 else x
|
28 |
+
|
29 |
+
for col in ['edmPlaceLatitude', 'edmPlaceLongitude', 'country', 'dataProvider', 'dcCreator']:
|
30 |
+
myquery_df[col] = myquery_df[col].apply(extract_single)
|
31 |
+
|
32 |
+
myquery_df['edmPlaceLatitude'] = pd.to_numeric(myquery_df['edmPlaceLatitude'], errors='coerce')
|
33 |
+
myquery_df['edmPlaceLongitude'] = pd.to_numeric(myquery_df['edmPlaceLongitude'], errors='coerce')
|
34 |
+
|
35 |
+
return myquery_df
|
36 |
+
|
37 |
+
# Set up the Streamlit app
|
38 |
+
st.title('Europeana Data Explorer')
|
39 |
+
|
40 |
+
# Input for provider name
|
41 |
+
provider_name = st.text_input('Enter the name of the data provider:')
|
42 |
+
|
43 |
+
# Button to trigger data fetch
|
44 |
+
if st.button('Fetch Data'):
|
45 |
+
if provider_name:
|
46 |
+
# Show loading message
|
47 |
+
with st.spinner('Fetching data...'):
|
48 |
+
# Get the data
|
49 |
+
df = get_provider_data(provider_name)
|
50 |
+
|
51 |
+
# Display the data
|
52 |
+
st.subheader(f'Data from {provider_name}')
|
53 |
+
st.write(f'Number of items retrieved: {len(df)}')
|
54 |
+
|
55 |
+
# Display the first few rows
|
56 |
+
st.subheader('First few rows of data:')
|
57 |
+
st.write(df.head())
|
58 |
+
|
59 |
+
# Create a map centered on the mean latitude and longitude
|
60 |
+
valid_coords = df.dropna(subset=['edmPlaceLatitude', 'edmPlaceLongitude'])
|
61 |
+
if not valid_coords.empty:
|
62 |
+
center_lat = valid_coords['edmPlaceLatitude'].mean()
|
63 |
+
center_lon = valid_coords['edmPlaceLongitude'].mean()
|
64 |
+
m = folium.Map(location=[center_lat, center_lon], zoom_start=2)
|
65 |
+
|
66 |
+
# Add markers for each item
|
67 |
+
for _, row in valid_coords.iterrows():
|
68 |
+
folium.Marker(
|
69 |
+
location=[row['edmPlaceLatitude'], row['edmPlaceLongitude']],
|
70 |
+
popup=f"ID: {row['id']}<br>Creator: {row['dcCreator']}<br>Country: {row['country']}",
|
71 |
+
tooltip=row['id']
|
72 |
+
).add_to(m)
|
73 |
+
|
74 |
+
# Display the map
|
75 |
+
st.subheader('Map of Object Locations')
|
76 |
+
folium_static(m)
|
77 |
+
else:
|
78 |
+
st.warning('No valid coordinates found in the data.')
|
79 |
+
|
80 |
+
# Option to download the full dataset
|
81 |
+
csv = df.to_csv(index=False)
|
82 |
+
st.download_button(
|
83 |
+
label="Download full dataset as CSV",
|
84 |
+
data=csv,
|
85 |
+
file_name=f"{provider_name}_data.csv",
|
86 |
+
mime="text/csv",
|
87 |
+
)
|
88 |
+
else:
|
89 |
+
st.warning('Please enter a provider name.')
|
90 |
+
|
91 |
+
# Run this app with: streamlit run app.py
|
requirements.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
geopandas
|
2 |
+
matplotlib
|
3 |
+
numpy
|
4 |
+
flake8
|
5 |
+
ipykernel
|
6 |
+
autopep8
|
7 |
+
pandas<2.0
|
8 |
+
scipy
|
9 |
+
shapely
|
10 |
+
nbconvert
|
11 |
+
python-dotenv
|
12 |
+
pyeuropeana
|
13 |
+
streamlit
|
14 |
+
folium
|
15 |
+
streamlit_folium
|