Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,11 @@ import pandas as pd
|
|
3 |
import requests
|
4 |
from apify_client import ApifyClient
|
5 |
|
6 |
-
# Function to fetch Google Maps info using the
|
7 |
def fetch_google_maps_info(website_name):
|
8 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
9 |
run_input = {"searchStringsArray": [website_name]}
|
10 |
-
run = apify_client.actor("
|
11 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
12 |
return items[0] if items else None
|
13 |
|
@@ -18,25 +18,14 @@ def fetch_weather_info(lat, lon):
|
|
18 |
response = requests.get(url)
|
19 |
return response.json()
|
20 |
|
21 |
-
# Function to fetch website content using the
|
22 |
def fetch_website_content(website_url):
|
23 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
24 |
-
run_input = {
|
25 |
-
run = apify_client.actor("
|
26 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
27 |
return items if items else None
|
28 |
|
29 |
-
# Function to fetch customer reviews using the Xb8osYTtOjlsgI6k9 actor
|
30 |
-
def fetch_customer_reviews(location_query):
|
31 |
-
client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
32 |
-
run_input = {
|
33 |
-
"searchStringsArray": ["restaurant"],
|
34 |
-
"locationQuery": location_query,
|
35 |
-
"language": "en",
|
36 |
-
}
|
37 |
-
run = client.actor("Xb8osYTtOjlsgI6k9").call(run_input=run_input)
|
38 |
-
return list(client.dataset(run["defaultDatasetId"]).iterate_items())
|
39 |
-
|
40 |
# Streamlit app for Data Visualization
|
41 |
st.title("Data Visualization")
|
42 |
|
@@ -49,21 +38,55 @@ if website_name:
|
|
49 |
|
50 |
# Fetch Google Maps data
|
51 |
google_maps_data = fetch_google_maps_info(website_name)
|
52 |
-
progress_bar.progress(
|
53 |
-
|
54 |
-
if google_maps_data:
|
55 |
-
location_query = google_maps_data.get("locationQuery")
|
56 |
-
reviews_data = fetch_customer_reviews(location_query)
|
57 |
-
progress_bar.progress(66)
|
58 |
|
59 |
-
|
60 |
-
#
|
|
|
|
|
61 |
|
62 |
-
# Display
|
63 |
-
|
64 |
-
|
65 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
progress_bar.progress(100)
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
else:
|
69 |
st.write("No results found for this website / company name on Google Maps.")
|
|
|
3 |
import requests
|
4 |
from apify_client import ApifyClient
|
5 |
|
6 |
+
# Function to fetch Google Maps info using the antonces~gmaps actor
|
7 |
def fetch_google_maps_info(website_name):
|
8 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
9 |
run_input = {"searchStringsArray": [website_name]}
|
10 |
+
run = apify_client.actor("antonces~gmaps").call(run_input=run_input)
|
11 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
12 |
return items[0] if items else None
|
13 |
|
|
|
18 |
response = requests.get(url)
|
19 |
return response.json()
|
20 |
|
21 |
+
# Function to fetch website content using the antonces~web-scraper-task actor
|
22 |
def fetch_website_content(website_url):
|
23 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
24 |
+
run_input = {}
|
25 |
+
run = apify_client.actor("antonces~web-scraper-task").call(run_input=run_input)
|
26 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
27 |
return items if items else None
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Streamlit app for Data Visualization
|
30 |
st.title("Data Visualization")
|
31 |
|
|
|
38 |
|
39 |
# Fetch Google Maps data
|
40 |
google_maps_data = fetch_google_maps_info(website_name)
|
41 |
+
progress_bar.progress(50)
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
if google_maps_data:
|
44 |
+
# Display website link
|
45 |
+
website_link = google_maps_data.get('website')
|
46 |
+
st.text_area("Website Link:", website_link)
|
47 |
|
48 |
+
# Display location and fetch weather info
|
49 |
+
lat = google_maps_data["location"]["lat"]
|
50 |
+
lng = google_maps_data["location"]["lng"]
|
51 |
+
st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]}))
|
52 |
+
weather_data = fetch_weather_info(lat, lng)
|
53 |
+
current_weather = weather_data.get("current", {})
|
54 |
+
temp = current_weather.get('temp')
|
55 |
+
temp_in_celsius = temp - 273.15
|
56 |
+
st.write(f"**Location:** {lat}, {lng}")
|
57 |
+
st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
|
58 |
+
st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
|
59 |
+
|
60 |
+
# Display Occupancy Data
|
61 |
+
st.subheader("Occupancy Data")
|
62 |
+
occupancy_data = google_maps_data.get('popularTimesHistogram', {})
|
63 |
+
for day, day_data in occupancy_data.items():
|
64 |
+
hours = [entry['hour'] for entry in day_data]
|
65 |
+
occupancy = [entry['occupancyPercent'] for entry in day_data]
|
66 |
+
st.write(day)
|
67 |
+
st.bar_chart(pd.Series(occupancy, index=hours))
|
68 |
|
69 |
+
# Display Review Count and Distribution
|
70 |
+
st.subheader("Review Count and Distribution")
|
71 |
+
st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
|
72 |
+
review_distribution = google_maps_data.get('reviewsDistribution', {})
|
73 |
+
st.bar_chart(pd.Series(review_distribution))
|
74 |
+
|
75 |
+
# Display Reviews Table
|
76 |
+
st.subheader("Customer Reviews")
|
77 |
+
reviews = google_maps_data.get('reviews', [])
|
78 |
+
review_df = pd.DataFrame(reviews)
|
79 |
+
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
|
80 |
+
|
81 |
+
# Fetch and Display Website Content
|
82 |
+
st.subheader("Website Content")
|
83 |
+
website_content_data = fetch_website_content(website_link)
|
84 |
progress_bar.progress(100)
|
85 |
+
|
86 |
+
if website_content_data:
|
87 |
+
website_df = pd.DataFrame(website_content_data)
|
88 |
+
st.table(website_df)
|
89 |
+
else:
|
90 |
+
st.write("Unable to retrieve website content.")
|
91 |
else:
|
92 |
st.write("No results found for this website / company name on Google Maps.")
|