From 078775dab84d70a5e9a81198d80f4b3965ebc6fd Mon Sep 17 00:00:00 2001 From: Srinivasan Saravanamuthu <131298719+srinivasansaravanamuthu@users.noreply.github.com> Date: Sun, 27 Jul 2025 17:46:37 -0700 Subject: [PATCH] Add airport map scraping interface --- Static/Styles.css | 50 ++++++++++++++++++++++++++++ Templates/Index.html | 65 +++++++++++++++++++++++++++++++++++- app.py | 78 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 185 insertions(+), 8 deletions(-) diff --git a/Static/Styles.css b/Static/Styles.css index 6889bfa..c8c234e 100644 --- a/Static/Styles.css +++ b/Static/Styles.css @@ -124,3 +124,53 @@ button { button:hover { background-color: #45a049; } + +.settings-link { + position: absolute; + top: 10px; + right: 10px; + color: white; + cursor: pointer; +} + +#settings-modal { + display: none; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.5); + justify-content: center; + align-items: center; +} + +#settings-modal .modal-content { + background: white; + padding: 20px; + border-radius: 8px; +} + +.scrape-container { + display: flex; + padding: 10px; + border-top: 1px solid #f0f0f0; +} + +.scrape-container input[type="text"] { + flex: 1; + padding: 10px; + border: 1px solid #ccc; + border-radius: 4px; +} + +.scrape-container button { + margin-left: 5px; +} + +#geojson-list { + padding: 10px; + border-top: 1px solid #f0f0f0; + max-height: 150px; + overflow-y: auto; +} diff --git a/Templates/Index.html b/Templates/Index.html index ba9000a..33e1dd8 100644 --- a/Templates/Index.html +++ b/Templates/Index.html @@ -3,7 +3,7 @@ - MapsPeople Customer Service Chatbot + Airport Map Scraper @@ -13,6 +13,7 @@

At your Service

+
Hello! I can help you with troubleshooting MapsPeople SDK. What is your query?
@@ -25,6 +26,20 @@

At your Service

+
+ + + +
+
+
+ +
+
diff --git a/app.py b/app.py index fa2d89e..a177de3 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,14 @@ from flask import Flask, render_template, request, jsonify import openai import os +import requests +from urllib.parse import urljoin +from bs4 import BeautifulSoup app = Flask(__name__) -# Configure OpenAI API key -openai.api_key = 'YOUR_OPENAI_API_KEY' +# Configure OpenAI API key. Can be overridden from the settings dialog +openai.api_key = os.environ.get("OPENAI_API_KEY", "") @app.route('/') def index(): @@ -17,16 +20,77 @@ def chat(): # Call OpenAI API to get a response try: - response = openai.Completion.create( - engine="davinci-codex", - prompt=user_message, - max_tokens=150 + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": user_message}], + max_tokens=150, ) - response_text = response.choices[0].text.strip() + response_text = response.choices[0].message["content"].strip() except Exception as e: response_text = "Sorry, I'm having trouble responding right now. Please try again later." return jsonify({"response": response_text}) + +def scrape_geojson(url): + """Return a list of GeoJSON links and descriptions from the provided URL.""" + try: + resp = requests.get(url, timeout=10) + resp.raise_for_status() + except Exception: + return [] + + soup = BeautifulSoup(resp.text, "html.parser") + results = [] + for tag in soup.find_all(["a", "script", "link"]): + for attr in ["href", "src", "data-src"]: + link = tag.get(attr) + if not link: + continue + if link.lower().endswith(".geojson") or link.lower().endswith(".json"): + full_url = urljoin(url, link) + desc = tag.get("title") or tag.get("alt") or tag.get("aria-label") or tag.text.strip() + results.append({"url": full_url, "description": desc}) + return results + + +@app.route("/scrape", methods=["POST"]) +def scrape(): + data = request.get_json() + target_url = data.get("url") + api_key = data.get("api_key") + if api_key: + openai.api_key = api_key + files = scrape_geojson(target_url) + if not files: + return jsonify({"success": False, "files": []}) + return jsonify({"success": True, "files": files}) + + +@app.route("/recheck", methods=["POST"]) +def recheck(): + data = request.get_json() + files = data.get("files", []) + target_url = data.get("url") + api_key = data.get("api_key") + if api_key: + openai.api_key = api_key + prompt = ( + "We scraped the following GeoJSON links from {url}:\n{files}\n" + "Did we capture all geospatial data? Provide a short critique.".format( + url=target_url, files="\n".join(f["url"] for f in files) + ) + ) + try: + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": prompt}], + max_tokens=150, + ) + critique = response.choices[0].message["content"].strip() + except Exception: + critique = "Unable to verify with ChatGPT at this time." + return jsonify({"critique": critique}) + if __name__ == '__main__': app.run(debug=True)