Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -10
src/streamlit_app.py
CHANGED
@@ -6,6 +6,7 @@ from dotenv import load_dotenv
|
|
6 |
from google_search import google_search
|
7 |
from mistral_llm import summarize_texts, detect_fake_news, analyze_sentiment
|
8 |
|
|
|
9 |
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), '..', '.env'))
|
10 |
|
11 |
st.set_page_config(page_title="π₯ Brand Crisis Detector", layout="wide", page_icon="π₯")
|
@@ -13,15 +14,15 @@ st.title("π₯ Real-Time Brand Crisis Detector")
|
|
13 |
st.markdown("Analyze web content about your brand in real-time using AI β‘")
|
14 |
st.caption(f"π Last refreshed: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
15 |
|
16 |
-
query = st.text_input("π Enter a brand or keyword", placeholder="e.g., Nvidia, Nestle, Jio"
|
17 |
|
18 |
if st.button("Start Analysis π") or (query and st.session_state.get("last_query") != query):
|
19 |
st.session_state.last_query = query
|
20 |
|
21 |
with st.spinner(f"π Searching Google for **{query}**..."):
|
22 |
-
|
23 |
articles = google_search(query, num_results=10)
|
24 |
-
fetch_time = round(time.time() -
|
25 |
|
26 |
if not articles:
|
27 |
st.warning("β No results found. Try a different query.")
|
@@ -31,16 +32,16 @@ if st.button("Start Analysis π") or (query and st.session_state.get("last_que
|
|
31 |
|
32 |
titles = [a['title'] for a in articles]
|
33 |
links = [a['link'] for a in articles]
|
34 |
-
|
35 |
|
36 |
with st.spinner("π§ Summarizing, classifying, and detecting fake news..."):
|
37 |
-
|
38 |
-
summaries = summarize_texts(
|
39 |
-
sentiments = analyze_sentiment(
|
40 |
-
fakeness = detect_fake_news(
|
41 |
-
|
42 |
|
43 |
-
st.info(f"β±οΈ AI analysis completed in {
|
44 |
|
45 |
for i in range(len(articles)):
|
46 |
with st.container():
|
@@ -50,3 +51,5 @@ if st.button("Start Analysis π") or (query and st.session_state.get("last_que
|
|
50 |
st.markdown(f"**π΅οΈ Fake News Score:** `{fakeness[i]}`")
|
51 |
st.markdown(f"**π Summary:** {summaries[i]}")
|
52 |
st.markdown("---")
|
|
|
|
|
|
6 |
from google_search import google_search
|
7 |
from mistral_llm import summarize_texts, detect_fake_news, analyze_sentiment
|
8 |
|
9 |
+
# Load environment variables (e.g., Hugging Face token)
|
10 |
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), '..', '.env'))
|
11 |
|
12 |
st.set_page_config(page_title="π₯ Brand Crisis Detector", layout="wide", page_icon="π₯")
|
|
|
14 |
st.markdown("Analyze web content about your brand in real-time using AI β‘")
|
15 |
st.caption(f"π Last refreshed: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
16 |
|
17 |
+
query = st.text_input("π Enter a brand or keyword", placeholder="e.g., Nvidia, Nestle, Jio")
|
18 |
|
19 |
if st.button("Start Analysis π") or (query and st.session_state.get("last_query") != query):
|
20 |
st.session_state.last_query = query
|
21 |
|
22 |
with st.spinner(f"π Searching Google for **{query}**..."):
|
23 |
+
start_time = time.time()
|
24 |
articles = google_search(query, num_results=10)
|
25 |
+
fetch_time = round(time.time() - start_time, 2)
|
26 |
|
27 |
if not articles:
|
28 |
st.warning("β No results found. Try a different query.")
|
|
|
32 |
|
33 |
titles = [a['title'] for a in articles]
|
34 |
links = [a['link'] for a in articles]
|
35 |
+
snippets = [a['snippet'] for a in articles]
|
36 |
|
37 |
with st.spinner("π§ Summarizing, classifying, and detecting fake news..."):
|
38 |
+
start_ai = time.time()
|
39 |
+
summaries = summarize_texts(snippets)
|
40 |
+
sentiments = analyze_sentiment(snippets)
|
41 |
+
fakeness = detect_fake_news(snippets)
|
42 |
+
ai_time = round(time.time() - start_ai, 2)
|
43 |
|
44 |
+
st.info(f"β±οΈ AI analysis completed in {ai_time} seconds.")
|
45 |
|
46 |
for i in range(len(articles)):
|
47 |
with st.container():
|
|
|
51 |
st.markdown(f"**π΅οΈ Fake News Score:** `{fakeness[i]}`")
|
52 |
st.markdown(f"**π Summary:** {summaries[i]}")
|
53 |
st.markdown("---")
|
54 |
+
else:
|
55 |
+
st.info("Enter a brand or keyword and click 'Start Analysis π' to begin.")
|