import os import base64 import requests import gradio as gr import pandas as pd import folium from src.gpx_parser import parse_gpx_file, haversine, save_enhanced_gpx import src.llm as llm import src.rag as rag # Initialize cache and temp folders os.makedirs("./temp", exist_ok=True) # Preloaded route path PRELOADED_ROUTE_PATH = r"C:\Users\skushwaha\Documents\hckthn\TrailHead\Routes\track_5-14724236830.gpx" MAP_HTML_INITIALIZER = """
""" EMERGENCY_CARD = """ ## 🚨 IMMEDIATE BACKCOUNTRY EMERGENCY CARD (OFFLINE) If you encounter a medical crisis with no cellular signal, follow these basic steps: 1. **Severe Bleeding:** Apply direct pressure with clean dressing. Elevate limb. Use tourniquet if blood is spurting. 2. **Hypothermia:** Wrap in windproof shell/sleeping bag. Replace wet clothes. Provide warm sweet drinks. 3. **Heat Stroke:** Move to shade. Actively cool by wetting skin and fanning. Sip cool water. 4. **Altitude Illness (AMS/HAPE/HACE):** Descend immediately. Do not ascend. Administer oxygen if available. 5. **Ankle Sprain (R.I.C.E):** Rest the joint. Ice or apply cold pack. Compress with elastic bandage. Elevate limb. *Disclaimer: This guide is for offline reference only. Always carry a PLB/satellite communicator on remote trails.* """ def generate_folium_map(points, checkpoints, pois, hiker_pos=None): """ Generate interactive folium map rendering track, checkpoints, POIs, and current hiker pos. """ if not points: m = folium.Map(location=[46.0734974, 11.1717214], zoom_start=13) return m._repr_html_() # Center map on current hiker position or middle of track if hiker_pos: center_lat, center_lon = hiker_pos["lat"], hiker_pos["lon"] zoom_val = 15 else: mid_idx = len(points) // 2 center_lat, center_lon = points[mid_idx]["lat"], points[mid_idx]["lon"] zoom_val = 14 m = folium.Map(location=[center_lat, center_lon], zoom_start=zoom_val) # Draw track polyline locations = [(p["lat"], p["lon"]) for p in points] folium.PolyLine(locations, color="#f59e0b", weight=5, opacity=0.85).add_to(m) # Draw checkpoints for cp in checkpoints: name = cp["name"] lat = cp["lat"] lon = cp["lon"] ele = cp["ele"] dist = cp["cum_dist"] if name == "Start": color = "green" icon = "play" elif name == "End": color = "red" icon = "flag" else: color = "cadetblue" icon = "info-sign" popup_text = f"""