talexm commited on
Commit
f4ff78b
1 Parent(s): 5827073
Files changed (1) hide show
  1. app.py +11 -51
app.py CHANGED
@@ -111,61 +111,21 @@ try:
111
  except Exception as e:
112
  news_results[category] = [f"Error fetching news: {str(e)}"]
113
 
114
- # Custom Carousel Style
115
- st.markdown(
116
- """
117
- <style>
118
- .carousel {
119
- display: flex;
120
- overflow-x: auto;
121
- scroll-snap-type: x mandatory;
122
- gap: 1rem;
123
- padding: 1rem;
124
- }
125
- .carousel-item {
126
- scroll-snap-align: start;
127
- flex: none;
128
- width: 300px;
129
- background: #f9f9f9;
130
- border-radius: 10px;
131
- padding: 1rem;
132
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
133
- }
134
- .carousel-item h3 {
135
- margin-bottom: 1rem;
136
- font-size: 1.25rem;
137
- color: #333;
138
- }
139
- .carousel-item a {
140
- text-decoration: none;
141
- color: #007BFF;
142
- }
143
- .carousel-item a:hover {
144
- text-decoration: underline;
145
- }
146
- </style>
147
- <div class="carousel">
148
- """,
149
- unsafe_allow_html=True,
150
- )
151
-
152
- # Add News Items to the Carousel
153
  for category, articles in news_results.items():
 
 
 
154
  if articles and "Error fetching news" not in articles[0]:
155
- st.markdown(
156
- f"""
157
- <div class="carousel-item">
158
- <h3>{category} News</h3>
159
- {"".join([f'<p><a href="{article}" target="_blank">{article}</a></p>' for article in articles])}
160
- </div>
161
- """,
162
- unsafe_allow_html=True,
163
- )
164
-
165
- # Close the carousel container
166
- st.markdown("</div>", unsafe_allow_html=True)
167
  except Exception as e:
168
  st.error(f"An unexpected error occurred: {str(e)}")
 
 
169
  # # Display results
170
  # for category, articles in news_results.items():
171
  # st.write(f"### Top News in {category}:")
 
111
  except Exception as e:
112
  news_results[category] = [f"Error fetching news: {str(e)}"]
113
 
114
+ # Display Results Using Columns
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  for category, articles in news_results.items():
116
+ st.subheader(f"{category} News")
117
+ cols = st.columns(3) # Create 3 columns for carousel-like layout
118
+
119
  if articles and "Error fetching news" not in articles[0]:
120
+ for idx, article in enumerate(articles):
121
+ with cols[idx % 3]: # Cycle through columns
122
+ st.markdown(f"### [{category} Article {idx + 1}]({article})", unsafe_allow_html=True)
123
+ else:
124
+ st.warning(f"Could not fetch news for **{category}**.")
 
 
 
 
 
 
 
125
  except Exception as e:
126
  st.error(f"An unexpected error occurred: {str(e)}")
127
+
128
+
129
  # # Display results
130
  # for category, articles in news_results.items():
131
  # st.write(f"### Top News in {category}:")