Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
# import os
|
| 4 |
# import re
|
|
@@ -13,7 +13,7 @@
|
|
| 13 |
|
| 14 |
# # β
Hugging Face and GROQ secrets loaded via Hugging Face Spaces Secrets interface
|
| 15 |
|
| 16 |
-
# #
|
| 17 |
# GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 18 |
# HF_TOKEN = os.getenv("HF_TOKEN")
|
| 19 |
# KAGGLE_USERNAME = os.getenv("KAGGLE_USERNAME")
|
|
@@ -59,6 +59,8 @@
|
|
| 59 |
# st.session_state.history = []
|
| 60 |
# if "audio_summary" not in st.session_state:
|
| 61 |
# st.session_state.audio_summary = ""
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# # =======================
|
| 64 |
# # Streamlit UI
|
|
@@ -173,9 +175,11 @@
|
|
| 173 |
# if clear_btn:
|
| 174 |
# st.session_state.history.clear()
|
| 175 |
# st.session_state.audio_summary = ""
|
|
|
|
| 176 |
# st.success("β
History cleared!")
|
| 177 |
|
| 178 |
# if analyze_btn:
|
|
|
|
| 179 |
# combined_text = text_input
|
| 180 |
# if uploaded_file:
|
| 181 |
# extracted = extract_text_from_file(uploaded_file)
|
|
@@ -207,9 +211,6 @@
|
|
| 207 |
# st.audio(f.read(), format="audio/mp3")
|
| 208 |
# os.remove(audio_path)
|
| 209 |
|
| 210 |
-
# if st.button("π€ Send Report to IT"):
|
| 211 |
-
# st.success("π¨ Report sent to IT successfully.")
|
| 212 |
-
|
| 213 |
# # Save history
|
| 214 |
# st.session_state.history.append({
|
| 215 |
# "input": combined_text,
|
|
@@ -230,10 +231,19 @@
|
|
| 230 |
# for term, definition in GLOSSARY.items():
|
| 231 |
# st.markdown(f"**{term.capitalize()}**: {definition}")
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
# render_history()
|
| 234 |
|
| 235 |
|
| 236 |
-
|
| 237 |
# app.py
|
| 238 |
|
| 239 |
import os
|
|
@@ -297,6 +307,12 @@ if "audio_summary" not in st.session_state:
|
|
| 297 |
st.session_state.audio_summary = ""
|
| 298 |
if "report_sent" not in st.session_state:
|
| 299 |
st.session_state.report_sent = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
# =======================
|
| 302 |
# Streamlit UI
|
|
@@ -306,11 +322,20 @@ st.set_page_config(page_title="ZeroPhish Gate", layout="wide")
|
|
| 306 |
st.title("π‘οΈ ZeroPhish Gate")
|
| 307 |
st.markdown("AI-powered phishing message detection and explanation.")
|
| 308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
# Input fields
|
| 310 |
col1, col2 = st.columns([3, 1])
|
| 311 |
with col1:
|
| 312 |
-
text_input = st.text_area("βοΈ Paste Suspicious Message", height=200)
|
| 313 |
-
uploaded_file = st.file_uploader("π Upload PDF/TXT (optional)", type=["pdf", "txt"])
|
| 314 |
|
| 315 |
with col2:
|
| 316 |
language = st.selectbox("π Preferred Language", language_choices)
|
|
@@ -416,9 +441,10 @@ if clear_btn:
|
|
| 416 |
|
| 417 |
if analyze_btn:
|
| 418 |
st.session_state.report_sent = False
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
|
|
|
| 422 |
combined_text += "\n" + extracted
|
| 423 |
|
| 424 |
if not combined_text.strip():
|
|
@@ -467,14 +493,15 @@ if analyze_btn:
|
|
| 467 |
for term, definition in GLOSSARY.items():
|
| 468 |
st.markdown(f"**{term.capitalize()}**: {definition}")
|
| 469 |
|
| 470 |
-
# β
Report to IT section -
|
| 471 |
-
st.
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
|
|
|
| 475 |
|
| 476 |
-
if st.session_state.report_sent:
|
| 477 |
-
|
| 478 |
|
| 479 |
render_history()
|
| 480 |
|
|
|
|
| 1 |
+
|
| 2 |
|
| 3 |
# import os
|
| 4 |
# import re
|
|
|
|
| 13 |
|
| 14 |
# # β
Hugging Face and GROQ secrets loaded via Hugging Face Spaces Secrets interface
|
| 15 |
|
| 16 |
+
# # βͺ Access secrets securely from environment variables
|
| 17 |
# GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 18 |
# HF_TOKEN = os.getenv("HF_TOKEN")
|
| 19 |
# KAGGLE_USERNAME = os.getenv("KAGGLE_USERNAME")
|
|
|
|
| 59 |
# st.session_state.history = []
|
| 60 |
# if "audio_summary" not in st.session_state:
|
| 61 |
# st.session_state.audio_summary = ""
|
| 62 |
+
# if "report_sent" not in st.session_state:
|
| 63 |
+
# st.session_state.report_sent = False
|
| 64 |
|
| 65 |
# # =======================
|
| 66 |
# # Streamlit UI
|
|
|
|
| 175 |
# if clear_btn:
|
| 176 |
# st.session_state.history.clear()
|
| 177 |
# st.session_state.audio_summary = ""
|
| 178 |
+
# st.session_state.report_sent = False
|
| 179 |
# st.success("β
History cleared!")
|
| 180 |
|
| 181 |
# if analyze_btn:
|
| 182 |
+
# st.session_state.report_sent = False
|
| 183 |
# combined_text = text_input
|
| 184 |
# if uploaded_file:
|
| 185 |
# extracted = extract_text_from_file(uploaded_file)
|
|
|
|
| 211 |
# st.audio(f.read(), format="audio/mp3")
|
| 212 |
# os.remove(audio_path)
|
| 213 |
|
|
|
|
|
|
|
|
|
|
| 214 |
# # Save history
|
| 215 |
# st.session_state.history.append({
|
| 216 |
# "input": combined_text,
|
|
|
|
| 231 |
# for term, definition in GLOSSARY.items():
|
| 232 |
# st.markdown(f"**{term.capitalize()}**: {definition}")
|
| 233 |
|
| 234 |
+
# # β
Report to IT section - outside the expander and stable
|
| 235 |
+
# st.markdown("---")
|
| 236 |
+
# report_it = st.button("π€ Report to IT", key="report_it_btn")
|
| 237 |
+
# if report_it:
|
| 238 |
+
# st.session_state.report_sent = True
|
| 239 |
+
|
| 240 |
+
# if st.session_state.report_sent:
|
| 241 |
+
# st.success("π¨ Report sent to IT successfully.")
|
| 242 |
+
|
| 243 |
# render_history()
|
| 244 |
|
| 245 |
|
| 246 |
+
|
| 247 |
# app.py
|
| 248 |
|
| 249 |
import os
|
|
|
|
| 307 |
st.session_state.audio_summary = ""
|
| 308 |
if "report_sent" not in st.session_state:
|
| 309 |
st.session_state.report_sent = False
|
| 310 |
+
if "chat_active" not in st.session_state:
|
| 311 |
+
st.session_state.chat_active = False
|
| 312 |
+
if "text_input" not in st.session_state:
|
| 313 |
+
st.session_state.text_input = ""
|
| 314 |
+
if "uploaded_file" not in st.session_state:
|
| 315 |
+
st.session_state.uploaded_file = None
|
| 316 |
|
| 317 |
# =======================
|
| 318 |
# Streamlit UI
|
|
|
|
| 322 |
st.title("π‘οΈ ZeroPhish Gate")
|
| 323 |
st.markdown("AI-powered phishing message detection and explanation.")
|
| 324 |
|
| 325 |
+
# β
New Chat button
|
| 326 |
+
if st.button("π New Chat"):
|
| 327 |
+
st.session_state.chat_active = False
|
| 328 |
+
st.session_state.audio_summary = ""
|
| 329 |
+
st.session_state.report_sent = False
|
| 330 |
+
st.session_state.text_input = ""
|
| 331 |
+
st.session_state.uploaded_file = None
|
| 332 |
+
st.experimental_rerun()
|
| 333 |
+
|
| 334 |
# Input fields
|
| 335 |
col1, col2 = st.columns([3, 1])
|
| 336 |
with col1:
|
| 337 |
+
st.session_state.text_input = st.text_area("βοΈ Paste Suspicious Message", value=st.session_state.text_input, height=200)
|
| 338 |
+
st.session_state.uploaded_file = st.file_uploader("π Upload PDF/TXT (optional)", type=["pdf", "txt"])
|
| 339 |
|
| 340 |
with col2:
|
| 341 |
language = st.selectbox("π Preferred Language", language_choices)
|
|
|
|
| 441 |
|
| 442 |
if analyze_btn:
|
| 443 |
st.session_state.report_sent = False
|
| 444 |
+
st.session_state.chat_active = True
|
| 445 |
+
combined_text = st.session_state.text_input
|
| 446 |
+
if st.session_state.uploaded_file:
|
| 447 |
+
extracted = extract_text_from_file(st.session_state.uploaded_file)
|
| 448 |
combined_text += "\n" + extracted
|
| 449 |
|
| 450 |
if not combined_text.strip():
|
|
|
|
| 493 |
for term, definition in GLOSSARY.items():
|
| 494 |
st.markdown(f"**{term.capitalize()}**: {definition}")
|
| 495 |
|
| 496 |
+
# β
Report to IT section - only visible after analysis
|
| 497 |
+
if st.session_state.chat_active:
|
| 498 |
+
st.markdown("---")
|
| 499 |
+
report_it = st.button("π€ Report to IT", key="report_it_btn")
|
| 500 |
+
if report_it:
|
| 501 |
+
st.session_state.report_sent = True
|
| 502 |
|
| 503 |
+
if st.session_state.report_sent:
|
| 504 |
+
st.success("π¨ Report sent to IT successfully.")
|
| 505 |
|
| 506 |
render_history()
|
| 507 |
|