Spaces:
Runtime error
Runtime error
Commit
·
fadc8f0
1
Parent(s):
15269fc
3 onglets + carte
Browse files- app.py +40 -32
- requirements.txt +5 -0
app.py
CHANGED
|
@@ -1,20 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
Args:
|
| 10 |
-
page (int): Numéro de la page à récupérer.
|
| 11 |
-
rows_per_page (int): Nombre de lignes par page.
|
| 12 |
-
|
| 13 |
-
Returns:
|
| 14 |
-
List[Dict]: Données de la page spécifiée sous forme de liste de dictionnaires.
|
| 15 |
-
"""
|
| 16 |
-
# Construction de l'URL avec pagination
|
| 17 |
-
url = f"https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows={rows_per_page}&start={page * rows_per_page}"
|
| 18 |
response = requests.get(url)
|
| 19 |
if response.status_code == 200:
|
| 20 |
data = response.json()
|
|
@@ -23,30 +15,46 @@ def get_data(page, rows_per_page=25):
|
|
| 23 |
else:
|
| 24 |
return [], 0
|
| 25 |
|
|
|
|
| 26 |
def display_organisations_engagees():
|
| 27 |
-
""
|
| 28 |
-
|
| 29 |
-
"""
|
| 30 |
-
# Pagination
|
| 31 |
-
page_number = st.sidebar.number_input("Page number", min_value=0, value=0, step=1)
|
| 32 |
-
data, total_hits = get_data(page_number)
|
| 33 |
|
|
|
|
| 34 |
if data:
|
| 35 |
df = pd.DataFrame(data)
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
cols_order = [col for col in cols_order if col in df.columns]
|
| 40 |
-
df = df[cols_order]
|
| 41 |
-
|
| 42 |
-
# Affichage des données avec les colonnes réordonnées
|
| 43 |
-
st.write(f"Organisations engagées - Page {page_number + 1} sur {((total_hits - 1) // 25) + 1}", df)
|
| 44 |
-
else:
|
| 45 |
-
st.write("Aucune donnée disponible.")
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
st.sidebar.title("Navigation")
|
| 49 |
-
app_mode = st.sidebar.
|
| 50 |
|
| 51 |
if app_mode == "Organisations engagées":
|
| 52 |
-
display_organisations_engagees()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
+
import folium
|
| 5 |
+
from streamlit_folium import folium_static
|
| 6 |
|
| 7 |
+
# Fonction pour récupérer les données de l'API (ajustez selon vos besoins)
|
| 8 |
+
def get_data():
|
| 9 |
+
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
response = requests.get(url)
|
| 11 |
if response.status_code == 200:
|
| 12 |
data = response.json()
|
|
|
|
| 15 |
else:
|
| 16 |
return [], 0
|
| 17 |
|
| 18 |
+
# Fonction pour l'onglet "Organisations engagées"
|
| 19 |
def display_organisations_engagees():
|
| 20 |
+
st.markdown("## OPEN DATA RSE")
|
| 21 |
+
st.markdown("### Découvrez les organisations engagées RSE de la métropole de Bordeaux")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
data, _ = get_data()
|
| 24 |
if data:
|
| 25 |
df = pd.DataFrame(data)
|
| 26 |
+
# Sélection et réorganisation des colonnes
|
| 27 |
+
df = df[["nom_courant_denomination", "commune", "libelle_section_naf", "tranche_effectif_entreprise", "action_rse"]]
|
| 28 |
+
st.dataframe(df, width=None, height=None) # Ajustez width et height si nécessaire
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Fonction pour afficher la carte avec Folium (à ajuster selon vos données)
|
| 31 |
+
def display_map():
|
| 32 |
+
data, _ = get_data()
|
| 33 |
+
if data:
|
| 34 |
+
# Création d'une carte centrée autour de Bordeaux
|
| 35 |
+
m = folium.Map(location=[44.8378, -0.5792], zoom_start=12)
|
| 36 |
+
# Ajout des entreprises sur la carte
|
| 37 |
+
for item in data:
|
| 38 |
+
if 'geolocalisation' in item:
|
| 39 |
+
folium.Marker(location=[item['geolocalisation'][0], item['geolocalisation'][1]],
|
| 40 |
+
popup=item["nom_courant_denomination"]).add_to(m)
|
| 41 |
+
folium_static(m)
|
| 42 |
+
|
| 43 |
+
# Fonction pour l'onglet "Dialoguer avec l'assistant IA RSE bziiit"
|
| 44 |
+
def display_dialogue():
|
| 45 |
+
st.markdown("# Patientez quelques heures encore... :)")
|
| 46 |
+
|
| 47 |
+
# Création des onglets de l'application
|
| 48 |
+
def main():
|
| 49 |
st.sidebar.title("Navigation")
|
| 50 |
+
app_mode = st.sidebar.radio("Choisissez l'onglet", ["Organisations engagées", "Carte", "Dialoguer avec l'assistant IA RSE bziiit"])
|
| 51 |
|
| 52 |
if app_mode == "Organisations engagées":
|
| 53 |
+
display_organisations_engagees()
|
| 54 |
+
elif app_mode == "Carte":
|
| 55 |
+
display_map()
|
| 56 |
+
elif app_mode == "Dialoguer avec l'assistant IA RSE bziiit":
|
| 57 |
+
display_dialogue()
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
requests
|
| 4 |
+
folium
|
| 5 |
+
streamlit-folium
|