Spaces:
Sleeping
Sleeping
nounouille commited on
Commit ·
a39cafb
1
Parent(s): ec3efd2
🧼 Nettoyage des chemins, chargement via Hub
Browse files
app.py
CHANGED
|
@@ -19,11 +19,11 @@ from src.utils.alert_email import send_alert_email
|
|
| 19 |
from transformers import pipeline as hf_pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
| 20 |
import plotly.express as px
|
| 21 |
|
| 22 |
-
# === Chargement du modèle
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
# === Globals ===
|
| 29 |
HISTORY_LIMIT = 5
|
|
@@ -32,8 +32,8 @@ ALERT_WINDOW_MINUTES = 5
|
|
| 32 |
ALERT_COOLDOWN_MINUTES = 10
|
| 33 |
FEEDBACK_ALERT_THRESHOLD = 3
|
| 34 |
alert_history = []
|
|
|
|
| 35 |
FEEDBACK_CSV = os.path.abspath("feedback_log_emotions.csv")
|
| 36 |
-
# EXPORT_CSV_PATH = os.path.abspath("outputs/emotion_stats_2000.csv")
|
| 37 |
EXPORT_XLSX_PATH = os.path.abspath("outputs/emotion_summary.xlsx")
|
| 38 |
suspect_text = ""
|
| 39 |
|
|
@@ -87,12 +87,6 @@ def contains_intense_words(text):
|
|
| 87 |
words = re.findall(r"\w+", text.lower())
|
| 88 |
return any(w in INTENSE_WORDS for w in words)
|
| 89 |
|
| 90 |
-
model_path = Path("notebooks/models/emotions/model").resolve().as_posix()
|
| 91 |
-
tokenizer_path = Path("notebooks/models/emotions/tokenizer").resolve().as_posix()
|
| 92 |
-
local_model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 93 |
-
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
|
| 94 |
-
emotion_pipeline = hf_pipeline("text-classification", model=local_model, tokenizer=tokenizer, top_k=None, function_to_apply="sigmoid")
|
| 95 |
-
|
| 96 |
def predict_emotions(text):
|
| 97 |
global suspect_text
|
| 98 |
if not text.strip():
|
|
@@ -107,7 +101,7 @@ def predict_emotions(text):
|
|
| 107 |
alert_banner = ""
|
| 108 |
if contains_intense_words(text):
|
| 109 |
suspect_text = text
|
| 110 |
-
alert_banner = "🟥 <strong style='color:red;'>⚠️ Ce tweet contient un mot intense. Consultez l’onglet \
|
| 111 |
html_output = f"<h2 style='text-align:center;'>🧠 Résultat : {result}</h2>" + (f"<div style='margin-top:10px'>{alert_banner}</div>" if alert_banner else "")
|
| 112 |
return html_output, update_pie_chart(), update_history(), text if alert_banner else ""
|
| 113 |
|
|
@@ -180,7 +174,6 @@ def update_feedback_stats():
|
|
| 180 |
except:
|
| 181 |
return "Erreur lecture stats."
|
| 182 |
|
| 183 |
-
|
| 184 |
def generate_emotion_summary():
|
| 185 |
if not history:
|
| 186 |
return None
|
|
@@ -234,9 +227,4 @@ with gr.Blocks() as demo:
|
|
| 234 |
gen_button.click(fn=generate_emotion_summary, outputs=download_btn)
|
| 235 |
|
| 236 |
if __name__ == "__main__":
|
| 237 |
-
demo.launch()
|
| 238 |
-
|
| 239 |
-
# # Lancement de l'interface
|
| 240 |
-
#
|
| 241 |
-
# python app.py
|
| 242 |
-
|
|
|
|
| 19 |
from transformers import pipeline as hf_pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
| 20 |
import plotly.express as px
|
| 21 |
|
| 22 |
+
# === Chargement du modèle hébergé sur Hugging Face Hub ===
|
| 23 |
+
MODEL_REPO = "arnaud66170/electra-p9v2.1"
|
| 24 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_REPO)
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
|
| 26 |
+
emotion_pipeline = hf_pipeline("text-classification", model=model, tokenizer=tokenizer, top_k=None, function_to_apply="sigmoid")
|
| 27 |
|
| 28 |
# === Globals ===
|
| 29 |
HISTORY_LIMIT = 5
|
|
|
|
| 32 |
ALERT_COOLDOWN_MINUTES = 10
|
| 33 |
FEEDBACK_ALERT_THRESHOLD = 3
|
| 34 |
alert_history = []
|
| 35 |
+
|
| 36 |
FEEDBACK_CSV = os.path.abspath("feedback_log_emotions.csv")
|
|
|
|
| 37 |
EXPORT_XLSX_PATH = os.path.abspath("outputs/emotion_summary.xlsx")
|
| 38 |
suspect_text = ""
|
| 39 |
|
|
|
|
| 87 |
words = re.findall(r"\w+", text.lower())
|
| 88 |
return any(w in INTENSE_WORDS for w in words)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
def predict_emotions(text):
|
| 91 |
global suspect_text
|
| 92 |
if not text.strip():
|
|
|
|
| 101 |
alert_banner = ""
|
| 102 |
if contains_intense_words(text):
|
| 103 |
suspect_text = text
|
| 104 |
+
alert_banner = "🟥 <strong style='color:red;'>⚠️ Ce tweet contient un mot intense. Consultez l’onglet \"Cas suspects\" pour audit.</strong>"
|
| 105 |
html_output = f"<h2 style='text-align:center;'>🧠 Résultat : {result}</h2>" + (f"<div style='margin-top:10px'>{alert_banner}</div>" if alert_banner else "")
|
| 106 |
return html_output, update_pie_chart(), update_history(), text if alert_banner else ""
|
| 107 |
|
|
|
|
| 174 |
except:
|
| 175 |
return "Erreur lecture stats."
|
| 176 |
|
|
|
|
| 177 |
def generate_emotion_summary():
|
| 178 |
if not history:
|
| 179 |
return None
|
|
|
|
| 227 |
gen_button.click(fn=generate_emotion_summary, outputs=download_btn)
|
| 228 |
|
| 229 |
if __name__ == "__main__":
|
| 230 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|