Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,9 +64,6 @@ def create_download_link(data, filename="Intel_Report.txt"):
|
|
| 64 |
st.title("π¨ OMNI-WATCH: GLOBAL WAR ROOM")
|
| 65 |
st.markdown(f"**Live Intelligence Analysis (UTC):** `{datetime.now().strftime('%H:%M:%S')}`")
|
| 66 |
|
| 67 |
-
st.subheader("π₯ Global Breaking Incidents (Last 12 Hours)")
|
| 68 |
-
st.caption("AI-monitored live feeds with 3-line strategic summaries.")
|
| 69 |
-
|
| 70 |
if st.button("π Refresh Dashboard"):
|
| 71 |
if 'hot_issues' in st.session_state: del st.session_state.hot_issues
|
| 72 |
|
|
@@ -90,7 +87,6 @@ for i, issue in enumerate(st.session_state.hot_issues):
|
|
| 90 |
with cols[i % 3]:
|
| 91 |
with st.container(border=True):
|
| 92 |
st.error(f"**{issue.get('event_title')}**")
|
| 93 |
-
st.markdown(f"**Threat Level:** `{issue.get('severity')}`")
|
| 94 |
summary_html = "".join([f"<li>{line}</li>" for line in issue.get('three_line_summary', [])])
|
| 95 |
st.markdown(f"<ul style='font-size: 0.85rem; padding-left: 15px;'>{summary_html}</ul>", unsafe_allow_html=True)
|
| 96 |
st.markdown(f"[π View Source]({issue.get('source_link')})")
|
|
@@ -98,14 +94,14 @@ for i, issue in enumerate(st.session_state.hot_issues):
|
|
| 98 |
st.markdown("---")
|
| 99 |
|
| 100 |
# --- 6. Strategic Tabs (7d Filter for Search) ---
|
| 101 |
-
tab1, tab2, tab3 = st.tabs(["π GLOBAL TRACKING & MARKET", "π NATIONAL
|
| 102 |
|
| 103 |
-
# --- [Tab 1: Global & Market] ---
|
| 104 |
with tab1:
|
| 105 |
-
st.subheader("Global Risk Propagation & Market Insight (7 Days)")
|
| 106 |
col_k1, col_k2 = st.columns([3, 1])
|
| 107 |
with col_k1:
|
| 108 |
-
keyword = st.text_input("Enter Issue Keyword (7d Scan)", "
|
| 109 |
selected_regions = st.multiselect("Select Regions", list(REGION_MAP.keys()), default=list(REGION_MAP.keys()))
|
| 110 |
with col_k2:
|
| 111 |
st.write("")
|
|
@@ -115,77 +111,80 @@ with tab1:
|
|
| 115 |
target_countries = []
|
| 116 |
for reg in selected_regions: target_countries.extend(REGION_MAP[reg])
|
| 117 |
results = []
|
|
|
|
| 118 |
progress = st.progress(0)
|
| 119 |
for i, geo in enumerate(target_countries):
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
progress.progress((i + 1) / len(target_countries))
|
| 123 |
|
| 124 |
st.plotly_chart(px.bar(pd.DataFrame(results), x="Country", y="Risk", color="Risk", color_continuous_scale="Reds"))
|
| 125 |
|
| 126 |
-
with st.spinner("
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
with tab2:
|
| 138 |
-
st.subheader("National Tactical Intelligence (Evidence
|
| 139 |
c1, c2 = st.columns([1, 4])
|
| 140 |
with c1:
|
| 141 |
-
target_geo = st.text_input("ISO Country Code", "
|
| 142 |
-
btn_deep = st.button("Generate
|
| 143 |
|
| 144 |
if btn_deep:
|
| 145 |
with st.status(f"Generating forensics for {target_geo} (7d data)...", expanded=True):
|
| 146 |
news = fetch_google_news(f"{target_geo} social controversy risk", geo=target_geo, limit=35, period="7d")
|
| 147 |
news_context = "\n".join([f"REF [{i+1}]: {n['title']} (Source: {n['source']})" for i, n in enumerate(news)])
|
| 148 |
|
| 149 |
-
#
|
| 150 |
system_prompt = f"""
|
| 151 |
Identify Top 5 Risks for {target_geo} based ONLY on the provided references.
|
| 152 |
-
For each risk, write a MINIMUM of 300 words summary citing
|
| 153 |
-
Return ONLY JSON
|
| 154 |
{{
|
| 155 |
"risks": [
|
| 156 |
{{
|
| 157 |
-
"rank": 1,
|
| 158 |
-
"title": "..",
|
| 159 |
-
"score": 90,
|
| 160 |
-
"summary": "..",
|
| 161 |
-
"violation": "..",
|
| 162 |
-
"demographics": "..",
|
| 163 |
-
"tactical_action": ".."
|
| 164 |
}}
|
| 165 |
]
|
| 166 |
}}
|
| 167 |
"""
|
| 168 |
try:
|
| 169 |
-
res = client.chat.completions.create(
|
| 170 |
-
model=CURRENT_MODEL,
|
| 171 |
-
messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": f"EVIDENCE FEED:\n{news_context}"}],
|
| 172 |
-
response_format={"type": "json_object"}
|
| 173 |
-
)
|
| 174 |
report_data = json.loads(res.choices[0].message.content).get('risks', [])
|
| 175 |
-
except
|
| 176 |
-
st.error(f"Analysis Error: {e}")
|
| 177 |
-
report_data = []
|
| 178 |
|
| 179 |
if report_data:
|
| 180 |
st.markdown(create_download_link(report_data, f"{target_geo}_Verified_Intel.txt"), unsafe_allow_html=True)
|
| 181 |
for r in report_data:
|
| 182 |
with st.expander(f"π© RANK {r.get('rank')}: {r.get('title')} (Verified)"):
|
| 183 |
-
st.markdown("### π Detailed Strategic Analysis")
|
| 184 |
st.write(r.get('summary'))
|
| 185 |
-
st.table(pd.DataFrame({
|
| 186 |
-
"Category": ["Policy Breach", "Vulnerability", "Action"],
|
| 187 |
-
"Insight": [r.get('violation'), r.get('demographics'), r.get('tactical_action')]
|
| 188 |
-
}))
|
| 189 |
|
| 190 |
st.divider()
|
| 191 |
st.subheader("π° Underlying Evidence Feed")
|
|
@@ -196,7 +195,7 @@ with tab2:
|
|
| 196 |
# --- [Tab 3: Trend Analysis] ---
|
| 197 |
with tab3:
|
| 198 |
st.subheader("π Risk Velocity Trend (Last 7 Days)")
|
| 199 |
-
trend_key = st.text_input("Trend Keyword", "AI
|
| 200 |
if st.button("Analyze Velocity"):
|
| 201 |
dates = [(datetime.now() - timedelta(days=i)).strftime("%m-%d") for i in range(6, -1, -1)]
|
| 202 |
scores = [15, 25, 45, 75, 85, 95, 92]
|
|
|
|
| 64 |
st.title("π¨ OMNI-WATCH: GLOBAL WAR ROOM")
|
| 65 |
st.markdown(f"**Live Intelligence Analysis (UTC):** `{datetime.now().strftime('%H:%M:%S')}`")
|
| 66 |
|
|
|
|
|
|
|
|
|
|
| 67 |
if st.button("π Refresh Dashboard"):
|
| 68 |
if 'hot_issues' in st.session_state: del st.session_state.hot_issues
|
| 69 |
|
|
|
|
| 87 |
with cols[i % 3]:
|
| 88 |
with st.container(border=True):
|
| 89 |
st.error(f"**{issue.get('event_title')}**")
|
|
|
|
| 90 |
summary_html = "".join([f"<li>{line}</li>" for line in issue.get('three_line_summary', [])])
|
| 91 |
st.markdown(f"<ul style='font-size: 0.85rem; padding-left: 15px;'>{summary_html}</ul>", unsafe_allow_html=True)
|
| 92 |
st.markdown(f"[π View Source]({issue.get('source_link')})")
|
|
|
|
| 94 |
st.markdown("---")
|
| 95 |
|
| 96 |
# --- 6. Strategic Tabs (7d Filter for Search) ---
|
| 97 |
+
tab1, tab2, tab3 = st.tabs(["π GLOBAL TRACKING & MARKET", "π NATIONAL TOP 5 FORENSICS", "π RISK VELOCITY TREND"])
|
| 98 |
|
| 99 |
+
# --- [Tab 1: Global & Market Insights] ---
|
| 100 |
with tab1:
|
| 101 |
+
st.subheader("Global Risk Propagation & Strategic Market Insight (7 Days)")
|
| 102 |
col_k1, col_k2 = st.columns([3, 1])
|
| 103 |
with col_k1:
|
| 104 |
+
keyword = st.text_input("Enter Issue Keyword (7d Deep Scan)", "Deepfake Propaganda")
|
| 105 |
selected_regions = st.multiselect("Select Regions", list(REGION_MAP.keys()), default=list(REGION_MAP.keys()))
|
| 106 |
with col_k2:
|
| 107 |
st.write("")
|
|
|
|
| 111 |
target_countries = []
|
| 112 |
for reg in selected_regions: target_countries.extend(REGION_MAP[reg])
|
| 113 |
results = []
|
| 114 |
+
all_news_for_tab1 = []
|
| 115 |
progress = st.progress(0)
|
| 116 |
for i, geo in enumerate(target_countries):
|
| 117 |
+
n_list = fetch_google_news(keyword, geo=geo, limit=5, period="7d")
|
| 118 |
+
all_news_for_tab1.extend(n_list)
|
| 119 |
+
results.append({"Country": geo, "Risk": min(len(n_list) * 20, 100)})
|
| 120 |
progress.progress((i + 1) / len(target_countries))
|
| 121 |
|
| 122 |
st.plotly_chart(px.bar(pd.DataFrame(results), x="Country", y="Risk", color="Risk", color_continuous_scale="Reds"))
|
| 123 |
|
| 124 |
+
with st.spinner("Synthesizing Strategic Narrative (No Fake Stats)..."):
|
| 125 |
+
news_summary = "\n".join([f"[{n['source']}] {n['title']}" for n in all_news_for_tab1[:25]])
|
| 126 |
+
# π‘οΈ FIXED: Double curly braces for JSON structure
|
| 127 |
+
global_prompt = f"""
|
| 128 |
+
You are a Senior Policy Director. Analyze the news provided.
|
| 129 |
+
DO NOT provide fake numerical statistics (like total views or engagement rates).
|
| 130 |
+
Provide a professional narrative analysis.
|
| 131 |
+
Return ONLY JSON:
|
| 132 |
+
{{
|
| 133 |
+
"global_summary": "Detailed narrative (300+ words) on propagation trends.",
|
| 134 |
+
"market_insights": {{
|
| 135 |
+
"TikTok": "Qualitative analysis of risks on this platform.",
|
| 136 |
+
"YouTube": "Qualitative analysis of risks on this platform.",
|
| 137 |
+
"Meta": "Qualitative analysis of risks on this platform.",
|
| 138 |
+
"X": "Qualitative analysis of risks on this platform."
|
| 139 |
+
}}
|
| 140 |
+
}}
|
| 141 |
+
"""
|
| 142 |
+
try:
|
| 143 |
+
res = client.chat.completions.create(model=CURRENT_MODEL, messages=[{"role": "system", "content": global_prompt}, {"role": "user", "content": f"NEWS DATA:\n{news_summary}"}], response_format={"type": "json_object"})
|
| 144 |
+
g_data = json.loads(res.choices[0].message.content)
|
| 145 |
+
st.info(g_data.get('global_summary'))
|
| 146 |
+
st.markdown("### π± Platform-Specific Intelligence")
|
| 147 |
+
st.table(pd.DataFrame(g_data.get('market_insights', {}).items(), columns=["Platform", "Strategic Insight"]))
|
| 148 |
+
except Exception as e:
|
| 149 |
+
st.error(f"Synthesis error: {e}")
|
| 150 |
+
|
| 151 |
+
# --- [Tab 2: National Forensics (Evidence-Grounded)] ---
|
| 152 |
with tab2:
|
| 153 |
+
st.subheader("National Tactical Intelligence (Verified Evidence)")
|
| 154 |
c1, c2 = st.columns([1, 4])
|
| 155 |
with c1:
|
| 156 |
+
target_geo = st.text_input("ISO Country Code", "US").upper()
|
| 157 |
+
btn_deep = st.button("Generate Evidence-Based Report", type="primary")
|
| 158 |
|
| 159 |
if btn_deep:
|
| 160 |
with st.status(f"Generating forensics for {target_geo} (7d data)...", expanded=True):
|
| 161 |
news = fetch_google_news(f"{target_geo} social controversy risk", geo=target_geo, limit=35, period="7d")
|
| 162 |
news_context = "\n".join([f"REF [{i+1}]: {n['title']} (Source: {n['source']})" for i, n in enumerate(news)])
|
| 163 |
|
| 164 |
+
# π‘οΈ FIXED: Double curly braces
|
| 165 |
system_prompt = f"""
|
| 166 |
Identify Top 5 Risks for {target_geo} based ONLY on the provided references.
|
| 167 |
+
For each risk, write a MINIMUM of 300 words summary citing REF IDs.
|
| 168 |
+
Return ONLY JSON:
|
| 169 |
{{
|
| 170 |
"risks": [
|
| 171 |
{{
|
| 172 |
+
"rank": 1, "title": "..", "score": 90, "summary": "..", "violation": "..", "demographics": "..", "tactical_action": ".."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}}
|
| 174 |
]
|
| 175 |
}}
|
| 176 |
"""
|
| 177 |
try:
|
| 178 |
+
res = client.chat.completions.create(model=CURRENT_MODEL, messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": f"EVIDENCE FEED:\n{news_context}"}], response_format={"type": "json_object"})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
report_data = json.loads(res.choices[0].message.content).get('risks', [])
|
| 180 |
+
except: report_data = []
|
|
|
|
|
|
|
| 181 |
|
| 182 |
if report_data:
|
| 183 |
st.markdown(create_download_link(report_data, f"{target_geo}_Verified_Intel.txt"), unsafe_allow_html=True)
|
| 184 |
for r in report_data:
|
| 185 |
with st.expander(f"π© RANK {r.get('rank')}: {r.get('title')} (Verified)"):
|
|
|
|
| 186 |
st.write(r.get('summary'))
|
| 187 |
+
st.table(pd.DataFrame({"Category": ["Policy", "Vulnerability", "Action"], "Insight": [r.get('violation'), r.get('demographics'), r.get('tactical_action')]}))
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
st.divider()
|
| 190 |
st.subheader("π° Underlying Evidence Feed")
|
|
|
|
| 195 |
# --- [Tab 3: Trend Analysis] ---
|
| 196 |
with tab3:
|
| 197 |
st.subheader("π Risk Velocity Trend (Last 7 Days)")
|
| 198 |
+
trend_key = st.text_input("Trend Keyword", "AI Fraud")
|
| 199 |
if st.button("Analyze Velocity"):
|
| 200 |
dates = [(datetime.now() - timedelta(days=i)).strftime("%m-%d") for i in range(6, -1, -1)]
|
| 201 |
scores = [15, 25, 45, 75, 85, 95, 92]
|