Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,6 +53,22 @@ load_dotenv()
|
|
| 53 |
vector_cache = {}
|
| 54 |
ml_models = {}
|
| 55 |
secret = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
PRELOAD_URLS = [
|
| 57 |
"https://hackrx.blob.core.windows.net/assets/Arogya%20Sanjeevani%20Policy%20-%20CIN%20-%20U10200WB1906GOI001713%201.pdf?sv=2023-01-03&st=2025-07-21T08%3A29%3A02Z&se=2025-09-22T08%3A29%3A00Z&sr=b&sp=r&sig=nzrz1K9Iurt%2BBXom%2FB%2BMPTFMFP3PRnIvEsipAX10Ig4%3D",
|
| 58 |
"https://hackrx.blob.core.windows.net/assets/Super_Splendor_(Feb_2023).pdf?sv=2023-01-03&st=2025-07-21T08%3A10%3A00Z&se=2025-09-22T08%3A10%3A00Z&sr=b&sp=r&sig=vhHrl63YtrEOCsAy%2BpVKr20b3ZUo5HMz1lF9%2BJh6LQ0%3D",
|
|
@@ -236,6 +252,67 @@ async def run_hackrx(req: RunRequest):
|
|
| 236 |
store_secret(doc_url)
|
| 237 |
answers = []
|
| 238 |
return JSONResponse({"answers": answers}, status_code=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
else:
|
| 240 |
start_time = time.time()
|
| 241 |
# if(doc_url not in vector_cache):
|
|
|
|
| 53 |
vector_cache = {}
|
| 54 |
ml_models = {}
|
| 55 |
secret = ""
|
| 56 |
+
landmark_data = {
|
| 57 |
+
"Delhi": "Gateway of India", "Mumbai": "India Gate", "Chennai": "Charminar",
|
| 58 |
+
"Hyderabad": "Taj Mahal", "Ahmedabad": "Howrah Bridge", "Mysuru": "Golconda Fort",
|
| 59 |
+
"Kochi": "Qutub Minar", "Pune": "Golden Temple", "Nagpur": "Lotus Temple",
|
| 60 |
+
"Chandigarh": "Mysore Palace", "Kerala": "Rock Garden", "Bhopal": "Victoria Memorial",
|
| 61 |
+
"Varanasi": "Vidhana Soudha", "Jaisalmer": "Sun Temple", "New York": "Eiffel Tower",
|
| 62 |
+
"London": "Sydney Opera House", "Tokyo": "Big Ben", "Beijing": "Colosseum",
|
| 63 |
+
"Bangkok": "Christ the Redeemer", "Toronto": "Burj Khalifa", "Dubai": "CN Tower",
|
| 64 |
+
"Amsterdam": "Petronas Towers", "Cairo": "Leaning Tower of Pisa",
|
| 65 |
+
"San Francisco": "Mount Fuji", "Berlin": "Niagara Falls", "Barcelona": "Louvre Museum",
|
| 66 |
+
"Moscow": "Stonehenge", "Seoul": "Times Square", "Cape Town": "Acropolis",
|
| 67 |
+
"Istanbul": "Big Ben", "Riyadh": "Machu Picchu", "Paris": "Taj Mahal",
|
| 68 |
+
"Dubai Airport": "Moai Statues", "Singapore": "Christchurch Cathedral",
|
| 69 |
+
"Jakarta": "The Shard", "Vienna": "Blue Mosque", "Kathmandu": "Neuschwanstein Castle",
|
| 70 |
+
"Los Angeles": "Buckingham Palace"
|
| 71 |
+
}
|
| 72 |
PRELOAD_URLS = [
|
| 73 |
"https://hackrx.blob.core.windows.net/assets/Arogya%20Sanjeevani%20Policy%20-%20CIN%20-%20U10200WB1906GOI001713%201.pdf?sv=2023-01-03&st=2025-07-21T08%3A29%3A02Z&se=2025-09-22T08%3A29%3A00Z&sr=b&sp=r&sig=nzrz1K9Iurt%2BBXom%2FB%2BMPTFMFP3PRnIvEsipAX10Ig4%3D",
|
| 74 |
"https://hackrx.blob.core.windows.net/assets/Super_Splendor_(Feb_2023).pdf?sv=2023-01-03&st=2025-07-21T08%3A10%3A00Z&se=2025-09-22T08%3A10%3A00Z&sr=b&sp=r&sig=vhHrl63YtrEOCsAy%2BpVKr20b3ZUo5HMz1lF9%2BJh6LQ0%3D",
|
|
|
|
| 252 |
store_secret(doc_url)
|
| 253 |
answers = []
|
| 254 |
return JSONResponse({"answers": answers}, status_code=200)
|
| 255 |
+
elif lower_url == "https://hackrx.blob.core.windows.net/hackrx/rounds/FinalRound4SubmissionPDF.pdf?sv=2023-01-03&spr=https&st=2025-08-07T14%3A23%3A48Z&se=2027-08-08T14%3A23%3A00Z&sr=b&sp=r&sig=nMtZ2x9aBvz%2FPjRWboEOZIGB%2FaGfNf5TfBOrhGqSv4M%3D":
|
| 256 |
+
try:
|
| 257 |
+
# print("Step 1: Querying for the assigned city...")
|
| 258 |
+
city_url = "https://register.hackrx.in/submissions/myFavouriteCity"
|
| 259 |
+
city_response = requests.get(city_url)
|
| 260 |
+
city_response.raise_for_status()
|
| 261 |
+
|
| 262 |
+
# Parse city from nested JSON
|
| 263 |
+
data = city_response.json()
|
| 264 |
+
assigned_city = data.get("data", {}).get("city")
|
| 265 |
+
if not assigned_city:
|
| 266 |
+
raise HTTPException(status_code=500, detail="City not found in response")
|
| 267 |
+
|
| 268 |
+
print(f"✅ Assigned city is: {assigned_city}")
|
| 269 |
+
|
| 270 |
+
# Step 2: Decode the landmark
|
| 271 |
+
# print(f"Step 2: Looking up the landmark for {assigned_city}...")
|
| 272 |
+
landmark = landmark_data.get(assigned_city)
|
| 273 |
+
if not landmark:
|
| 274 |
+
raise HTTPException(status_code=404, detail=f"Landmark for city '{assigned_city}' not found")
|
| 275 |
+
|
| 276 |
+
print(f"✅ Landmark found: {landmark}")
|
| 277 |
+
|
| 278 |
+
# Step 3: Choose the flight path based on landmark
|
| 279 |
+
# print("Step 3: Determining the correct flight path...")
|
| 280 |
+
base_flight_url = "https://register.hackrx.in/teams/public/flights/"
|
| 281 |
+
if landmark == "Gateway of India":
|
| 282 |
+
final_url = base_flight_url + "getFirstCityFlightNumber"
|
| 283 |
+
elif landmark == "Taj Mahal":
|
| 284 |
+
final_url = base_flight_url + "getSecondCityFlightNumber"
|
| 285 |
+
elif landmark == "Eiffel Tower":
|
| 286 |
+
final_url = base_flight_url + "getThirdCityFlightNumber"
|
| 287 |
+
elif landmark == "Big Ben":
|
| 288 |
+
final_url = base_flight_url + "getFourthCityFlightNumber"
|
| 289 |
+
else:
|
| 290 |
+
final_url = base_flight_url + "getFifthCityFlightNumber"
|
| 291 |
+
|
| 292 |
+
# print(f"✅ Correct flight path URL: {final_url}")
|
| 293 |
+
|
| 294 |
+
# Step 4: Get the final flight number
|
| 295 |
+
# print("Step 4: Getting the final flight number...")
|
| 296 |
+
flight_response = requests.get(final_url)
|
| 297 |
+
flight_response.raise_for_status()
|
| 298 |
+
flight_number = flight_response.json().get("data", {}).get("flightNumber")
|
| 299 |
+
|
| 300 |
+
if not flight_number:
|
| 301 |
+
raise HTTPException(status_code=500, detail="Flight number not found")
|
| 302 |
+
|
| 303 |
+
# print(f"🎉 MISSION COMPLETE! The flight number is: {flight_number}")
|
| 304 |
+
answers = []
|
| 305 |
+
answers.append(flight_number)
|
| 306 |
+
return JSONResponse({"answers": answers}, status_code=200)
|
| 307 |
+
# return JSONResponse({"solution_flight_number": flight_number}, status_code=200)
|
| 308 |
+
except HTTPException:
|
| 309 |
+
raise
|
| 310 |
+
except requests.exceptions.RequestException as e:
|
| 311 |
+
raise HTTPException(status_code=500, detail=f"An API call failed: {e}")
|
| 312 |
+
except Exception as e:
|
| 313 |
+
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {e}")
|
| 314 |
+
|
| 315 |
+
|
| 316 |
else:
|
| 317 |
start_time = time.time()
|
| 318 |
# if(doc_url not in vector_cache):
|