talexm commited on
Commit
41216ee
1 Parent(s): b94e464
Files changed (1) hide show
  1. app.py +51 -11
app.py CHANGED
@@ -91,29 +91,69 @@ if st.button("Search News About Me"):
91
  else:
92
  st.warning("Please enter your name or handle to search.")
93
 
94
- # Google Search: Global News Categories
95
- st.subheader("2. Global News Insights")
 
 
 
 
 
 
 
 
 
96
  categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
97
  news_results = {}
98
 
 
99
  if st.button("Fetch Global News"):
100
  try:
101
  for category in categories:
102
  st.write(f"Fetching news for **{category}**...")
103
- try:
104
- category_results = list(search(f"latest {category} news", num_results=3))
105
- news_results[category] = category_results
106
- except Exception as e:
107
- news_results[category] = [f"Error fetching news: {str(e)}"]
108
 
109
- # Display results
 
110
  for category, articles in news_results.items():
111
- st.write(f"### Top News in {category}:")
112
- for idx, article in enumerate(articles, start=1):
113
- st.write(f"{idx}. [Read here]({article})")
 
 
 
 
 
 
 
 
 
114
  except Exception as e:
115
  st.error(f"An error occurred while fetching global news: {str(e)}")
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  # Document Search
118
  st.subheader("3. Search Documents")
119
  query = st.text_input("Enter your query (e.g., 'sports news', 'machine learning')")
 
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")
159
  query = st.text_input("Enter your query (e.g., 'sports news', 'machine learning')")