Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,12 +17,22 @@ st.set_page_config(
|
|
| 17 |
initial_sidebar_state="expanded"
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# 2. ENHANCED PROFESSIONAL STYLING (Optimized)
|
| 21 |
st.markdown("""
|
| 22 |
<style>
|
| 23 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
|
| 24 |
-
.stApp { background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%); color: #0f172a; font-family: 'Inter', sans-serif; }
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
/* METRIC CARDS */
|
| 27 |
div[data-testid="stMetric"] {
|
| 28 |
background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
|
|
@@ -33,7 +43,7 @@ st.markdown("""
|
|
| 33 |
div[data-testid="stMetricValue"] { color: #0f172a !important; font-weight: 800 !important; font-size: 2rem !important; }
|
| 34 |
div[data-testid="stMetricLabel"] { color: #334155 !important; font-weight: 600 !important; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
|
| 35 |
|
| 36 |
-
/* DATAFRAME */
|
| 37 |
div[data-testid="stDataFrame"] { border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
|
| 38 |
div[data-testid="stDataFrame"] div[role="columnheader"] {
|
| 39 |
background: linear-gradient(to bottom, #f8fafc, #f1f5f9) !important;
|
|
@@ -43,14 +53,37 @@ st.markdown("""
|
|
| 43 |
color: #334155 !important;
|
| 44 |
}
|
| 45 |
|
| 46 |
-
/* SIDEBAR */
|
| 47 |
-
[data-testid="stSidebar"] {
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
/* UI ELEMENTS */
|
| 52 |
h1 { background: linear-gradient(135deg, #0f172a 0%, #334155 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 800 !important; }
|
| 53 |
-
h2, h3 { color: #0f172a !important; }
|
|
|
|
| 54 |
.status-badge { display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 9999px; font-size: 12px; font-weight: 700; text-transform: uppercase; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
|
| 55 |
.bg-red { background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); color: #991b1b; }
|
| 56 |
.bg-green { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); color: #166534; }
|
|
@@ -93,13 +126,38 @@ def fetch_coordinates_batch(unique_locations):
|
|
| 93 |
except json.JSONDecodeError:
|
| 94 |
pass # File corrupted, start fresh
|
| 95 |
|
| 96 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
missing_locs = [loc for loc in unique_locations if loc not in coords_map]
|
| 98 |
|
| 99 |
if not missing_locs:
|
| 100 |
return coords_map
|
| 101 |
|
| 102 |
-
#
|
| 103 |
progress_text = "📡 New locations found. Fetching coordinates..."
|
| 104 |
my_bar = st.progress(0, text=progress_text)
|
| 105 |
|
|
@@ -133,7 +191,7 @@ def fetch_coordinates_batch(unique_locations):
|
|
| 133 |
|
| 134 |
my_bar.empty()
|
| 135 |
|
| 136 |
-
#
|
| 137 |
if updated:
|
| 138 |
# Convert keys to string "District|State" for JSON compatibility
|
| 139 |
save_data = {f"{k[0]}|{k[1]}": v for k, v in coords_map.items()}
|
|
|
|
| 17 |
initial_sidebar_state="expanded"
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# 2. ENHANCED PROFESSIONAL STYLING (Optimized for Visibility)
|
| 21 |
st.markdown("""
|
| 22 |
<style>
|
| 23 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
|
|
|
|
| 24 |
|
| 25 |
+
/* Global Text Visibility Fix */
|
| 26 |
+
.stApp {
|
| 27 |
+
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
|
| 28 |
+
color: #0f172a !important;
|
| 29 |
+
font-family: 'Inter', sans-serif;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
p, span, div, label {
|
| 33 |
+
color: #0f172a;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
/* METRIC CARDS */
|
| 37 |
div[data-testid="stMetric"] {
|
| 38 |
background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
|
|
|
|
| 43 |
div[data-testid="stMetricValue"] { color: #0f172a !important; font-weight: 800 !important; font-size: 2rem !important; }
|
| 44 |
div[data-testid="stMetricLabel"] { color: #334155 !important; font-weight: 600 !important; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
|
| 45 |
|
| 46 |
+
/* DATAFRAME VISIBILITY FIX */
|
| 47 |
div[data-testid="stDataFrame"] { border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
|
| 48 |
div[data-testid="stDataFrame"] div[role="columnheader"] {
|
| 49 |
background: linear-gradient(to bottom, #f8fafc, #f1f5f9) !important;
|
|
|
|
| 53 |
color: #334155 !important;
|
| 54 |
}
|
| 55 |
|
| 56 |
+
/* SIDEBAR VISIBILITY FIXES */
|
| 57 |
+
[data-testid="stSidebar"] {
|
| 58 |
+
background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
|
| 59 |
+
border-right: 1px solid #334155;
|
| 60 |
+
}
|
| 61 |
+
[data-testid="stSidebar"] * {
|
| 62 |
+
color: #f8fafc !important;
|
| 63 |
+
}
|
| 64 |
+
/* Specific Fix for Input Labels inside Sidebar */
|
| 65 |
+
[data-testid="stSidebar"] label, [data-testid="stSidebar"] .stMarkdown p {
|
| 66 |
+
color: #e2e8f0 !important;
|
| 67 |
+
font-weight: 600;
|
| 68 |
+
}
|
| 69 |
+
/* Fix for Date Input Text inside the white box */
|
| 70 |
+
[data-testid="stSidebar"] input {
|
| 71 |
+
color: #0f172a !important;
|
| 72 |
+
}
|
| 73 |
+
/* Fix for Selectbox Text inside the white box */
|
| 74 |
+
[data-testid="stSidebar"] div[data-baseweb="select"] span {
|
| 75 |
+
color: #0f172a !important;
|
| 76 |
+
}
|
| 77 |
+
/* Fix for Link Button */
|
| 78 |
+
[data-testid="stSidebar"] a {
|
| 79 |
+
color: #3b82f6 !important;
|
| 80 |
+
font-weight: 600;
|
| 81 |
+
}
|
| 82 |
|
| 83 |
/* UI ELEMENTS */
|
| 84 |
h1 { background: linear-gradient(135deg, #0f172a 0%, #334155 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 800 !important; }
|
| 85 |
+
h2, h3, h4, h5 { color: #0f172a !important; font-weight: 700 !important; }
|
| 86 |
+
|
| 87 |
.status-badge { display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 9999px; font-size: 12px; font-weight: 700; text-transform: uppercase; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
|
| 88 |
.bg-red { background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); color: #991b1b; }
|
| 89 |
.bg-green { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); color: #166534; }
|
|
|
|
| 126 |
except json.JSONDecodeError:
|
| 127 |
pass # File corrupted, start fresh
|
| 128 |
|
| 129 |
+
# 2. Add Hardcoded Pre-fills (High Priority Redundancy)
|
| 130 |
+
prefills = {
|
| 131 |
+
('Gautam Buddha Nagar', 'Uttar Pradesh'): (28.39, 77.65),
|
| 132 |
+
('West Jaintia Hills', 'Meghalaya'): (25.55, 92.38),
|
| 133 |
+
('West Khasi Hills', 'Meghalaya'): (25.56, 91.29),
|
| 134 |
+
('Bijapur', 'Chhattisgarh'): (18.80, 80.82),
|
| 135 |
+
('Dhule', 'Maharashtra'): (20.90, 74.77),
|
| 136 |
+
('Dhamtari', 'Chhattisgarh'): (20.71, 81.55),
|
| 137 |
+
('Udupi', 'Karnataka'): (13.34, 74.75),
|
| 138 |
+
('Supaul', 'Bihar'): (26.29, 86.82),
|
| 139 |
+
('Puruliya', 'West Bengal'): (23.25, 86.50),
|
| 140 |
+
('Mumbai', 'Maharashtra'): (19.0760, 72.8777),
|
| 141 |
+
('Pune', 'Maharashtra'): (18.5204, 73.8567),
|
| 142 |
+
('Bangalore', 'Karnataka'): (12.9716, 77.5946),
|
| 143 |
+
('Bengaluru', 'Karnataka'): (12.9716, 77.5946),
|
| 144 |
+
('Chennai', 'Tamil Nadu'): (13.0827, 80.2707),
|
| 145 |
+
('Hyderabad', 'Telangana'): (17.3850, 78.4867),
|
| 146 |
+
('Kolkata', 'West Bengal'): (22.5726, 88.3639),
|
| 147 |
+
('Delhi', 'Delhi'): (28.7041, 77.1025),
|
| 148 |
+
('Shimla', 'Himachal Pradesh'): (31.1048, 77.1734)
|
| 149 |
+
}
|
| 150 |
+
for k, v in prefills.items():
|
| 151 |
+
if k not in coords_map:
|
| 152 |
+
coords_map[k] = v
|
| 153 |
+
|
| 154 |
+
# 3. Identify missing locations
|
| 155 |
missing_locs = [loc for loc in unique_locations if loc not in coords_map]
|
| 156 |
|
| 157 |
if not missing_locs:
|
| 158 |
return coords_map
|
| 159 |
|
| 160 |
+
# 4. Dynamic Fetching for missing
|
| 161 |
progress_text = "📡 New locations found. Fetching coordinates..."
|
| 162 |
my_bar = st.progress(0, text=progress_text)
|
| 163 |
|
|
|
|
| 191 |
|
| 192 |
my_bar.empty()
|
| 193 |
|
| 194 |
+
# 5. Save back to JSON if new data fetched
|
| 195 |
if updated:
|
| 196 |
# Convert keys to string "District|State" for JSON compatibility
|
| 197 |
save_data = {f"{k[0]}|{k[1]}": v for k, v in coords_map.items()}
|