Commit
·
bb3771a
1
Parent(s):
d3827eb
Pytorch V0.5
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import requests
|
|
@@ -10,43 +9,16 @@ def get_data():
|
|
| 10 |
response = requests.get(url)
|
| 11 |
if response.status_code == 200:
|
| 12 |
data = response.json()
|
| 13 |
-
records = data
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
for record in records:
|
| 17 |
-
item = record["fields"]
|
| 18 |
-
point_geo = item.get("point_geo", {})
|
| 19 |
-
if isinstance(point_geo, dict):
|
| 20 |
-
lat = point_geo.get("lat")
|
| 21 |
-
lon = point_geo.get("lon")
|
| 22 |
-
if lat and lon:
|
| 23 |
-
item['latitude'] = lat
|
| 24 |
-
item['longitude'] = lon
|
| 25 |
-
cleaned_data.append(item)
|
| 26 |
-
return cleaned_data, data.get("nhits", 0)
|
| 27 |
-
else:
|
| 28 |
-
return [], 0
|
| 29 |
-
|
| 30 |
-
def display_map(data):
|
| 31 |
-
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 32 |
-
for item in data:
|
| 33 |
-
lat = item.get('latitude')
|
| 34 |
-
lon = item.get('longitude')
|
| 35 |
-
if lat and lon:
|
| 36 |
-
folium.Marker(
|
| 37 |
-
[lat, lon],
|
| 38 |
-
icon=folium.Icon(color="green", icon="leaf"),
|
| 39 |
-
popup=item.get('Nom', 'Sans nom'),
|
| 40 |
-
).add_to(m)
|
| 41 |
-
folium_static(m)
|
| 42 |
|
| 43 |
-
def display_organisations_engagees():
|
| 44 |
st.markdown("## OPEN DATA RSE")
|
| 45 |
st.markdown("### Découvrez les organisations engagées RSE de la métropole de Bordeaux")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
if
|
| 49 |
-
df = pd.DataFrame(data)
|
| 50 |
df = df.rename(columns={
|
| 51 |
"nom_courant_denomination": "Nom",
|
| 52 |
"commune": "Commune",
|
|
@@ -55,16 +27,30 @@ def display_organisations_engagees():
|
|
| 55 |
"action_rse": "Action RSE"
|
| 56 |
})
|
| 57 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
| 58 |
-
st.dataframe(df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
def main():
|
| 61 |
st.sidebar.title("Navigation")
|
| 62 |
app_mode = st.sidebar.radio("Choisissez l'onglet", ["Organisations engagées", "Localisation des Entreprises"])
|
| 63 |
|
|
|
|
|
|
|
| 64 |
if app_mode == "Organisations engagées":
|
| 65 |
-
display_organisations_engagees()
|
| 66 |
elif app_mode == "Localisation des Entreprises":
|
| 67 |
-
data, _ = get_data()
|
| 68 |
display_map(data)
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
|
|
|
| 9 |
response = requests.get(url)
|
| 10 |
if response.status_code == 200:
|
| 11 |
data = response.json()
|
| 12 |
+
records = data["records"]
|
| 13 |
+
return [record["fields"] for record in records]
|
| 14 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
def display_organisations_engagees(data):
|
| 17 |
st.markdown("## OPEN DATA RSE")
|
| 18 |
st.markdown("### Découvrez les organisations engagées RSE de la métropole de Bordeaux")
|
| 19 |
|
| 20 |
+
df = pd.DataFrame(data)
|
| 21 |
+
if not df.empty:
|
|
|
|
| 22 |
df = df.rename(columns={
|
| 23 |
"nom_courant_denomination": "Nom",
|
| 24 |
"commune": "Commune",
|
|
|
|
| 27 |
"action_rse": "Action RSE"
|
| 28 |
})
|
| 29 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
| 30 |
+
st.dataframe(df)
|
| 31 |
+
else:
|
| 32 |
+
st.write("Aucune donnée disponible.")
|
| 33 |
+
|
| 34 |
+
def display_map(data):
|
| 35 |
+
m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
|
| 36 |
+
for item in data:
|
| 37 |
+
if 'latitude' in item and 'longitude' in item:
|
| 38 |
+
folium.Marker(
|
| 39 |
+
[item['latitude'], item['longitude']],
|
| 40 |
+
icon=folium.Icon(color="green", icon="leaf"),
|
| 41 |
+
popup=item.get('Nom', 'Sans nom'),
|
| 42 |
+
).add_to(m)
|
| 43 |
+
folium_static(m)
|
| 44 |
|
| 45 |
def main():
|
| 46 |
st.sidebar.title("Navigation")
|
| 47 |
app_mode = st.sidebar.radio("Choisissez l'onglet", ["Organisations engagées", "Localisation des Entreprises"])
|
| 48 |
|
| 49 |
+
data = get_data()
|
| 50 |
+
|
| 51 |
if app_mode == "Organisations engagées":
|
| 52 |
+
display_organisations_engagees(data)
|
| 53 |
elif app_mode == "Localisation des Entreprises":
|
|
|
|
| 54 |
display_map(data)
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|