Upload folder using huggingface_hub
Browse files- Dockerfile +15 -13
- README.md +9 -0
- app.py +60 -96
- requirements.txt +0 -4
Dockerfile
CHANGED
|
@@ -1,21 +1,23 @@
|
|
| 1 |
-
FROM python:3.
|
| 2 |
|
| 3 |
-
WORKDIR /app
|
| 4 |
|
| 5 |
-
RUN apt-get update
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
COPY
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
| 14 |
-
RUN
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
|
| 3 |
+
WORKDIR /home/app
|
| 4 |
|
| 5 |
+
RUN apt-get update \
|
| 6 |
+
&& apt-get install -y --no-install-recommends nano unzip curl \
|
|
|
|
|
|
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
+
COPY . .
|
|
|
|
| 10 |
|
| 11 |
+
RUN curl -fsSL https://get.deta.dev/cli.sh | sh
|
| 12 |
|
| 13 |
+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
| 14 |
+
RUN unzip awscliv2.zip
|
| 15 |
+
RUN ./aws/install
|
| 16 |
|
| 17 |
+
COPY requirements.txt /dependencies/requirements.txt
|
| 18 |
+
RUN pip install -r /dependencies/requirements.txt
|
| 19 |
|
| 20 |
+
# Environment variables will be passed at runtime via docker run -e flags
|
| 21 |
+
# No need to set them here in the Dockerfile
|
| 22 |
+
|
| 23 |
+
CMD streamlit run app.py
|
README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: "Bloc3_Streamlit"
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
app.py
CHANGED
|
@@ -1,108 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
import streamlit as st
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
-
import
|
| 7 |
-
from urllib.error import URLError
|
| 8 |
-
from sqlalchemy import create_engine, text
|
| 9 |
-
from datetime import datetime, timedelta
|
| 10 |
-
|
| 11 |
-
@st.cache_data
|
| 12 |
-
def check_table_exists() -> bool:
|
| 13 |
-
"""Check if the transactions table exists in the database"""
|
| 14 |
-
try:
|
| 15 |
-
engine = create_engine(os.environ['BACKEND_STORE_URI'])
|
| 16 |
-
with engine.connect() as conn:
|
| 17 |
-
result = conn.execute(text("""
|
| 18 |
-
SELECT EXISTS (
|
| 19 |
-
SELECT FROM information_schema.tables
|
| 20 |
-
WHERE table_name = 'currentTransaction'
|
| 21 |
-
);
|
| 22 |
-
"""))
|
| 23 |
-
return result.scalar()
|
| 24 |
-
except Exception as e:
|
| 25 |
-
st.error(f"Error checking table existence: {str(e)}")
|
| 26 |
-
return False
|
| 27 |
-
|
| 28 |
-
@st.cache_data
|
| 29 |
-
def get_data() -> pd.DataFrame:
|
| 30 |
-
"""Fetch transactions from the previous day"""
|
| 31 |
-
try:
|
| 32 |
-
conn = st.connection(
|
| 33 |
-
"postgresql",
|
| 34 |
-
type="sql",
|
| 35 |
-
url=os.environ['BACKEND_STORE_URI']
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
query = f"""
|
| 43 |
-
SELECT * FROM transactions
|
| 44 |
-
WHERE trans_date_trans_time >= '{yesterday} 00:00:00'
|
| 45 |
-
AND trans_date_trans_time < '{today} 00:00:00'
|
| 46 |
-
ORDER BY trans_date_trans_time DESC
|
| 47 |
-
"""
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
st.error("⚠️ La table 'transactions' n'existe pas dans la base de données!")
|
| 61 |
-
st.info("""
|
| 62 |
-
### Pour créer la table, exécutez:
|
| 63 |
-
```bash
|
| 64 |
-
python create_database.py
|
| 65 |
-
```
|
| 66 |
-
Ce script va:
|
| 67 |
-
- Créer la table 'transactions' avec le bon schéma
|
| 68 |
-
- Optionnellement charger des données d'exemple
|
| 69 |
-
""")
|
| 70 |
-
st.stop()
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
st.warning(f"⚠️ Aucune transaction trouvée pour le {JOUR_HIER}")
|
| 79 |
-
st.info("Assurez-vous que des transactions ont été chargées dans la base de données pour cette date.")
|
| 80 |
-
else:
|
| 81 |
-
st.success(f"✅ {len(df)} transactions trouvées")
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if 'prediction' in df.columns:
|
| 92 |
-
fraud_count = len(df[df['prediction'] == 1])
|
| 93 |
-
fraud_amount = df[df['prediction'] == 1]['amt'].sum()
|
| 94 |
-
st.metric(label="Nombre de transactions frauduleuses", value=fraud_count)
|
| 95 |
-
st.metric(label="Montant total des transactions frauduleuses", value=f"${fraud_amount:,.2f}")
|
| 96 |
-
elif 'is_fraud' in df.columns:
|
| 97 |
-
fraud_count = len(df[df['is_fraud'] == 1])
|
| 98 |
-
fraud_amount = df[df['is_fraud'] == 1]['amt'].sum()
|
| 99 |
-
st.metric(label="Nombre de transactions frauduleuses", value=fraud_count)
|
| 100 |
-
st.metric(label="Montant total des transactions frauduleuses", value=f"${fraud_amount:,.2f}")
|
| 101 |
-
else:
|
| 102 |
-
st.info("Colonne 'prediction' ou 'is_fraud' non trouvée")
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dashboard/test_quality_dashboard.py
|
| 2 |
+
import os
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
+
import psycopg2
|
| 5 |
import pandas as pd
|
| 6 |
+
import plotly.express as px
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
from dotenv import load_dotenv, find_dotenv
|
| 9 |
+
env_path = find_dotenv()
|
| 10 |
+
load_dotenv(env_path, override=True)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
st.title("📊 Dashboard Suivi des indicateurs qualité")
|
| 14 |
+
# st.markdown("""
|
| 15 |
+
# Ce dashboard présente les indicateurs clés de performance (KPI) des tests automatisés
|
| 16 |
+
# exécutés sur le modèle de détection de fraude. Il permet de suivre la qualité du modèle
|
| 17 |
+
# au fil du temps et d'identifier rapidement les éventuels problèmes.
|
| 18 |
+
# """)
|
| 19 |
|
| 20 |
+
# Connexion DB
|
| 21 |
+
conn = psycopg2.connect(os.getenv("BACKEND_STORE_URI"))
|
| 22 |
|
| 23 |
+
# KPIs
|
| 24 |
+
col1, col2, col3, col4 = st.columns(4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Dernières 24h
|
| 27 |
+
df_recent = pd.read_sql("""
|
| 28 |
+
SELECT
|
| 29 |
+
COUNT(*) as total,
|
| 30 |
+
SUM(CASE WHEN status = 'passed' THEN 1 ELSE 0 END) as passed,
|
| 31 |
+
AVG(duration_ms) as avg_duration
|
| 32 |
+
FROM test_logs
|
| 33 |
+
WHERE created_at >= NOW() - INTERVAL '24 hours'
|
| 34 |
+
""", conn)
|
| 35 |
|
| 36 |
+
col1.metric("Total Tests (24h)", df_recent['total'].iloc[0])
|
| 37 |
+
col2.metric("Taux Réussite", f"{df_recent['passed'].iloc[0] / df_recent['total'].iloc[0] * 100:.1f}%")
|
| 38 |
+
col3.metric("Durée Moyenne", f"{df_recent['avg_duration'].iloc[0]:.0f}ms")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Graphique évolution accuracy
|
| 41 |
+
df_accuracy = pd.read_sql("""
|
| 42 |
+
SELECT
|
| 43 |
+
DATE(created_at) as date,
|
| 44 |
+
AVG(model_accuracy) as accuracy
|
| 45 |
+
FROM test_logs
|
| 46 |
+
WHERE test_name = 'test_model_accuracy_threshold'
|
| 47 |
+
AND created_at >= NOW() - INTERVAL '30 days'
|
| 48 |
+
GROUP BY DATE(created_at)
|
| 49 |
+
ORDER BY date
|
| 50 |
+
""", conn)
|
| 51 |
|
| 52 |
+
fig = px.line(df_accuracy, x='date', y='accuracy',
|
| 53 |
+
title="Évolution Accuracy (30 jours)",
|
| 54 |
+
labels={'accuracy': 'Accuracy', 'date': 'Date'})
|
| 55 |
+
fig.add_hline(y=0.92, line_dash="dash", line_color="red",
|
| 56 |
+
annotation_text="Seuil minimum (92%)")
|
| 57 |
+
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# Table des derniers échecs
|
| 60 |
+
st.subheader("🔴 Derniers Tests Échoués")
|
| 61 |
+
df_failures = pd.read_sql("""
|
| 62 |
+
SELECT
|
| 63 |
+
test_name,
|
| 64 |
+
error_message,
|
| 65 |
+
created_at,
|
| 66 |
+
git_commit_hash
|
| 67 |
+
FROM test_logs
|
| 68 |
+
WHERE status = 'failed'
|
| 69 |
+
ORDER BY created_at DESC
|
| 70 |
+
LIMIT 10
|
| 71 |
+
""", conn)
|
| 72 |
+
st.dataframe(df_failures)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,3 @@
|
|
| 1 |
-
altair
|
| 2 |
-
pandas
|
| 3 |
-
streamlit
|
| 4 |
-
dotenv
|
| 5 |
boto3
|
| 6 |
requests>=2.31.0,<3
|
| 7 |
pandas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
boto3
|
| 2 |
requests>=2.31.0,<3
|
| 3 |
pandas
|