talexm commited on
Commit
ceef17e
·
1 Parent(s): 1ab9704
Files changed (1) hide show
  1. app.py +33 -51
app.py CHANGED
@@ -7,6 +7,7 @@ import os
7
  from rag_sec.document_search_system import DocumentSearchSystem
8
  from chainguard.blockchain_logger import BlockchainLogger
9
  from PIL import Image
 
10
 
11
  # Blockchain Logger
12
  blockchain_logger = BlockchainLogger()
@@ -91,68 +92,49 @@ if st.button("Search News About Me"):
91
  else:
92
  st.warning("Please enter your name or handle to search.")
93
 
94
- # Mocked fetch_news for demonstration; replace with actual API or data retrieval
95
- def fetch_news(query, num_results=3):
96
- """Fetch news for a specific query. Replace with actual API logic."""
97
- return [
98
- {"title": f"{query} Headline 1", "link": "https://example.com/news1", "img_url": "https://via.placeholder.com/150"},
99
- {"title": f"{query} Headline 2", "link": "https://example.com/news2", "img_url": "https://via.placeholder.com/150"},
100
- {"title": f"{query} Headline 3", "link": "https://example.com/news3", "img_url": "https://via.placeholder.com/150"}
101
- ]
102
-
103
- # Global News Carousel
104
- st.title("Global News Insights")
105
  categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
106
  news_results = {}
107
 
108
- # Fetch Global News
109
  if st.button("Fetch Global News"):
110
  try:
111
  for category in categories:
112
  st.write(f"Fetching news for **{category}**...")
113
- category_results = fetch_news(f"latest {category} news", num_results=3)
114
- news_results[category] = category_results
115
-
116
- # Display News Carousel
117
- st.subheader("Latest Global News Carousel")
118
- for category, articles in news_results.items():
119
- with st.container():
120
- st.markdown(f"### {category} News")
121
- for article in articles:
122
- col1, col2 = st.columns([1, 4])
123
- with col1:
124
- # Display news image
125
- st.image(article["img_url"], width=100)
126
- with col2:
127
- # Display news title and link
128
- st.markdown(f"**[{article['title']}]({article['link']})**")
129
- st.write(article["link"])
 
 
 
 
 
 
130
 
131
  except Exception as e:
132
  st.error(f"An error occurred while fetching global news: {str(e)}")
133
 
134
- # Google Search: Global News Categories
135
- # st.subheader("2. Global News Insights")
136
- # categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
137
- # news_results = {}
138
- #
139
- # if st.button("Fetch Global News"):
140
- # try:
141
- # for category in categories:
142
- # st.write(f"Fetching news for **{category}**...")
143
- # try:
144
- # category_results = list(search(f"latest {category} news", num_results=3))
145
- # news_results[category] = category_results
146
- # except Exception as e:
147
- # news_results[category] = [f"Error fetching news: {str(e)}"]
148
- #
149
- # # Display results
150
- # for category, articles in news_results.items():
151
- # st.write(f"### Top News in {category}:")
152
- # for idx, article in enumerate(articles, start=1):
153
- # st.write(f"{idx}. [Read here]({article})")
154
- # except Exception as e:
155
- # st.error(f"An error occurred while fetching global news: {str(e)}")
156
 
157
  # Document Search
158
  st.subheader("3. Search Documents")
 
7
  from rag_sec.document_search_system import DocumentSearchSystem
8
  from chainguard.blockchain_logger import BlockchainLogger
9
  from PIL import Image
10
+ from itertools import cycle
11
 
12
  # Blockchain Logger
13
  blockchain_logger = BlockchainLogger()
 
92
  else:
93
  st.warning("Please enter your name or handle to search.")
94
 
95
+ # Google Search: Global News Categories
96
+ st.subheader("2. Global News Insights")
 
 
 
 
 
 
 
 
 
97
  categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
98
  news_results = {}
99
 
 
100
  if st.button("Fetch Global News"):
101
  try:
102
  for category in categories:
103
  st.write(f"Fetching news for **{category}**...")
104
+ try:
105
+ category_results = list(search(f"latest {category} news", num_results=3))
106
+ news_results[category] = category_results
107
+ except Exception as e:
108
+ news_results[category] = [f"Error fetching news: {str(e)}"]
109
+ # Convert results into a carousel display
110
+ st.subheader("Global News Carousel")
111
+ articles = []
112
+ for category, urls in news_results.items():
113
+ for url in urls:
114
+ articles.append({"category": category, "url": url})
115
+
116
+ # Implement carousel
117
+ if articles:
118
+ article_cycle = cycle(articles) # Create a looping iterator
119
+ st.write("Use the arrows below to navigate through the articles:")
120
+ for _ in range(len(articles)):
121
+ article = next(article_cycle)
122
+ with st.container():
123
+ st.markdown(f"### {article['category']} News")
124
+ st.markdown(f"[Read Article Here]({article['url']})")
125
+ else:
126
+ st.warning("No news articles found.")
127
 
128
  except Exception as e:
129
  st.error(f"An error occurred while fetching global news: {str(e)}")
130
 
131
+ # # Display results
132
+ # for category, articles in news_results.items():
133
+ # st.write(f"### Top News in {category}:")
134
+ # for idx, article in enumerate(articles, start=1):
135
+ # st.write(f"{idx}. [Read here]({article})")
136
+ # except Exception as e:
137
+ # st.error(f"An error occurred while fetching global news: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  # Document Search
140
  st.subheader("3. Search Documents")