Anne314159 commited on
Commit
bc1f973
·
verified ·
1 Parent(s): da0305b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -29
app.py CHANGED
@@ -6,6 +6,8 @@ from gnews import GNews
6
  from newspaper import Article
7
  import pandas as pd
8
  import numpy as np
 
 
9
 
10
 
11
  def fetch_news(topic):
@@ -136,46 +138,78 @@ def page_article_to_social_post():
136
  st.success('Generated Content:')
137
  st.write(post_content)
138
 
139
- def page_vaccation():
140
-
141
- st.title("Map Display with Start and End Points")
142
-
143
- # Collect user inputs for latitude and longitude of start and end points
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  st.header("Start Point")
145
- start_lat = st.number_input("Start Latitude", value=37.76, format="%.6f")
146
- start_lon = st.number_input("Start Longitude", value=-122.4, format="%.6f")
147
-
148
- st.header("End Point")
149
- end_lat = st.number_input("End Latitude", value=37.76, format="%.6f")
150
- end_lon = st.number_input("End Longitude", value=-122.41, format="%.6f")
151
-
152
- # Prepare data for the map
153
- if start_lat and start_lon and end_lat and end_lon:
154
- points_df = pd.DataFrame({
155
- 'lat': [start_lat, end_lat],
156
- 'lon': [start_lon, end_lon],
157
- 'color': ['#ff0000', '#0000ff'], # Start in red, end in blue
158
- 'size': [100, 100] # Size of the points
159
- })
160
-
161
- # Display the map with customized points
162
- st.map(data=points_df, latitude='lat', longitude='lon', color='color', size='size')
163
-
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
  # Setup the sidebar with page selection
167
  st.sidebar.title("Anne's Current Projects :star2:")
168
 
169
  page = st.sidebar.selectbox(
170
  'What project do you like to see first?',
171
- ('trending_niche', 'page_article_to_social_post', 'Vaccation Page'))
172
-
173
 
174
  # Display the selected page
175
  if page == 'trending_niche':
176
  page_trending_niche()
177
  elif page == 'page_article_to_social_post':
178
  page_article_to_social_post()
179
- elif page == 'Vaccation Page':
180
- page_vaccation()
181
-
 
6
  from newspaper import Article
7
  import pandas as pd
8
  import numpy as np
9
+ import requests
10
+ import json
11
 
12
 
13
  def fetch_news(topic):
 
138
  st.success('Generated Content:')
139
  st.write(post_content)
140
 
141
+ # Corrected Function to get a route from OpenRouteService
142
+ def get_route(start_coord, end_coord, api_key):
143
+ url = "https://api.openrouteservice.org/v2/directions/driving-car"
144
+ headers = {
145
+ 'Authorization': api_key,
146
+ 'Content-Type': 'application/json'
147
+ }
148
+ body = {
149
+ "coordinates": [start_coord, end_coord]
150
+ }
151
+ response = requests.post(url, headers=headers, data=json.dumps(body))
152
+ if response.status_code == 200:
153
+ route = response.json()['features'][0]['geometry']['coordinates']
154
+ return route
155
+ else:
156
+ st.error("Failed to get route data")
157
+ return None
158
+
159
+ def page_vacation():
160
+ st.title("Route Finder with OpenRouteService")
161
+
162
+ # Input for API Key
163
+ api_key = st.text_input("Enter your OpenRouteService API Key", type="password")
164
+
165
+ # Inputs for start and end coordinates
166
  st.header("Start Point")
167
+ start_lat = st.number_input("Start Latitude", value=37.76)
168
+ start_lon = st.number_input("Start Longitude", value=-122.4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
+ st.header("End Point")
171
+ end_lat = st.number_input("End Latitude", value=37.77)
172
+ end_lon = st.number_input("End Longitude", value=-122.41)
173
+
174
+ if st.button("Find Route") and api_key:
175
+ route = get_route([start_lon, start_lat], [end_lon, end_lat], api_key)
176
+ if route:
177
+ # Convert the route to a DataFrame
178
+ route_df = pd.DataFrame(route, columns=['lon', 'lat'])
179
+
180
+ # Display the route using PyDeck
181
+ st.pydeck_chart(pdk.Deck(
182
+ map_style='mapbox://styles/mapbox/light-v9',
183
+ initial_view_state=pdk.ViewState(
184
+ latitude=37.76,
185
+ longitude=-122.4,
186
+ zoom=11,
187
+ pitch=50,
188
+ ),
189
+ layers=[
190
+ pdk.Layer(
191
+ 'LineLayer',
192
+ data=route_df,
193
+ get_source_position='[lon, lat]',
194
+ get_target_position='[lon, lat]',
195
+ get_color='[255, 0, 0, 160]',
196
+ get_width=5,
197
+ pickable=True
198
+ ),
199
+ ],
200
+ ))
201
 
202
  # Setup the sidebar with page selection
203
  st.sidebar.title("Anne's Current Projects :star2:")
204
 
205
  page = st.sidebar.selectbox(
206
  'What project do you like to see first?',
207
+ ('trending_niche', 'page_article_to_social_post', 'Vacation Page'))
 
208
 
209
  # Display the selected page
210
  if page == 'trending_niche':
211
  page_trending_niche()
212
  elif page == 'page_article_to_social_post':
213
  page_article_to_social_post()
214
+ elif page == 'Vacation Page':
215
+ page_vacation()