antfraia commited on
Commit
3e996d0
·
1 Parent(s): fabbbe0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -0
app.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ from langchain.utilities import ApifyWrapper
5
+ from langchain.document_loaders.base import Document
6
+
7
+ # Initialize ApifyWrapper and other environment variables
8
+ os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
9
+ os.environ["APIFY_API_TOKEN"] = "Your Apify API token"
10
+
11
+ APIFY_WEATHER_KEY = "91b23cab82ee530b2052c8757e343b0d"
12
+ apify = ApifyWrapper()
13
+
14
+ def get_website_summary(website_url):
15
+ # For now, return a dummy summary. Replace this with the API logic you have
16
+ return "This is a dummy summary for " + website_url
17
+
18
+ def get_google_reviews(website_url):
19
+ # Return dummy Google Maps reviews for now.
20
+ # Replace this with the logic to get reviews summary using GPT-3.5 and Google Maps API.
21
+ return {
22
+ "pros": ["Great ambiance", "Friendly staff", "Tasty food"],
23
+ "cons": ["A bit pricey", "Long waiting times on weekends", "Limited parking"]
24
+ }
25
+
26
+ def get_peak_times(website_url):
27
+ # Dummy data for peak times.
28
+ # Replace this with the logic to fetch peak times using Google Maps API.
29
+ return {
30
+ "Monday": [10, 20, 30, 40, 30, 20, 10],
31
+ "Tuesday": [15, 25, 35, 45, 35, 25, 15],
32
+ # ... add other days
33
+ }
34
+
35
+ def get_images(website_url):
36
+ # Return dummy image URLs.
37
+ # Replace this with logic to fetch place images using Google Maps API.
38
+ return [
39
+ "https://via.placeholder.com/150",
40
+ "https://via.placeholder.com/150",
41
+ "https://via.placeholder.com/150",
42
+ "https://via.placeholder.com/150",
43
+ "https://via.placeholder.com/150",
44
+ ]
45
+
46
+ def get_map_widget(website_url):
47
+ # Return dummy map coordinates (for New York City).
48
+ # Replace this with the logic to fetch actual coordinates of the place using its website URL.
49
+ return {
50
+ "lat": 40.730610,
51
+ "lon": -73.935242
52
+ }
53
+
54
+ def get_weather_data(lat, lon):
55
+ BASE_URL = f"https://api.openweathermap.org/data/3.0/onecall"
56
+ params = {
57
+ "lat": lat,
58
+ "lon": lon,
59
+ "exclude": "hourly,daily,minutely",
60
+ "appid": APIFY_WEATHER_KEY,
61
+ "units": "metric"
62
+ }
63
+ response = requests.get(BASE_URL, params=params)
64
+ if response.status_code == 200:
65
+ return response.json()
66
+ else:
67
+ return None
68
+
69
+ def process_website(website_url):
70
+ website_summary = get_website_summary(website_url)
71
+ reviews = get_google_reviews(website_url)
72
+ peak_times = get_peak_times(website_url)
73
+ images = get_images(website_url)
74
+ map_widget = get_map_widget(website_url)
75
+
76
+ weather_data = get_weather_data(map_widget["lat"], map_widget["lon"])
77
+ if weather_data:
78
+ temp = weather_data["current"]["temp"]
79
+ weather_desc = weather_data["current"]["weather"][0]["description"]
80
+ weather_widget = f"It's {temp}°C with {weather_desc}."
81
+ else:
82
+ weather_widget = "Unable to fetch weather data at the moment."
83
+
84
+ return website_summary, reviews, peak_times, images, map_widget, weather_widget
85
+
86
+ # Streamlit UI
87
+ st.title("Website Information Extractor")
88
+
89
+ website_url = st.text_input("Enter a website/company name:")
90
+
91
+ if website_url:
92
+ summary, reviews, peak_times, images, map_data, weather_info = process_website(website_url)
93
+
94
+ st.subheader("Website Summary")
95
+ st.write(summary)
96
+
97
+ st.subheader("Google Reviews")
98
+ st.write("Pros:")
99
+ for pro in reviews["pros"]:
100
+ st.write(f"- {pro}")
101
+
102
+ st.write("Cons:")
103
+ for con in reviews["cons"]:
104
+ st.write(f"- {con}")
105
+
106
+ st.subheader("Peak Times")
107
+ for day, times in peak_times.items():
108
+ st.write(f"{day}: {times}")
109
+
110
+ st.subheader("Images")
111
+ for image in images:
112
+ st.image(image)
113
+
114
+ st.subheader("Location")
115
+ st.map({"lat": map_data["lat"], "lon": map_data["lon"]})
116
+
117
+ st.subheader("Current Weather")
118
+ st.write(weather_info)