Update app.py
Browse files
app.py
CHANGED
|
@@ -61,14 +61,17 @@ DIMINISHERS = [r"\bun[e]?\s+peu\b", r"\bassez\b", r"\bplut[oô]t\b", r"\bl[eé]
|
|
| 61 |
INTENSIFIER_W, DIMINISHER_W = 1.5, 0.7
|
| 62 |
|
| 63 |
# --------------- OpenAI (optionnel) ---------------
|
|
|
|
| 64 |
OPENAI_AVAILABLE = False
|
| 65 |
try:
|
| 66 |
from openai import OpenAI
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
except Exception:
|
| 70 |
OPENAI_AVAILABLE = False
|
| 71 |
|
|
|
|
| 72 |
# ---------------- Utils ----------------
|
| 73 |
def normalize(t:str)->str:
|
| 74 |
if not isinstance(t,str): return ""
|
|
@@ -211,8 +214,9 @@ def analyze_text(pasted_txt, has_sc, sep_chr,
|
|
| 211 |
if do_anonymize:
|
| 212 |
df["comment"]=df["comment"].apply(anonymize)
|
| 213 |
|
|
|
|
| 214 |
if (use_oa_sent or use_oa_themes or use_oa_summary) and not OPENAI_AVAILABLE:
|
| 215 |
-
|
| 216 |
|
| 217 |
# HF sentiment (optionnel)
|
| 218 |
HF_AVAILABLE=False
|
|
|
|
| 61 |
INTENSIFIER_W, DIMINISHER_W = 1.5, 0.7
|
| 62 |
|
| 63 |
# --------------- OpenAI (optionnel) ---------------
|
| 64 |
+
# --- OpenAI (optionnel, robuste) ---
|
| 65 |
OPENAI_AVAILABLE = False
|
| 66 |
try:
|
| 67 |
from openai import OpenAI
|
| 68 |
+
if os.getenv("OPENAI_API_KEY"):
|
| 69 |
+
_client = OpenAI()
|
| 70 |
+
OPENAI_AVAILABLE = True
|
| 71 |
except Exception:
|
| 72 |
OPENAI_AVAILABLE = False
|
| 73 |
|
| 74 |
+
|
| 75 |
# ---------------- Utils ----------------
|
| 76 |
def normalize(t:str)->str:
|
| 77 |
if not isinstance(t,str): return ""
|
|
|
|
| 214 |
if do_anonymize:
|
| 215 |
df["comment"]=df["comment"].apply(anonymize)
|
| 216 |
|
| 217 |
+
# après (on retombe sur HF/règles automatiquement)
|
| 218 |
if (use_oa_sent or use_oa_themes or use_oa_summary) and not OPENAI_AVAILABLE:
|
| 219 |
+
use_oa_sent = use_oa_themes = use_oa_summary = False
|
| 220 |
|
| 221 |
# HF sentiment (optionnel)
|
| 222 |
HF_AVAILABLE=False
|