Spaces:
Running
Running
talexm
commited on
Commit
·
7da4f80
1
Parent(s):
f72b5a3
update
Browse files
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 |
-
|
|
|
97 |
categories = ["Technology", "Sports", "Politics", "Entertainment", "Science"]
|
98 |
|
99 |
-
#
|
|
|
|
|
|
|
100 |
news_results = {}
|
101 |
|
102 |
-
|
|
|
103 |
|
104 |
try:
|
105 |
-
# Fetch
|
106 |
for category in categories:
|
107 |
-
st.markdown(f"Fetching news for **{category}**...")
|
108 |
try:
|
109 |
-
|
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 |
-
#
|
116 |
st.subheader("Global News Carousel")
|
117 |
for category, articles in news_results.items():
|
118 |
-
st.markdown(f"
|
119 |
-
|
120 |
-
|
121 |
-
|
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
|
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():
|