Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -13
src/streamlit_app.py
CHANGED
|
@@ -1,28 +1,33 @@
|
|
| 1 |
#streamlit_app.py
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 24 |
-
|
| 25 |
-
evaluate_model("drug_analysis_data_3months")
|
| 26 |
|
| 27 |
st.set_page_config(
|
| 28 |
page_title="Twitter Drug Crime Monitoring",
|
|
@@ -30,9 +35,6 @@ st.set_page_config(
|
|
| 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
|
|
|
|
| 1 |
#streamlit_app.py
|
| 2 |
+
# streamlit_app.py
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
import os
|
| 6 |
+
import json
|
| 7 |
+
import plotly.express as px
|
| 8 |
+
import plotly.graph_objects as go
|
| 9 |
+
from plotly.subplots import make_subplots
|
| 10 |
+
from datetime import datetime, timedelta
|
| 11 |
+
import numpy as np
|
| 12 |
+
import time
|
| 13 |
+
import re
|
| 14 |
+
import seaborn as sns
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
|
| 17 |
from alerts import compute_dynamic_risk, assign_dynamic_risk_level, trigger_alerts
|
| 18 |
|
| 19 |
+
# Detect if running in Hugging Face Space
|
| 20 |
IS_HF = os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID")
|
| 21 |
+
|
| 22 |
if IS_HF:
|
| 23 |
st.warning("🚨 Email alerts are simulated in this Hugging Face Space (no real emails sent).")
|
| 24 |
else:
|
| 25 |
st.info("📩 Real email alerts enabled (local environment).")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
from evaluation import evaluate_model
|
| 28 |
|
| 29 |
+
# Run evaluation on the scraped CSV folder (no logs shown)
|
| 30 |
+
evaluate_model("drug_analysis_data_3months")
|
|
|
|
| 31 |
|
| 32 |
st.set_page_config(
|
| 33 |
page_title="Twitter Drug Crime Monitoring",
|
|
|
|
| 35 |
initial_sidebar_state="expanded"
|
| 36 |
)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Import NLTK with error handling
|
| 40 |
import nltk
|