akashjayampu commited on
Commit
72bcd1f
Β·
verified Β·
1 Parent(s): 138f148

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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", label_visibility="visible")
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
- t1 = time.time()
23
  articles = google_search(query, num_results=10)
24
- fetch_time = round(time.time() - t1, 2)
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
- contents = [a['snippet'] for a in articles]
35
 
36
  with st.spinner("🧠 Summarizing, classifying, and detecting fake news..."):
37
- t2 = time.time()
38
- summaries = summarize_texts(contents)
39
- sentiments = analyze_sentiment(contents)
40
- fakeness = detect_fake_news(contents)
41
- process_time = round(time.time() - t2, 2)
42
 
43
- st.info(f"⏱️ AI analysis completed in {process_time} seconds.")
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.")