Spaces:
Runtime error
Runtime error
Commit
·
f7f5fe1
1
Parent(s):
0fff078
V1.0 RSECategorizer.py
Browse files- RSECategorizer.py +32 -0
- app.py +41 -15
RSECategorizer.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# RSECategorizer.py
|
| 2 |
+
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Charger le pipeline de classification avec un modèle léger
|
| 7 |
+
classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli")
|
| 8 |
+
|
| 9 |
+
def classify_rse_actions(descriptions):
|
| 10 |
+
categories = [
|
| 11 |
+
"La gouvernance de la structure",
|
| 12 |
+
"Les droits humains",
|
| 13 |
+
"Les conditions et relations de travail",
|
| 14 |
+
"La responsabilité environnementale",
|
| 15 |
+
"La loyauté des pratiques",
|
| 16 |
+
"Les questions relatives au consommateur et à la protection du consommateur",
|
| 17 |
+
"Les communautés et le développement local"
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
classified_data = []
|
| 21 |
+
for description in descriptions:
|
| 22 |
+
# Classification de chaque description
|
| 23 |
+
result = classifier(description, categories)
|
| 24 |
+
# Récupération de la catégorie avec la probabilité la plus élevée
|
| 25 |
+
top_category = result['labels'][0]
|
| 26 |
+
classified_data.append(top_category)
|
| 27 |
+
|
| 28 |
+
return classified_data
|
| 29 |
+
|
| 30 |
+
# Exemple d'utilisation (à des fins de test, à commenter ou supprimer pour l'intégration finale)
|
| 31 |
+
# descriptions = ["Promotion de l'énergie renouvelable", "Amélioration des conditions de travail"]
|
| 32 |
+
# print(classify_rse_actions(descriptions))
|
app.py
CHANGED
|
@@ -3,6 +3,7 @@ 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
|
| 8 |
def get_data():
|
|
@@ -33,33 +34,58 @@ def display_organisations_engagees():
|
|
| 33 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
| 34 |
st.dataframe(df, width=None, height=None)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
def display_geo_rse_insights():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
data, _ = get_data()
|
| 39 |
if data:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
[lat, lon],
|
| 49 |
-
popup=f"<b>{item.get('nom_courant_denomination', 'Sans nom')}</b><br>Action RSE: {item.get('action_rse', 'Non spécifié')}",
|
| 50 |
-
icon=folium.Icon(color="green", icon="leaf"),
|
| 51 |
-
).add_to(m)
|
| 52 |
-
folium_static(m)
|
| 53 |
|
| 54 |
# Main function orchestrating the app UI
|
| 55 |
def main():
|
| 56 |
st.sidebar.title("Navigation")
|
| 57 |
-
app_mode = st.sidebar.radio("Choisissez l'onglet", ["Organisations engagées", "GeoRSE Insights"])
|
| 58 |
|
| 59 |
if app_mode == "Organisations engagées":
|
| 60 |
display_organisations_engagees()
|
| 61 |
elif app_mode == "GeoRSE Insights":
|
| 62 |
display_geo_rse_insights()
|
|
|
|
|
|
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
main()
|
|
|
|
| 3 |
import requests
|
| 4 |
import folium
|
| 5 |
from streamlit_folium import folium_static
|
| 6 |
+
from transformers import pipeline
|
| 7 |
|
| 8 |
# Fonction pour récupérer les données de l'API
|
| 9 |
def get_data():
|
|
|
|
| 34 |
df = df[["Nom", "Commune", "Section NAF", "Effectif", "Action RSE"]]
|
| 35 |
st.dataframe(df, width=None, height=None)
|
| 36 |
|
| 37 |
+
# Fonction pour l'onglet "GeoRSE Insights"
|
| 38 |
def display_geo_rse_insights():
|
| 39 |
+
# La même fonction que celle définie précédemment pour afficher la carte
|
| 40 |
+
|
| 41 |
+
# Classification des actions RSE basée sur les descriptions
|
| 42 |
+
def classify_rse_actions(descriptions):
|
| 43 |
+
classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli")
|
| 44 |
+
categories = [
|
| 45 |
+
"La gouvernance de la structure",
|
| 46 |
+
"Les droits humains",
|
| 47 |
+
"Les conditions et relations de travail",
|
| 48 |
+
"La responsabilité environnementale",
|
| 49 |
+
"La loyauté des pratiques",
|
| 50 |
+
"Les questions relatives au consommateur et à la protection du consommateur",
|
| 51 |
+
"Les communautés et le développement local"
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
classified_data = []
|
| 55 |
+
for description in descriptions:
|
| 56 |
+
result = classifier(description, categories)
|
| 57 |
+
top_category = result['labels'][0]
|
| 58 |
+
classified_data.append(top_category)
|
| 59 |
+
|
| 60 |
+
return classified_data
|
| 61 |
+
|
| 62 |
+
# Nouvelle fonction pour l'onglet de classification RSE
|
| 63 |
+
def display_rse_categorizer():
|
| 64 |
+
st.header("Classification des Actions RSE")
|
| 65 |
+
st.write("Classification automatique des actions RSE des entreprises.")
|
| 66 |
+
|
| 67 |
data, _ = get_data()
|
| 68 |
if data:
|
| 69 |
+
descriptions = [item['action_rse'] for item in data if 'action_rse' in item]
|
| 70 |
+
categories = classify_rse_actions(descriptions)
|
| 71 |
+
|
| 72 |
+
# Affichage des résultats
|
| 73 |
+
for i, category in enumerate(categories):
|
| 74 |
+
st.write(f"Action RSE: {descriptions[i]}")
|
| 75 |
+
st.write(f"Catégorie prédite: {category}")
|
| 76 |
+
st.write("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Main function orchestrating the app UI
|
| 79 |
def main():
|
| 80 |
st.sidebar.title("Navigation")
|
| 81 |
+
app_mode = st.sidebar.radio("Choisissez l'onglet", ["Organisations engagées", "GeoRSE Insights", "Classification RSE"])
|
| 82 |
|
| 83 |
if app_mode == "Organisations engagées":
|
| 84 |
display_organisations_engagees()
|
| 85 |
elif app_mode == "GeoRSE Insights":
|
| 86 |
display_geo_rse_insights()
|
| 87 |
+
elif app_mode == "Classification RSE":
|
| 88 |
+
display_rse_categorizer()
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
main()
|