Spaces:
Sleeping
Sleeping
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) |