Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,75 +1,43 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
from apify_client import ApifyClient
|
5 |
import requests
|
6 |
|
7 |
-
# Function to fetch
|
8 |
-
def
|
9 |
-
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
10 |
-
run_input = {"searchStringsArray": [website_name]}
|
11 |
-
run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)
|
12 |
-
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
13 |
-
return items[0] if items else None
|
14 |
-
|
15 |
-
# Function to fetch weather info
|
16 |
-
def fetch_weather_info(lat, lon):
|
17 |
-
API_KEY = "91b23cab82ee530b2052c8757e343b0d"
|
18 |
-
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
|
19 |
response = requests.get(url)
|
20 |
return response.json()
|
21 |
|
22 |
# Streamlit app
|
23 |
st.title("Data Visualization")
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
if day_data:
|
52 |
-
hours = [entry['hour'] for entry in day_data]
|
53 |
-
occupancy = [entry['occupancyPercent'] for entry in day_data]
|
54 |
-
st.write(day)
|
55 |
-
st.bar_chart(pd.Series(occupancy, index=hours), use_container_width=True)
|
56 |
-
|
57 |
-
# Review Count and Distribution
|
58 |
-
st.subheader("Review Count and Distribution")
|
59 |
-
st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
|
60 |
-
review_distribution = google_maps_data['reviewsDistribution']
|
61 |
-
days_order = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
|
62 |
-
ordered_distribution = {day: review_distribution.get(day, 0) for day in days_order}
|
63 |
-
st.bar_chart(pd.Series(ordered_distribution), use_container_width=True)
|
64 |
-
|
65 |
-
# Reviews Table
|
66 |
-
st.subheader("Customer Reviews")
|
67 |
-
reviews = google_maps_data.get('reviews', [])
|
68 |
-
if reviews:
|
69 |
-
review_df = pd.DataFrame(reviews)
|
70 |
-
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
|
71 |
-
else:
|
72 |
-
st.write("No reviews available.")
|
73 |
-
|
74 |
else:
|
75 |
-
st.write("No
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
4 |
import requests
|
5 |
|
6 |
+
# Function to fetch data from the Apify actor
|
7 |
+
def fetch_data_from_apify_actor(url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
response = requests.get(url)
|
9 |
return response.json()
|
10 |
|
11 |
# Streamlit app
|
12 |
st.title("Data Visualization")
|
13 |
|
14 |
+
# Fetch data using Apify actor
|
15 |
+
apify_actor_url = "https://api.apify.com/v2/actor-runs/HsejBCDbeF39qAgsa?token=apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp"
|
16 |
+
data = fetch_data_from_apify_actor(apify_actor_url)
|
17 |
+
google_maps_data = data.get('output', {}).get('data', {})
|
18 |
+
|
19 |
+
if google_maps_data:
|
20 |
+
# Display website link in a specific output box
|
21 |
+
website_link = google_maps_data.get('website')
|
22 |
+
st.text_area("Website Link:", website_link)
|
23 |
+
|
24 |
+
# Occupancy Data: Aggregate and rank
|
25 |
+
st.subheader("Occupancy Data (Aggregated by Day)")
|
26 |
+
occupancy_data = google_maps_data.get('popularTimesHistogram', {})
|
27 |
+
avg_occupancy = {}
|
28 |
+
for day, day_data in occupancy_data.items():
|
29 |
+
if day_data:
|
30 |
+
avg_occupancy[day] = np.mean([entry['occupancyPercent'] for entry in day_data])
|
31 |
+
days_order = sorted(avg_occupancy, key=avg_occupancy.get, reverse=True)
|
32 |
+
st.bar_chart(pd.Series({day: avg_occupancy[day] for day in days_order}), use_container_width=True)
|
33 |
+
|
34 |
+
# Reviews Table
|
35 |
+
st.subheader("Customer Reviews")
|
36 |
+
reviews = google_maps_data.get('reviews', [])
|
37 |
+
if reviews:
|
38 |
+
review_df = pd.DataFrame(reviews)
|
39 |
+
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
else:
|
41 |
+
st.write("No reviews available.")
|
42 |
+
else:
|
43 |
+
st.write("No results found.")
|