Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import requests
|
| 4 |
from apify_client import ApifyClient
|
| 5 |
|
| 6 |
# Function to fetch Google Maps info using the updated actor
|
|
@@ -19,9 +18,9 @@ def fetch_weather_info(lat, lon):
|
|
| 19 |
return response.json()
|
| 20 |
|
| 21 |
# Function to fetch website content using the updated actor
|
| 22 |
-
def fetch_website_content(
|
| 23 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 24 |
-
run_input = {}
|
| 25 |
run = apify_client.actor("moJRLRc85AitArpNN").call(run_input=run_input)
|
| 26 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
| 27 |
return items if items else None
|
|
@@ -31,7 +30,7 @@ def fetch_customer_reviews(google_maps_url):
|
|
| 31 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 32 |
run_input = {
|
| 33 |
"startUrls": [{"url": google_maps_url}],
|
| 34 |
-
"maxReviews":
|
| 35 |
"reviewsSort": "newest",
|
| 36 |
"language": "en",
|
| 37 |
"personalData": True,
|
|
@@ -55,56 +54,21 @@ if website_name:
|
|
| 55 |
progress_bar.progress(50)
|
| 56 |
|
| 57 |
if google_maps_data:
|
| 58 |
-
# Display
|
| 59 |
-
website_link = google_maps_data.get('website')
|
| 60 |
-
st.text_area("Website Link:", website_link)
|
| 61 |
-
|
| 62 |
-
# Display location and fetch weather info
|
| 63 |
-
lat = google_maps_data["location"]["lat"]
|
| 64 |
-
lng = google_maps_data["location"]["lng"]
|
| 65 |
-
st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]}))
|
| 66 |
-
weather_data = fetch_weather_info(lat, lng)
|
| 67 |
-
current_weather = weather_data.get("current", {})
|
| 68 |
-
temp = current_weather.get('temp')
|
| 69 |
-
temp_in_celsius = temp - 273.15
|
| 70 |
-
st.write(f"**Location:** {lat}, {lng}")
|
| 71 |
-
st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
|
| 72 |
-
st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
|
| 73 |
-
|
| 74 |
-
# Display Occupancy Data
|
| 75 |
-
st.subheader("Occupancy Data")
|
| 76 |
-
occupancy_data = google_maps_data.get('popularTimesHistogram', {})
|
| 77 |
-
for day, day_data in occupancy_data.items():
|
| 78 |
-
hours = [entry['hour'] for entry in day_data]
|
| 79 |
-
occupancy = [entry['occupancyPercent'] for entry in day_data]
|
| 80 |
-
st.write(day)
|
| 81 |
-
st.bar_chart(pd.Series(occupancy, index=hours))
|
| 82 |
-
|
| 83 |
-
# Display Review Count and Distribution
|
| 84 |
-
st.subheader("Review Count and Distribution")
|
| 85 |
-
st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
|
| 86 |
-
review_distribution = google_maps_data.get('reviewsDistribution', {})
|
| 87 |
-
st.bar_chart(pd.Series(review_distribution))
|
| 88 |
-
|
| 89 |
-
# Fetch customer reviews from the new API
|
| 90 |
google_maps_url = google_maps_data.get('url')
|
| 91 |
-
|
| 92 |
progress_bar.progress(75)
|
| 93 |
-
|
| 94 |
-
# Display the reviews from the new API
|
| 95 |
-
reviews_df = pd.DataFrame(reviews_data)
|
| 96 |
-
st.subheader("Customer Reviews from New API")
|
| 97 |
-
st.table(reviews_df)
|
| 98 |
-
|
| 99 |
-
# Fetch and Display Website Content
|
| 100 |
-
st.subheader("Website Content")
|
| 101 |
-
website_content_data = fetch_website_content(website_link)
|
| 102 |
-
progress_bar.progress(100)
|
| 103 |
|
| 104 |
if website_content_data:
|
| 105 |
website_df = pd.DataFrame(website_content_data)
|
| 106 |
st.table(website_df)
|
| 107 |
else:
|
| 108 |
st.write("Unable to retrieve website content.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
else:
|
| 110 |
st.write("No results found for this website / company name on Google Maps.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from apify_client import ApifyClient
|
| 4 |
|
| 5 |
# Function to fetch Google Maps info using the updated actor
|
|
|
|
| 18 |
return response.json()
|
| 19 |
|
| 20 |
# Function to fetch website content using the updated actor
|
| 21 |
+
def fetch_website_content(google_maps_url):
|
| 22 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 23 |
+
run_input = {"startUrls": [{"url": google_maps_url}]}
|
| 24 |
run = apify_client.actor("moJRLRc85AitArpNN").call(run_input=run_input)
|
| 25 |
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
| 26 |
return items if items else None
|
|
|
|
| 30 |
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 31 |
run_input = {
|
| 32 |
"startUrls": [{"url": google_maps_url}],
|
| 33 |
+
"maxReviews": 20,
|
| 34 |
"reviewsSort": "newest",
|
| 35 |
"language": "en",
|
| 36 |
"personalData": True,
|
|
|
|
| 54 |
progress_bar.progress(50)
|
| 55 |
|
| 56 |
if google_maps_data:
|
| 57 |
+
# Fetch and Display Website Content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
google_maps_url = google_maps_data.get('url')
|
| 59 |
+
website_content_data = fetch_website_content(google_maps_url)
|
| 60 |
progress_bar.progress(75)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
if website_content_data:
|
| 63 |
website_df = pd.DataFrame(website_content_data)
|
| 64 |
st.table(website_df)
|
| 65 |
else:
|
| 66 |
st.write("Unable to retrieve website content.")
|
| 67 |
+
|
| 68 |
+
# Fetch customer reviews from the new API and display them
|
| 69 |
+
reviews_data = fetch_customer_reviews(google_maps_url)
|
| 70 |
+
reviews_df = pd.DataFrame(reviews_data)[['text']]
|
| 71 |
+
st.subheader("Customer Reviews from New API")
|
| 72 |
+
st.table(reviews_df)
|
| 73 |
else:
|
| 74 |
st.write("No results found for this website / company name on Google Maps.")
|