Spaces:
Running
Running
Update streamlit_app.py
Browse files- streamlit_app.py +14 -7
streamlit_app.py
CHANGED
|
@@ -6,6 +6,7 @@ from datetime import datetime
|
|
| 6 |
import threading
|
| 7 |
import time
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
# Create a global lock for file operations
|
| 11 |
data_lock = threading.Lock()
|
|
@@ -193,9 +194,9 @@ if active_df is not None and not active_df.empty:
|
|
| 193 |
st.session_state.exec_briefing = "Click the button below to generate a high-level briefing."
|
| 194 |
st.info(st.session_state.exec_briefing)
|
| 195 |
|
| 196 |
-
if
|
| 197 |
if st.button("Generate Briefing"):
|
| 198 |
-
with st.spinner("
|
| 199 |
|
| 200 |
# Filter down to the Radar logic
|
| 201 |
temp_df = active_df[active_df['type'].isin(selected_types)] if selected_types else active_df
|
|
@@ -207,15 +208,15 @@ if active_df is not None and not active_df.empty:
|
|
| 207 |
|
| 208 |
# Safe fallback in case the Radar is completely empty today
|
| 209 |
if briefing_items.empty:
|
| 210 |
-
briefing_items = temp_df.head(
|
| 211 |
|
| 212 |
context = "\n".join([f"• SOURCE: {row['source']} | TITLE: {row['title']} | SUMMARY: {row.get('analysis', 'N/A')}" for _, row in briefing_items.iterrows()])
|
| 213 |
|
| 214 |
# NEW: Strict context prompt
|
| 215 |
prompt = f"""
|
| 216 |
-
Provide a highly concise, 3-5 paragraph
|
| 217 |
|
| 218 |
-
Do not include outside information.
|
| 219 |
|
| 220 |
Ensure you are synthesizing and summarizing information from across the Radar tracking system, not just the first 1 or 2 entries. This is a CRITICAL function for effective application funtionality.
|
| 221 |
All summaries should be in an understated tone. Do not infer implications or make recommendations. Simply summarize the most key information for the user.
|
|
@@ -227,11 +228,17 @@ if active_df is not None and not active_df.empty:
|
|
| 227 |
|
| 228 |
messages = [{"role": "user", "content": prompt}]
|
| 229 |
try:
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
st.session_state.exec_briefing = response.choices[0].message.content
|
| 232 |
st.rerun()
|
| 233 |
except Exception as e:
|
| 234 |
-
st.error(f"Briefing failed: {e}")
|
| 235 |
|
| 236 |
st.divider()
|
| 237 |
|
|
|
|
| 6 |
import threading
|
| 7 |
import time
|
| 8 |
import os
|
| 9 |
+
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
# Create a global lock for file operations
|
| 12 |
data_lock = threading.Lock()
|
|
|
|
| 194 |
st.session_state.exec_briefing = "Click the button below to generate a high-level briefing."
|
| 195 |
st.info(st.session_state.exec_briefing)
|
| 196 |
|
| 197 |
+
if os.getenv("HF_TOKEN"):
|
| 198 |
if st.button("Generate Briefing"):
|
| 199 |
+
with st.spinner("Gemma 31B is synthesizing your Radar intelligence..."):
|
| 200 |
|
| 201 |
# Filter down to the Radar logic
|
| 202 |
temp_df = active_df[active_df['type'].isin(selected_types)] if selected_types else active_df
|
|
|
|
| 208 |
|
| 209 |
# Safe fallback in case the Radar is completely empty today
|
| 210 |
if briefing_items.empty:
|
| 211 |
+
briefing_items = temp_df.head(20)
|
| 212 |
|
| 213 |
context = "\n".join([f"• SOURCE: {row['source']} | TITLE: {row['title']} | SUMMARY: {row.get('analysis', 'N/A')}" for _, row in briefing_items.iterrows()])
|
| 214 |
|
| 215 |
# NEW: Strict context prompt
|
| 216 |
prompt = f"""
|
| 217 |
+
Provide a highly concise, 3-5 paragraph briefing based only on the recent intelligence gathered from the user's Radar tracking system.
|
| 218 |
|
| 219 |
+
Do not include outside information. Cite all sources used in the summary using in-line citations for easy user verification.
|
| 220 |
|
| 221 |
Ensure you are synthesizing and summarizing information from across the Radar tracking system, not just the first 1 or 2 entries. This is a CRITICAL function for effective application funtionality.
|
| 222 |
All summaries should be in an understated tone. Do not infer implications or make recommendations. Simply summarize the most key information for the user.
|
|
|
|
| 228 |
|
| 229 |
messages = [{"role": "user", "content": prompt}]
|
| 230 |
try:
|
| 231 |
+
# ---------------------------------------------------------
|
| 232 |
+
# THE TWO-TIER ARCHITECTURE: Dedicated Gemma Client
|
| 233 |
+
# ---------------------------------------------------------
|
| 234 |
+
gemma_client = InferenceClient("google/gemma-4-31b-it", token=os.getenv("HF_TOKEN"))
|
| 235 |
+
|
| 236 |
+
# Max tokens bumped slightly to accommodate the 3-5 paragraphs requested
|
| 237 |
+
response = gemma_client.chat_completion(messages, max_tokens=700, temperature=0.1)
|
| 238 |
st.session_state.exec_briefing = response.choices[0].message.content
|
| 239 |
st.rerun()
|
| 240 |
except Exception as e:
|
| 241 |
+
st.error(f"Briefing failed. (model may be loading or hitting tier limits): {e}")
|
| 242 |
|
| 243 |
st.divider()
|
| 244 |
|