Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
mois_disponibles = ['Janv.', 'Fev.', 'Mars', 'Avr.', 'Mai', 'Juin', 'Juil.', 'Août', 'Sept.', 'Oct.', 'Nov.', 'Dec.']
|
| 6 |
+
|
| 7 |
+
def generer_graphique(file, mois):
|
| 8 |
+
sheet1 = pd.read_excel(file.name, sheet_name='CDT Assemblage', skiprows=4)
|
| 9 |
+
sheet2 = pd.read_excel(file.name, sheet_name='CDT PE', skiprows=4)
|
| 10 |
+
|
| 11 |
+
def extraire(df, mois):
|
| 12 |
+
standards = df.iloc[:, 2]
|
| 13 |
+
valeurs = df[mois]
|
| 14 |
+
df_filtré = pd.DataFrame({'Standard': standards, 'Valeur': valeurs}).dropna()
|
| 15 |
+
exclure = ['Objectifs', 'Résultats', 'mat>', 'mat> B']
|
| 16 |
+
return df_filtré[~df_filtré['Standard'].astype(str).str.contains('|'.join(exclure), case=False)]
|
| 17 |
+
|
| 18 |
+
df1 = extraire(sheet1, mois)
|
| 19 |
+
df2 = extraire(sheet2, mois)
|
| 20 |
+
merged = pd.merge(df1, df2, on='Standard', suffixes=('_1', '_2'))
|
| 21 |
+
merged['Moyenne'] = merged[['Valeur_1', 'Valeur_2']].mean(axis=1)
|
| 22 |
+
|
| 23 |
+
ordre = sheet1.iloc[:, 2].dropna().tolist()
|
| 24 |
+
ordre_filtré = [s for s in ordre if s in merged['Standard'].values]
|
| 25 |
+
merged = merged.set_index('Standard').loc[ordre_filtré].reset_index()
|
| 26 |
+
|
| 27 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 28 |
+
ax.bar(merged['Standard'], merged['Moyenne'], color='skyblue')
|
| 29 |
+
ax.set_title(f"Moyenne des scores – {mois}")
|
| 30 |
+
ax.set_xlabel("Standards")
|
| 31 |
+
ax.set_ylabel("Moyenne")
|
| 32 |
+
plt.xticks(rotation=45, ha='right')
|
| 33 |
+
plt.tight_layout()
|
| 34 |
+
|
| 35 |
+
return fig
|
| 36 |
+
|
| 37 |
+
interface = gr.Interface(
|
| 38 |
+
fn=generer_graphique,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.File(label="Fichier Excel (.xlsx)", file_types=[".xlsx"]),
|
| 41 |
+
gr.Dropdown(choices=mois_disponibles, label="Mois")
|
| 42 |
+
],
|
| 43 |
+
outputs=gr.Plot(label="Graphique"),
|
| 44 |
+
title="Analyse de Maturité par Standard",
|
| 45 |
+
description="Chargez un fichier Excel, sélectionnez un mois, et visualisez la moyenne des scores."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
interface.launch()
|