talexm commited on
Commit
7da4f80
·
1 Parent(s): f72b5a3
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -93,37 +93,40 @@ if st.button("Search News About Me"):
93
  st.warning("Please enter your name or handle to search.")
94
 
95
  # Google Search: Global News Categories
96
- # Global News Categories
 
97
  categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
98
 
99
- # News Results
 
 
 
100
  news_results = {}
101
 
102
- st.title("Global News Insights")
 
103
 
104
  try:
105
- # Fetch News for Each Category
106
  for category in categories:
107
- st.markdown(f"Fetching news for **{category}**...")
108
  try:
109
- category_results = list(search(f"latest {category} news", num_results=3))
110
- news_results[category] = category_results
111
  except Exception as e:
112
- # Handle Errors and Populate Default Message
113
  news_results[category] = [f"Error fetching news: {str(e)}"]
114
 
115
- # Display News Carousel
116
  st.subheader("Global News Carousel")
117
  for category, articles in news_results.items():
118
- st.markdown(f"### {category} News")
119
- for idx, article in enumerate(articles, start=1):
120
- if "Error fetching news" in article:
121
- st.warning(f"News for **{category}** could not be retrieved.")
122
- else:
123
  st.markdown(f"{idx}. [Read Article Here]({article})")
 
 
124
 
125
  except Exception as e:
126
- st.error(f"An unexpected error occurred while fetching global news: {str(e)}")
127
 
128
  # # Display results
129
  # for category, articles in news_results.items():
 
93
  st.warning("Please enter your name or handle to search.")
94
 
95
  # Google Search: Global News Categories
96
+
97
+ # Categories to Fetch News
98
  categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
99
 
100
+ # Title and Introduction
101
+ st.title("Global News Insights")
102
+
103
+ # News Results Dictionary
104
  news_results = {}
105
 
106
+ # Fetch and Display News
107
+ st.markdown("### Fetching News for Popular Categories")
108
 
109
  try:
110
+ # Fetch Top 3 Articles for Each Category
111
  for category in categories:
 
112
  try:
113
+ news_results[category] = list(search(f"latest {category} news", num_results=3))
 
114
  except Exception as e:
 
115
  news_results[category] = [f"Error fetching news: {str(e)}"]
116
 
117
+ # Carousel Style Display
118
  st.subheader("Global News Carousel")
119
  for category, articles in news_results.items():
120
+ st.markdown(f"#### {category} News")
121
+ if articles and "Error fetching news" not in articles[0]:
122
+ # Use Embedded Links
123
+ for idx, article in enumerate(articles, start=1):
 
124
  st.markdown(f"{idx}. [Read Article Here]({article})")
125
+ else:
126
+ st.warning(f"Could not fetch news for **{category}**.")
127
 
128
  except Exception as e:
129
+ st.error(f"An unexpected error occurred: {str(e)}")
130
 
131
  # # Display results
132
  # for category, articles in news_results.items():