Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -18
src/streamlit_app.py
CHANGED
|
@@ -2,37 +2,38 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
from
|
| 10 |
-
import numpy as np
|
| 11 |
-
import time
|
| 12 |
-
import re
|
| 13 |
-
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 |
-
# Detect if running in Hugging Face Space
|
| 18 |
-
IS_HF = os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID")
|
| 19 |
|
| 20 |
-
|
| 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 |
-
#
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
st.set_page_config(
|
| 32 |
page_title="Twitter Drug Crime Monitoring",
|
| 33 |
layout="wide",
|
| 34 |
initial_sidebar_state="expanded"
|
| 35 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Import NLTK with error handling
|
| 37 |
import nltk
|
| 38 |
from nltk.corpus import stopwords
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
+
import io
|
| 6 |
+
import logging
|
| 7 |
+
from contextlib import redirect_stdout
|
| 8 |
+
|
| 9 |
+
from alerts import compute_dynamic_risk, assign_dynamic_risk_level, trigger_alerts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
IS_HF = os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID")
|
| 12 |
if IS_HF:
|
| 13 |
st.warning("🚨 Email alerts are simulated in this Hugging Face Space (no real emails sent).")
|
| 14 |
else:
|
| 15 |
st.info("📩 Real email alerts enabled (local environment).")
|
| 16 |
+
|
| 17 |
+
# Capture stdout and logs
|
| 18 |
+
log_stream = io.StringIO()
|
| 19 |
+
logging.basicConfig(stream=log_stream, level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 20 |
+
|
| 21 |
from evaluation import evaluate_model
|
| 22 |
|
| 23 |
+
# Redirect print statements to log_stream
|
| 24 |
+
with redirect_stdout(log_stream):
|
| 25 |
+
evaluate_model("drug_analysis_data_3months")
|
| 26 |
|
| 27 |
st.set_page_config(
|
| 28 |
page_title="Twitter Drug Crime Monitoring",
|
| 29 |
layout="wide",
|
| 30 |
initial_sidebar_state="expanded"
|
| 31 |
)
|
| 32 |
+
|
| 33 |
+
st.subheader("📊 Scraper Evaluation Logs")
|
| 34 |
+
st.text(log_stream.getvalue())
|
| 35 |
+
|
| 36 |
+
|
| 37 |
# Import NLTK with error handling
|
| 38 |
import nltk
|
| 39 |
from nltk.corpus import stopwords
|