Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import requests | |
# Function to fetch data from the Apify actor | |
def fetch_data_from_apify_actor(url): | |
response = requests.get(url) | |
return response.json() | |
# Streamlit app | |
st.title("Data Visualization") | |
# Fetch data using Apify actor | |
apify_actor_url = "https://api.apify.com/v2/actor-runs/HsejBCDbeF39qAgsa?token=apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp" | |
data = fetch_data_from_apify_actor(apify_actor_url) | |
google_maps_data = data.get('output', {}).get('data', {}) | |
if google_maps_data: | |
# Display website link in a specific output box | |
website_link = google_maps_data.get('website') | |
st.text_area("Website Link:", website_link) | |
# Occupancy Data: Aggregate and rank | |
st.subheader("Occupancy Data (Aggregated by Day)") | |
occupancy_data = google_maps_data.get('popularTimesHistogram', {}) | |
avg_occupancy = {} | |
for day, day_data in occupancy_data.items(): | |
if day_data: | |
avg_occupancy[day] = np.mean([entry['occupancyPercent'] for entry in day_data]) | |
days_order = sorted(avg_occupancy, key=avg_occupancy.get, reverse=True) | |
st.bar_chart(pd.Series({day: avg_occupancy[day] for day in days_order}), use_container_width=True) | |
# Reviews Table | |
st.subheader("Customer Reviews") | |
reviews = google_maps_data.get('reviews', []) | |
if reviews: | |
review_df = pd.DataFrame(reviews) | |
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']]) | |
else: | |
st.write("No reviews available.") | |
else: | |
st.write("No results found.") |