gopal7093 commited on
Commit
94f3bc7
Β·
verified Β·
1 Parent(s): 2374012

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -10
app.py CHANGED
@@ -1,19 +1,78 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
3
 
4
- # Load the chatbot model from Hugging Face
5
- chatbot = pipeline("text-generation", model="google/flan-t5-base")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # Streamlit UI
8
  st.title("🌍 Tourist Guider Chatbot πŸ—ΊοΈ")
9
- st.write("Ask me anything about travel, places, or recommendations!")
10
 
11
  # User input
12
- user_input = st.text_input("Your question:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- if st.button("Ask"):
15
- if user_input:
16
- response = chatbot(user_input, max_length=100)
17
- st.write("**Chatbot:**", response[0]['generated_text'])
18
  else:
19
- st.write("Please enter a question.")
 
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.")