antfraia commited on
Commit
ba1946b
·
1 Parent(s): 3e996d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -91
app.py CHANGED
@@ -1,55 +1,25 @@
1
  import streamlit as st
2
- import requests
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
- def get_website_summary(website_url):
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 get_google_reviews(website_url):
19
- # Return dummy Google Maps reviews for now.
20
- # Replace this with the logic to get reviews summary using GPT-3.5 and Google Maps API.
21
- return {
22
- "pros": ["Great ambiance", "Friendly staff", "Tasty food"],
23
- "cons": ["A bit pricey", "Long waiting times on weekends", "Limited parking"]
24
  }
25
 
26
- def get_peak_times(website_url):
27
- # Dummy data for peak times.
28
- # Replace this with the logic to fetch peak times using Google Maps API.
29
- return {
30
- "Monday": [10, 20, 30, 40, 30, 20, 10],
31
- "Tuesday": [15, 25, 35, 45, 35, 25, 15],
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
- website_url = st.text_input("Enter a website/company name:")
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
- st.subheader("Peak Times")
107
- for day, times in peak_times.items():
108
- st.write(f"{day}: {times}")
109
-
110
- st.subheader("Images")
111
- for image in images:
112
- st.image(image)
113
-
114
- st.subheader("Location")
115
- st.map({"lat": map_data["lat"], "lon": map_data["lon"]})
116
-
117
- st.subheader("Current Weather")
118
- st.write(weather_info)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")