Spaces:
Runtime error
Runtime error
LaurentTRIPIED
commited on
Commit
•
b807d87
1
Parent(s):
a7981ed
Pytorch V0.1
Browse files- app.py +8 -69
- requirements.txt +4 -2
app.py
CHANGED
@@ -1,15 +1,10 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
import folium
|
5 |
from streamlit_folium import folium_static
|
6 |
-
from transformers import pipeline
|
7 |
-
|
8 |
-
import tensorflow as tf
|
9 |
-
assert tf.__version__.startswith('2.')
|
10 |
-
print("TensorFlow version:", tf.__version__)
|
11 |
|
12 |
-
# Fonction pour récupérer les données de l'API
|
13 |
def get_data():
|
14 |
url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
|
15 |
response = requests.get(url)
|
@@ -20,7 +15,6 @@ def get_data():
|
|
20 |
else:
|
21 |
return [], 0
|
22 |
|
23 |
-
# Fonction pour l'onglet "Organisations engagées"
|
24 |
def display_organisations_engagees():
|
25 |
st.markdown("## OPEN DATA RSE")
|
26 |
st.markdown("### Découvrez les organisations engagées RSE de la métropole de Bordeaux")
|
@@ -38,70 +32,15 @@ def display_organisations_engagees():
|
|
38 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
39 |
st.dataframe(df, width=None, height=None)
|
40 |
|
41 |
-
# Fonction pour l'onglet "GeoRSE Insights"
|
42 |
-
def display_geo_rse_insights():
|
43 |
-
data, _ = get_data()
|
44 |
-
if data:
|
45 |
-
m = folium.Map(location=[44.84474, -0.60711], zoom_start=11)
|
46 |
-
for item in data:
|
47 |
-
point_geo = item.get('point_geo', [])
|
48 |
-
if point_geo:
|
49 |
-
lat, lon = point_geo
|
50 |
-
lat, lon = float(lat), float(lon)
|
51 |
-
if lat and lon:
|
52 |
-
folium.Marker(
|
53 |
-
[lat, lon],
|
54 |
-
popup=f"<b>{item.get('nom_courant_denomination', 'Sans nom')}</b><br>Action RSE: {item.get('action_rse', 'Non spécifié')}",
|
55 |
-
icon=folium.Icon(color="green", icon="leaf"),
|
56 |
-
).add_to(m)
|
57 |
-
folium_static(m)
|
58 |
-
|
59 |
-
# Fonction pour la classification des actions RSE
|
60 |
-
def classify_rse_actions(descriptions):
|
61 |
-
classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli")
|
62 |
-
categories = [
|
63 |
-
"La gouvernance de la structure",
|
64 |
-
"Les droits humains",
|
65 |
-
"Les conditions et relations de travail",
|
66 |
-
"La responsabilité environnementale",
|
67 |
-
"La loyauté des pratiques",
|
68 |
-
"Les questions relatives au consommateur et à la protection du consommateur",
|
69 |
-
"Les communautés et le développement local"
|
70 |
-
]
|
71 |
-
|
72 |
-
classified_data = []
|
73 |
-
for description in descriptions:
|
74 |
-
result = classifier(description, categories)
|
75 |
-
top_category = result['labels'][0]
|
76 |
-
classified_data.append(top_category)
|
77 |
-
|
78 |
-
return classified_data
|
79 |
-
|
80 |
-
# Nouvelle fonction pour l'onglet de classification RSE
|
81 |
-
def display_rse_categorizer():
|
82 |
-
st.header("Classification des Actions RSE")
|
83 |
-
st.write("Cet outil classe les actions RSE des entreprises selon les critères de la norme ISO 26000.")
|
84 |
-
|
85 |
-
data, _ = get_data()
|
86 |
-
if data:
|
87 |
-
descriptions = [item['action_rse'] for item in data if 'action_rse' in item]
|
88 |
-
categories = classify_rse_actions(descriptions)
|
89 |
-
for i, category in enumerate(categories):
|
90 |
-
st.write(f"Action RSE: {descriptions[i]}")
|
91 |
-
st.write(f"Catégorie prédite: {category}")
|
92 |
-
st.write("---")
|
93 |
-
|
94 |
-
# Main function orchestrating the app UI
|
95 |
def main():
|
96 |
-
st.sidebar.title("
|
97 |
-
app_mode = st.sidebar.radio("
|
98 |
-
|
99 |
-
if app_mode == "
|
|
|
|
|
|
|
100 |
display_organisations_engagees()
|
101 |
-
elif app_mode == "Localisation":
|
102 |
-
display_geo_rse_insights()
|
103 |
-
elif app_mode == "Type d'actions RSE":
|
104 |
-
display_rse_categorizer()
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
main()
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
import folium
|
6 |
from streamlit_folium import folium_static
|
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
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)
|
|
|
15 |
else:
|
16 |
return [], 0
|
17 |
|
|
|
18 |
def display_organisations_engagees():
|
19 |
st.markdown("## OPEN DATA RSE")
|
20 |
st.markdown("### Découvrez les organisations engagées RSE de la métropole de Bordeaux")
|
|
|
32 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
33 |
st.dataframe(df, width=None, height=None)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def main():
|
36 |
+
st.sidebar.title("Navigation")
|
37 |
+
app_mode = st.sidebar.radio("Choose a page", ["Home", "Organisations Engagées"])
|
38 |
+
|
39 |
+
if app_mode == "Home":
|
40 |
+
st.header("Welcome to the RSE Data Explorer!")
|
41 |
+
st.markdown("Please select a page on the left.")
|
42 |
+
elif app_mode == "Organisations Engagées":
|
43 |
display_organisations_engagees()
|
|
|
|
|
|
|
|
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
main()
|
requirements.txt
CHANGED
@@ -3,5 +3,7 @@ pandas
|
|
3 |
requests
|
4 |
folium
|
5 |
streamlit-folium
|
6 |
-
transformers
|
7 |
-
|
|
|
|
|
|
3 |
requests
|
4 |
folium
|
5 |
streamlit-folium
|
6 |
+
transformers
|
7 |
+
torch
|
8 |
+
torchvision
|
9 |
+
torchaudio
|