Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
from langchain.utilities import ApifyWrapper
|
5 |
-
from langchain.document_loaders.base import Document
|
6 |
-
|
7 |
-
# Initialize ApifyWrapper and other environment variables
|
8 |
-
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
|
9 |
-
os.environ["APIFY_API_TOKEN"] = "Your Apify API token"
|
10 |
|
|
|
11 |
APIFY_WEATHER_KEY = "91b23cab82ee530b2052c8757e343b0d"
|
12 |
-
apify = ApifyWrapper()
|
13 |
|
14 |
-
|
15 |
-
# For now, return a dummy summary. Replace this with the API logic you have
|
16 |
-
return "This is a dummy summary for " + website_url
|
17 |
|
18 |
-
def
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
"
|
23 |
-
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# ... add other days
|
33 |
-
}
|
34 |
-
|
35 |
-
def get_images(website_url):
|
36 |
-
# Return dummy image URLs.
|
37 |
-
# Replace this with logic to fetch place images using Google Maps API.
|
38 |
-
return [
|
39 |
-
"https://via.placeholder.com/150",
|
40 |
-
"https://via.placeholder.com/150",
|
41 |
-
"https://via.placeholder.com/150",
|
42 |
-
"https://via.placeholder.com/150",
|
43 |
-
"https://via.placeholder.com/150",
|
44 |
-
]
|
45 |
-
|
46 |
-
def get_map_widget(website_url):
|
47 |
-
# Return dummy map coordinates (for New York City).
|
48 |
-
# Replace this with the logic to fetch actual coordinates of the place using its website URL.
|
49 |
-
return {
|
50 |
-
"lat": 40.730610,
|
51 |
-
"lon": -73.935242
|
52 |
-
}
|
53 |
|
54 |
def get_weather_data(lat, lon):
|
55 |
BASE_URL = f"https://api.openweathermap.org/data/3.0/onecall"
|
@@ -66,53 +36,42 @@ def get_weather_data(lat, lon):
|
|
66 |
else:
|
67 |
return None
|
68 |
|
69 |
-
def process_website(website_url):
|
70 |
-
website_summary = get_website_summary(website_url)
|
71 |
-
reviews = get_google_reviews(website_url)
|
72 |
-
peak_times = get_peak_times(website_url)
|
73 |
-
images = get_images(website_url)
|
74 |
-
map_widget = get_map_widget(website_url)
|
75 |
-
|
76 |
-
weather_data = get_weather_data(map_widget["lat"], map_widget["lon"])
|
77 |
-
if weather_data:
|
78 |
-
temp = weather_data["current"]["temp"]
|
79 |
-
weather_desc = weather_data["current"]["weather"][0]["description"]
|
80 |
-
weather_widget = f"It's {temp}°C with {weather_desc}."
|
81 |
-
else:
|
82 |
-
weather_widget = "Unable to fetch weather data at the moment."
|
83 |
-
|
84 |
-
return website_summary, reviews, peak_times, images, map_widget, weather_widget
|
85 |
-
|
86 |
# Streamlit UI
|
87 |
st.title("Website Information Extractor")
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
if website_url:
|
92 |
-
summary, reviews, peak_times, images, map_data, weather_info = process_website(website_url)
|
93 |
-
|
94 |
-
st.subheader("Website Summary")
|
95 |
-
st.write(summary)
|
96 |
-
|
97 |
-
st.subheader("Google Reviews")
|
98 |
-
st.write("Pros:")
|
99 |
-
for pro in reviews["pros"]:
|
100 |
-
st.write(f"- {pro}")
|
101 |
-
|
102 |
-
st.write("Cons:")
|
103 |
-
for con in reviews["cons"]:
|
104 |
-
st.write(f"- {con}")
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
st.
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from apify_client import ApifyClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
APIFY_API_TOKEN = "apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp"
|
5 |
APIFY_WEATHER_KEY = "91b23cab82ee530b2052c8757e343b0d"
|
|
|
6 |
|
7 |
+
client = ApifyClient(APIFY_API_TOKEN)
|
|
|
|
|
8 |
|
9 |
+
def fetch_places_from_google_maps(website_name, location):
|
10 |
+
run_input = {
|
11 |
+
"searchStringsArray": [website_name],
|
12 |
+
"locationQuery": location,
|
13 |
+
"maxCrawledPlacesPerSearch": 1, # Fetching only one record for simplicity
|
14 |
+
# Other input parameters can be added as per your requirements
|
15 |
}
|
16 |
|
17 |
+
run = client.actor("mc9KJTQJg3zfQpANg/nwua9Gu5YrADL7ZDj").call(run_input=run_input)
|
18 |
+
|
19 |
+
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
|
20 |
+
if items:
|
21 |
+
return items[0]
|
22 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def get_weather_data(lat, lon):
|
25 |
BASE_URL = f"https://api.openweathermap.org/data/3.0/onecall"
|
|
|
36 |
else:
|
37 |
return None
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Streamlit UI
|
40 |
st.title("Website Information Extractor")
|
41 |
|
42 |
+
website_name = st.text_input("Enter a website/company name:")
|
43 |
+
location = st.text_input("Enter location (e.g., New York, USA):")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
if website_name and location:
|
46 |
+
place_data = fetch_places_from_google_maps(website_name, location)
|
47 |
+
|
48 |
+
if place_data:
|
49 |
+
st.subheader("Place Details")
|
50 |
+
st.write(f"Name: {place_data.get('name')}")
|
51 |
+
st.write(f"Address: {place_data.get('address')}")
|
52 |
+
st.write(f"Rating: {place_data.get('rating')}")
|
53 |
+
|
54 |
+
# Display reviews if available
|
55 |
+
if 'reviews' in place_data and place_data['reviews']:
|
56 |
+
st.subheader("Reviews")
|
57 |
+
for review in place_data['reviews']:
|
58 |
+
st.write(f"Reviewer: {review.get('reviewerName', 'N/A')}")
|
59 |
+
st.write(f"Review: {review.get('text', 'N/A')}")
|
60 |
+
|
61 |
+
# Display images if available
|
62 |
+
if 'imageUrls' in place_data and place_data['imageUrls']:
|
63 |
+
st.subheader("Images")
|
64 |
+
for image_url in place_data['imageUrls']:
|
65 |
+
st.image(image_url)
|
66 |
+
|
67 |
+
lat, lon = place_data.get("location", {}).get("lat"), place_data.get("location", {}).get("lng")
|
68 |
+
|
69 |
+
if lat and lon:
|
70 |
+
weather_data = get_weather_data(lat, lon)
|
71 |
+
if weather_data:
|
72 |
+
temp = weather_data["current"]["temp"]
|
73 |
+
weather_desc = weather_data["current"]["weather"][0]["description"]
|
74 |
+
st.subheader("Current Weather")
|
75 |
+
st.write(f"It's {temp}°C with {weather_desc}.")
|
76 |
+
else:
|
77 |
+
st.write("Couldn't fetch details for the provided input. Please try again.")
|