AhmadRAZA23 commited on
Commit
6f982bd
·
verified ·
1 Parent(s): 098d424

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -31
app.py CHANGED
@@ -1,39 +1,63 @@
1
  import streamlit as st
 
 
 
2
  import requests
3
- from bs4 import BeautifulSoup
4
- from transformers import pipeline
5
 
6
- # Load a Hugging Face model (for example, a text classification model)
7
- model = pipeline("text-classification", model="distilbert-base-uncased")
8
 
9
- # Define a function to get flight data by web scraping
10
- def get_flight_data(departure, arrival):
11
- url = f'https://example.com/flights?departure={departure}&arrival={arrival}'
12
  response = requests.get(url)
13
- soup = BeautifulSoup(response.content, 'html.parser')
14
-
15
- flights = soup.find_all('div', class_='flight-info')
16
- return flights
17
-
18
- # Initialize Streamlit app
19
- st.title('Flight Timing Travel Application')
20
-
21
- # User input
22
- departure = st.text_input('Departure City/Country')
23
- arrival = st.text_input('Arrival City/Country')
24
 
25
- if st.button('Search'):
26
- # Process user input with the Hugging Face model
27
- processed_departure = model(departure)[0]['label']
28
- processed_arrival = model(arrival)[0]['label']
29
 
30
- # Get flight data
31
- flights = get_flight_data(processed_departure, processed_arrival)
 
 
 
 
32
 
33
- if flights:
34
- for flight in flights:
35
- flight_details = flight.text
36
- st.write(flight_details)
37
- st.write("---")
38
- else:
39
- st.write("No flights found.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from geopy.distance import geodesic
3
+ import folium
4
+ from streamlit_folium import st_folium
5
  import requests
 
 
6
 
7
+ # OpenWeatherMap API Key (replace with your own key)
8
+ API_KEY = "your_openweathermap_api_key"
9
 
10
+ def get_weather(lat, lon):
11
+ url = f"http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_KEY}&units=metric"
 
12
  response = requests.get(url)
13
+ if response.status_code == 200:
14
+ weather_data = response.json()
15
+ return weather_data
16
+ else:
17
+ return None
 
 
 
 
 
 
18
 
19
+ def main():
20
+ st.title("Simplified Flight Planning App")
 
 
21
 
22
+ # Flight Planning
23
+ st.header("Flight Planning")
24
+ lat1 = st.number_input("Enter Departure Latitude", value=37.6213) # Example: SFO
25
+ lon1 = st.number_input("Enter Departure Longitude", value=-122.3790)
26
+ lat2 = st.number_input("Enter Destination Latitude", value=34.0522) # Example: LAX
27
+ lon2 = st.number_input("Enter Destination Longitude", value=-118.2437)
28
 
29
+ if st.button("Calculate Distance"):
30
+ coords_1 = (lat1, lon1)
31
+ coords_2 = (lat2, lon2)
32
+ distance = geodesic(coords_1, coords_2).miles
33
+ st.write(f"Distance: {distance:.2f} miles")
34
+
35
+ # Navigation
36
+ st.header("Navigation")
37
+ m = folium.Map(location=[(lat1 + lat2) / 2, (lon1 + lon2) / 2], zoom_start=6)
38
+ folium.Marker([lat1, lon1], tooltip="Departure").add_to(m)
39
+ folium.Marker([lat2, lon2], tooltip="Destination").add_to(m)
40
+ st_folium(m, width=700)
41
+
42
+ # Weather Updates
43
+ st.header("Weather Updates")
44
+ if st.button("Get Weather Updates"):
45
+ weather_departure = get_weather(lat1, lon1)
46
+ weather_destination = get_weather(lat2, lon2)
47
+
48
+ if weather_departure:
49
+ st.write(f"Weather at Departure: {weather_departure['weather'][0]['description']}")
50
+ st.write(f"Temperature: {weather_departure['main']['temp']}°C")
51
+ st.write(f"Wind Speed: {weather_departure['wind']['speed']} m/s")
52
+ else:
53
+ st.write("Failed to retrieve weather data for departure location.")
54
+
55
+ if weather_destination:
56
+ st.write(f"Weather at Destination: {weather_destination['weather'][0]['description']}")
57
+ st.write(f"Temperature: {weather_destination['main']['temp']}°C")
58
+ st.write(f"Wind Speed: {weather_destination['wind']['speed']} m/s")
59
+ else:
60
+ st.write("Failed to retrieve weather data for destination location.")
61
+
62
+ if __name__ == "__main__":
63
+ main()