Spaces:
Running
Running
talexm
commited on
Commit
·
f72b5a3
1
Parent(s):
ceef17e
update
Browse files
app.py
CHANGED
@@ -93,40 +93,37 @@ 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 |
-
|
97 |
categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
|
|
|
|
|
98 |
news_results = {}
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
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():
|
|
|
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():
|