Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -3
src/streamlit_app.py
CHANGED
|
@@ -14,6 +14,15 @@ import seaborn as sns
|
|
| 14 |
import matplotlib.pyplot as plt
|
| 15 |
|
| 16 |
from alerts import compute_dynamic_risk,assign_dynamic_risk_level,trigger_alerts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
from evaluation import evaluate_model
|
| 18 |
|
| 19 |
# Run evaluation on the scraped CSV folder
|
|
@@ -502,6 +511,8 @@ st.sidebar.info(f"Showing {len(df)} tweets")
|
|
| 502 |
|
| 503 |
# ---------------- EMAIL ALERTS SECTION ---------------
|
| 504 |
|
|
|
|
|
|
|
| 505 |
st.sidebar.header("π© Email Alerts")
|
| 506 |
num_tweets = st.sidebar.number_input(
|
| 507 |
"Number of high-risk tweets to send",
|
|
@@ -513,9 +524,12 @@ num_tweets = st.sidebar.number_input(
|
|
| 513 |
send_button = st.sidebar.button("Send Alerts")
|
| 514 |
|
| 515 |
if send_button:
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
|
|
|
|
|
|
|
|
|
| 519 |
|
| 520 |
# ------------------------
|
| 521 |
# EXECUTIVE SUMMARY
|
|
|
|
| 14 |
import matplotlib.pyplot as plt
|
| 15 |
|
| 16 |
from alerts import compute_dynamic_risk,assign_dynamic_risk_level,trigger_alerts
|
| 17 |
+
# Detect if running in Hugging Face Space
|
| 18 |
+
IS_HF = os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID")
|
| 19 |
+
|
| 20 |
+
# Optional: you can also check simulation flag if you imported from alerts.py
|
| 21 |
+
if IS_HF:
|
| 22 |
+
st.warning("π¨ Email alerts are simulated in this Hugging Face Space (no real emails sent).")
|
| 23 |
+
else:
|
| 24 |
+
st.info("π© Real email alerts enabled (local environment).")
|
| 25 |
+
|
| 26 |
from evaluation import evaluate_model
|
| 27 |
|
| 28 |
# Run evaluation on the scraped CSV folder
|
|
|
|
| 511 |
|
| 512 |
# ---------------- EMAIL ALERTS SECTION ---------------
|
| 513 |
|
| 514 |
+
from alerts import IS_HF # import the HF detection flag
|
| 515 |
+
|
| 516 |
st.sidebar.header("π© Email Alerts")
|
| 517 |
num_tweets = st.sidebar.number_input(
|
| 518 |
"Number of high-risk tweets to send",
|
|
|
|
| 524 |
send_button = st.sidebar.button("Send Alerts")
|
| 525 |
|
| 526 |
if send_button:
|
| 527 |
+
if IS_HF:
|
| 528 |
+
st.warning(f"π¨ HF Space detected: Alerts are simulated. Would send top {num_tweets} tweets.")
|
| 529 |
+
else:
|
| 530 |
+
st.info(f"Sending top {num_tweets} high-risk tweets via email...")
|
| 531 |
+
trigger_alerts(max_tweets=num_tweets)
|
| 532 |
+
st.success(f"β
Alerts sent for top {num_tweets} tweets!")
|
| 533 |
|
| 534 |
# ------------------------
|
| 535 |
# EXECUTIVE SUMMARY
|