Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,7 @@ if 'hot_issues' not in st.session_state:
|
|
| 74 |
with st.spinner("Analyzing high-priority 12h feeds..."):
|
| 75 |
raw_news = fetch_extensive_news("breaking news crisis risk security", limit=35, period="12h")
|
| 76 |
news_context = "\n".join([f"Event: {n['title']}" for n in raw_news])
|
| 77 |
-
system_msg = """Identify TOP 5
|
| 78 |
try:
|
| 79 |
res = client.chat.completions.create(model=CURRENT_MODEL, messages=[{"role": "system", "content": system_msg}, {"role": "user", "content": news_context}], response_format={"type": "json_object"})
|
| 80 |
st.session_state.hot_issues = json.loads(res.choices[0].message.content).get('issues', [])[:5]
|
|
@@ -85,7 +85,6 @@ if st.session_state.hot_issues:
|
|
| 85 |
for i, issue in enumerate(st.session_state.hot_issues):
|
| 86 |
with cols[i]:
|
| 87 |
with st.container(border=True):
|
| 88 |
-
# FIXED: Added unique key for each chart to avoid DuplicateElementId
|
| 89 |
st.plotly_chart(render_gauge(issue.get('score', 50), "Severity Index"), use_container_width=True, key=f"war_room_gauge_{i}")
|
| 90 |
st.error(f"**{issue.get('title')}**")
|
| 91 |
for line in issue.get('summary', []): st.caption(f"β’ {line}")
|
|
@@ -99,22 +98,25 @@ tab1, tab2, tab3 = st.tabs(["π STRATEGIC GLOBAL SCAN", "π TACTICAL FORENSI
|
|
| 99 |
# --- [Tab 1: Strategic Global Scan] ---
|
| 100 |
with tab1:
|
| 101 |
st.header("Strategic Intelligence Briefing (SIB)")
|
| 102 |
-
keyword = st.text_input("Analysis Keyword
|
| 103 |
if st.button("πΊοΈ Generate Strategic Briefing", type="primary"):
|
| 104 |
-
with st.status("
|
| 105 |
all_news = []
|
| 106 |
for reg in REGION_MAP:
|
| 107 |
for geo in REGION_MAP[reg][:2]:
|
| 108 |
all_news.extend(fetch_extensive_news(keyword, geo=geo, limit=6, period="7d"))
|
| 109 |
-
status.write(f"β
Gathered {len(all_news)} articles. Synthesizing...")
|
| 110 |
|
| 111 |
-
news_summary = "\n".join([
|
|
|
|
| 112 |
global_prompt = f"""
|
| 113 |
-
Analyze '{keyword}' in English
|
| 114 |
-
IMPORTANT:
|
|
|
|
|
|
|
| 115 |
Return ONLY JSON:
|
| 116 |
{{
|
| 117 |
-
"executive_summary": "A
|
| 118 |
"risk_landscape": [
|
| 119 |
{{"Component": "Target Demographics", "Findings": "...", "Risk_Level": "High"}},
|
| 120 |
{{"Component": "Policy Violation", "Findings": "...", "Risk_Level": "Medium"}},
|
|
@@ -135,8 +137,7 @@ with tab1:
|
|
| 135 |
|
| 136 |
with st.container(border=True):
|
| 137 |
st.markdown("### π 1. Executive Summary")
|
| 138 |
-
|
| 139 |
-
st.markdown(summary_text)
|
| 140 |
|
| 141 |
st.markdown("### π 2. Strategic Risk Landscape Matrix")
|
| 142 |
st.dataframe(pd.DataFrame(g_data.get('risk_landscape')), hide_index=True, use_container_width=True)
|
|
@@ -151,19 +152,21 @@ with tab2:
|
|
| 151 |
st.header("National Tactical Forensic Deep-Dive")
|
| 152 |
target_geo = st.text_input("ISO Country Code", "US").upper()
|
| 153 |
if st.button("Generate National Forensic Report"):
|
| 154 |
-
with st.status(f"
|
| 155 |
news = fetch_extensive_news(f"{target_geo} social risk", geo=target_geo, limit=40, period="7d")
|
| 156 |
-
news_titles = "\n".join([
|
| 157 |
|
|
|
|
| 158 |
system_prompt = f"""
|
| 159 |
-
Identify Top 5 Risks for {target_geo} in English
|
| 160 |
-
|
|
|
|
| 161 |
Return ONLY JSON:
|
| 162 |
{{
|
| 163 |
"risks": [
|
| 164 |
{{
|
| 165 |
"rank": 1, "title": "..", "score": 90,
|
| 166 |
-
"summary": "
|
| 167 |
"forensic_grid": {{
|
| 168 |
"Policy_Violation": "..",
|
| 169 |
"Vulnerable_Groups": "..",
|
|
@@ -181,12 +184,10 @@ with tab2:
|
|
| 181 |
with st.expander(f"π© RISK {r.get('rank')}: {r.get('title')} (Severity: {r.get('score')})", expanded=True):
|
| 182 |
c1, c2 = st.columns([1, 4])
|
| 183 |
with c1:
|
| 184 |
-
# FIXED: Added unique key for forensics gauge
|
| 185 |
st.plotly_chart(render_gauge(r.get('score'), "Risk Index"), use_container_width=True, key=f"forensic_gauge_{i}")
|
| 186 |
with c2:
|
| 187 |
st.markdown("**Situational Analysis:**")
|
| 188 |
-
|
| 189 |
-
st.markdown(formatted_summary)
|
| 190 |
|
| 191 |
st.markdown("**π‘οΈ Forensics Intelligence Grid**")
|
| 192 |
grid_df = pd.DataFrame(r.get('forensic_grid', {}).items(), columns=["Analytical Component", "Intelligence Finding"])
|
|
|
|
| 74 |
with st.spinner("Analyzing high-priority 12h feeds..."):
|
| 75 |
raw_news = fetch_extensive_news("breaking news crisis risk security", limit=35, period="12h")
|
| 76 |
news_context = "\n".join([f"Event: {n['title']}" for n in raw_news])
|
| 77 |
+
system_msg = """Identify TOP 5 incidents. Return ONLY JSON: {"issues": [{"title": "..", "score": 85, "summary": ["..", "..", ".."], "link": ".."}]}"""
|
| 78 |
try:
|
| 79 |
res = client.chat.completions.create(model=CURRENT_MODEL, messages=[{"role": "system", "content": system_msg}, {"role": "user", "content": news_context}], response_format={"type": "json_object"})
|
| 80 |
st.session_state.hot_issues = json.loads(res.choices[0].message.content).get('issues', [])[:5]
|
|
|
|
| 85 |
for i, issue in enumerate(st.session_state.hot_issues):
|
| 86 |
with cols[i]:
|
| 87 |
with st.container(border=True):
|
|
|
|
| 88 |
st.plotly_chart(render_gauge(issue.get('score', 50), "Severity Index"), use_container_width=True, key=f"war_room_gauge_{i}")
|
| 89 |
st.error(f"**{issue.get('title')}**")
|
| 90 |
for line in issue.get('summary', []): st.caption(f"β’ {line}")
|
|
|
|
| 98 |
# --- [Tab 1: Strategic Global Scan] ---
|
| 99 |
with tab1:
|
| 100 |
st.header("Strategic Intelligence Briefing (SIB)")
|
| 101 |
+
keyword = st.text_input("Analysis Keyword", "Cyber Warfare")
|
| 102 |
if st.button("πΊοΈ Generate Strategic Briefing", type="primary"):
|
| 103 |
+
with st.status("Gathering Global Evidence...", expanded=True) as status:
|
| 104 |
all_news = []
|
| 105 |
for reg in REGION_MAP:
|
| 106 |
for geo in REGION_MAP[reg][:2]:
|
| 107 |
all_news.extend(fetch_extensive_news(keyword, geo=geo, limit=6, period="7d"))
|
| 108 |
+
status.write(f"β
Gathered {len(all_news)} articles. Synthesizing Narrative...")
|
| 109 |
|
| 110 |
+
news_summary = "\n".join([n['title'] for n in all_news[:45]])
|
| 111 |
+
# π‘οΈ UPDATED PROMPT: Narrative synthesis without clunky REF tags
|
| 112 |
global_prompt = f"""
|
| 113 |
+
Analyze '{keyword}' in English based on the provided news headlines.
|
| 114 |
+
IMPORTANT: The 'executive_summary' MUST be a clean, professional narrative summary of the actual events and risks.
|
| 115 |
+
DO NOT use clunky 'REF1', 'REF2' tags or list titles. Write it like a real intelligence report.
|
| 116 |
+
Use bullet points and clear paragraph breaks for readability.
|
| 117 |
Return ONLY JSON:
|
| 118 |
{{
|
| 119 |
+
"executive_summary": "A clean narrative summary (300+ words) of the situation and emerging trends.",
|
| 120 |
"risk_landscape": [
|
| 121 |
{{"Component": "Target Demographics", "Findings": "...", "Risk_Level": "High"}},
|
| 122 |
{{"Component": "Policy Violation", "Findings": "...", "Risk_Level": "Medium"}},
|
|
|
|
| 137 |
|
| 138 |
with st.container(border=True):
|
| 139 |
st.markdown("### π 1. Executive Summary")
|
| 140 |
+
st.markdown(g_data.get('executive_summary').replace(". ", ".\n\n"))
|
|
|
|
| 141 |
|
| 142 |
st.markdown("### π 2. Strategic Risk Landscape Matrix")
|
| 143 |
st.dataframe(pd.DataFrame(g_data.get('risk_landscape')), hide_index=True, use_container_width=True)
|
|
|
|
| 152 |
st.header("National Tactical Forensic Deep-Dive")
|
| 153 |
target_geo = st.text_input("ISO Country Code", "US").upper()
|
| 154 |
if st.button("Generate National Forensic Report"):
|
| 155 |
+
with st.status(f"Scanning Evidence for {target_geo}...", expanded=True):
|
| 156 |
news = fetch_extensive_news(f"{target_geo} social risk", geo=target_geo, limit=40, period="7d")
|
| 157 |
+
news_titles = "\n".join([n['title'] for n in news])
|
| 158 |
|
| 159 |
+
# π‘οΈ UPDATED PROMPT: Narrative synthesis without clunky REF tags
|
| 160 |
system_prompt = f"""
|
| 161 |
+
Identify Top 5 Risks for {target_geo} in English.
|
| 162 |
+
The 'summary' MUST be a clean, 300+ word narrative of the issue.
|
| 163 |
+
DO NOT use 'REF1', 'REF2' tags. Synthesize the information into a readable briefing.
|
| 164 |
Return ONLY JSON:
|
| 165 |
{{
|
| 166 |
"risks": [
|
| 167 |
{{
|
| 168 |
"rank": 1, "title": "..", "score": 90,
|
| 169 |
+
"summary": "Clean narrative analysis with bullet points and clear breaks.",
|
| 170 |
"forensic_grid": {{
|
| 171 |
"Policy_Violation": "..",
|
| 172 |
"Vulnerable_Groups": "..",
|
|
|
|
| 184 |
with st.expander(f"π© RISK {r.get('rank')}: {r.get('title')} (Severity: {r.get('score')})", expanded=True):
|
| 185 |
c1, c2 = st.columns([1, 4])
|
| 186 |
with c1:
|
|
|
|
| 187 |
st.plotly_chart(render_gauge(r.get('score'), "Risk Index"), use_container_width=True, key=f"forensic_gauge_{i}")
|
| 188 |
with c2:
|
| 189 |
st.markdown("**Situational Analysis:**")
|
| 190 |
+
st.markdown(r.get('summary').replace(". ", ".\n\n"))
|
|
|
|
| 191 |
|
| 192 |
st.markdown("**π‘οΈ Forensics Intelligence Grid**")
|
| 193 |
grid_df = pd.DataFrame(r.get('forensic_grid', {}).items(), columns=["Analytical Component", "Intelligence Finding"])
|