File size: 3,800 Bytes
3e996d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
import requests

from langchain.utilities import ApifyWrapper
from langchain.document_loaders.base import Document

# Initialize ApifyWrapper and other environment variables
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
os.environ["APIFY_API_TOKEN"] = "Your Apify API token"

APIFY_WEATHER_KEY = "91b23cab82ee530b2052c8757e343b0d"
apify = ApifyWrapper()

def get_website_summary(website_url):
    # For now, return a dummy summary. Replace this with the API logic you have
    return "This is a dummy summary for " + website_url

def get_google_reviews(website_url):
    # Return dummy Google Maps reviews for now.
    # Replace this with the logic to get reviews summary using GPT-3.5 and Google Maps API.
    return {
        "pros": ["Great ambiance", "Friendly staff", "Tasty food"],
        "cons": ["A bit pricey", "Long waiting times on weekends", "Limited parking"]
    }

def get_peak_times(website_url):
    # Dummy data for peak times.
    # Replace this with the logic to fetch peak times using Google Maps API.
    return {
        "Monday": [10, 20, 30, 40, 30, 20, 10],
        "Tuesday": [15, 25, 35, 45, 35, 25, 15],
        # ... add other days
    }

def get_images(website_url):
    # Return dummy image URLs.
    # Replace this with logic to fetch place images using Google Maps API.
    return [
        "https://via.placeholder.com/150",
        "https://via.placeholder.com/150",
        "https://via.placeholder.com/150",
        "https://via.placeholder.com/150",
        "https://via.placeholder.com/150",
    ]

def get_map_widget(website_url):
    # Return dummy map coordinates (for New York City).
    # Replace this with the logic to fetch actual coordinates of the place using its website URL.
    return {
        "lat": 40.730610,
        "lon": -73.935242
    }

def get_weather_data(lat, lon):
    BASE_URL = f"https://api.openweathermap.org/data/3.0/onecall"
    params = {
        "lat": lat,
        "lon": lon,
        "exclude": "hourly,daily,minutely",
        "appid": APIFY_WEATHER_KEY,
        "units": "metric"
    }
    response = requests.get(BASE_URL, params=params)
    if response.status_code == 200:
        return response.json()
    else:
        return None

def process_website(website_url):
    website_summary = get_website_summary(website_url)
    reviews = get_google_reviews(website_url)
    peak_times = get_peak_times(website_url)
    images = get_images(website_url)
    map_widget = get_map_widget(website_url)
    
    weather_data = get_weather_data(map_widget["lat"], map_widget["lon"])
    if weather_data:
        temp = weather_data["current"]["temp"]
        weather_desc = weather_data["current"]["weather"][0]["description"]
        weather_widget = f"It's {temp}°C with {weather_desc}."
    else:
        weather_widget = "Unable to fetch weather data at the moment."
    
    return website_summary, reviews, peak_times, images, map_widget, weather_widget

# Streamlit UI
st.title("Website Information Extractor")

website_url = st.text_input("Enter a website/company name:")

if website_url:
    summary, reviews, peak_times, images, map_data, weather_info = process_website(website_url)

    st.subheader("Website Summary")
    st.write(summary)

    st.subheader("Google Reviews")
    st.write("Pros:")
    for pro in reviews["pros"]:
        st.write(f"- {pro}")

    st.write("Cons:")
    for con in reviews["cons"]:
        st.write(f"- {con}")

    st.subheader("Peak Times")
    for day, times in peak_times.items():
        st.write(f"{day}: {times}")

    st.subheader("Images")
    for image in images:
        st.image(image)

    st.subheader("Location")
    st.map({"lat": map_data["lat"], "lon": map_data["lon"]})

    st.subheader("Current Weather")
    st.write(weather_info)