Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,78 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Streamlit UI
|
| 8 |
st.title("π Tourist Guider Chatbot πΊοΈ")
|
| 9 |
-
st.write("
|
| 10 |
|
| 11 |
# User input
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
st.write("**Chatbot:**", response[0]['generated_text'])
|
| 18 |
else:
|
| 19 |
-
st.write("Please enter a
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import googlemaps
|
| 4 |
|
| 5 |
+
# API Keys (Replace with your own)
|
| 6 |
+
UNSPLASH_ACCESS_KEY = "your_unsplash_api_key"
|
| 7 |
+
GOOGLE_MAPS_API_KEY = "your_google_places_api_key"
|
| 8 |
+
|
| 9 |
+
# Initialize Google Maps client
|
| 10 |
+
gmaps = googlemaps.Client(key=GOOGLE_MAPS_API_KEY)
|
| 11 |
+
|
| 12 |
+
# Function to fetch images from Unsplash
|
| 13 |
+
def get_place_image(place):
|
| 14 |
+
url = f"https://api.unsplash.com/search/photos?query={place}&client_id={UNSPLASH_ACCESS_KEY}"
|
| 15 |
+
response = requests.get(url).json()
|
| 16 |
+
if response.get("results"):
|
| 17 |
+
return response["results"][0]["urls"]["regular"]
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
# Function to fetch top tourist attractions from Google Places API
|
| 21 |
+
def get_top_places(location):
|
| 22 |
+
places_result = gmaps.places_nearby(
|
| 23 |
+
location=location, radius=10000, type="tourist_attraction"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
places = sorted(
|
| 27 |
+
places_result.get("results", []),
|
| 28 |
+
key=lambda x: x.get("rating", 0), # Sort by rating (highest first)
|
| 29 |
+
reverse=True
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return places[:5] # Return top 5 attractions
|
| 33 |
+
|
| 34 |
+
# Function to generate Google Maps link
|
| 35 |
+
def get_maps_link(place):
|
| 36 |
+
return f"https://www.google.com/maps/search/?api=1&query={place.replace(' ', '+')}"
|
| 37 |
|
| 38 |
# Streamlit UI
|
| 39 |
st.title("π Tourist Guider Chatbot πΊοΈ")
|
| 40 |
+
st.write("Enter a place name to get recommendations!")
|
| 41 |
|
| 42 |
# User input
|
| 43 |
+
place_name = st.text_input("Enter a place name:")
|
| 44 |
+
|
| 45 |
+
if st.button("Search"):
|
| 46 |
+
if place_name:
|
| 47 |
+
# Get location coordinates
|
| 48 |
+
geocode_result = gmaps.geocode(place_name)
|
| 49 |
+
if not geocode_result:
|
| 50 |
+
st.write("β Location not found.")
|
| 51 |
+
else:
|
| 52 |
+
location = geocode_result[0]["geometry"]["location"]
|
| 53 |
+
lat, lng = location["lat"], location["lng"]
|
| 54 |
+
|
| 55 |
+
# Fetch tourist attractions
|
| 56 |
+
st.subheader("ποΈ Top Attractions")
|
| 57 |
+
attractions = get_top_places((lat, lng))
|
| 58 |
+
|
| 59 |
+
if attractions:
|
| 60 |
+
for attraction in attractions:
|
| 61 |
+
name = attraction["name"]
|
| 62 |
+
rating = attraction.get("rating", "No rating")
|
| 63 |
+
image_url = get_place_image(name) or get_place_image(place_name)
|
| 64 |
+
|
| 65 |
+
# Display attraction details
|
| 66 |
+
st.write(f"**{name}** - β {rating}")
|
| 67 |
+
if image_url:
|
| 68 |
+
st.image(image_url, width=300)
|
| 69 |
+
st.markdown(f"[π View on Maps]({get_maps_link(name)})")
|
| 70 |
+
st.write("---") # Divider
|
| 71 |
+
else:
|
| 72 |
+
st.write("No attractions found.")
|
| 73 |
|
| 74 |
+
# Provide Google Maps link for directions
|
| 75 |
+
st.subheader("πΊοΈ How to Reach?")
|
| 76 |
+
st.markdown(f"[π Get Directions to {place_name}]({get_maps_link(place_name)})")
|
|
|
|
| 77 |
else:
|
| 78 |
+
st.write("Please enter a place name.")
|