Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,12 @@ from api_clients import AVAILABLE_BASEMAPS
|
|
| 16 |
from map_utils import handle_map_type_change
|
| 17 |
from image_utils import load_captured_image, process_fade_with_drop
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# --- UI Helper/Callback Functions (Tightly coupled to the Gradio UI) ---
|
| 20 |
|
| 21 |
def populate_products_tab(products_json: str):
|
|
@@ -92,7 +98,19 @@ with gr.Blocks(theme=dark_theme, title="Anamnesis-GIS", css=APP_CSS, head=APP_HE
|
|
| 92 |
with gr.Group():
|
| 93 |
county_select = gr.Dropdown(label="Select County Lattice", choices=list(COUNTY_CONFIG.keys()), value="Kitsap County (Blueprint)")
|
| 94 |
address_input = gr.Textbox(label="Enter Address or Parcel ID", placeholder=COUNTY_CONFIG["Kitsap County (Blueprint)"]["example_query"])
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
submit_btn = gr.Button("Submit Query", variant="primary")
|
| 97 |
gr.Markdown("### 🗺️ Parcel Map")
|
| 98 |
map_type_radio = gr.Radio(choices=ordered_basemap_choices, value="USGS Topo", label="Map Type", type="value", interactive=True, show_label=False, elem_id="map-type-radio")
|
|
@@ -151,6 +169,7 @@ with gr.Blocks(theme=dark_theme, title="Anamnesis-GIS", css=APP_CSS, head=APP_HE
|
|
| 151 |
map_init_script = gr.Textbox(visible=False, label="Map Initializer Script") # Stores the JS to render/update the map
|
| 152 |
|
| 153 |
with gr.Accordion("Examples", open=False):
|
|
|
|
| 154 |
gr.Examples(examples=[[c, v["example_query"], ""] for c, v in COUNTY_CONFIG.items()], inputs=[county_select, address_input, api_key_input], label=None)
|
| 155 |
|
| 156 |
# --- Event Wiring ---
|
|
|
|
| 16 |
from map_utils import handle_map_type_change
|
| 17 |
from image_utils import load_captured_image, process_fade_with_drop
|
| 18 |
|
| 19 |
+
# --- Hugging Face Secrets Integration ---
|
| 20 |
+
# Attempt to get the Gemini API key from Hugging Face secrets (environment variables)
|
| 21 |
+
# If the secret is set, it will be used; otherwise, it will be None.
|
| 22 |
+
gemini_api_key_from_env = os.environ.get("GEMINI_API_KEY")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
# --- UI Helper/Callback Functions (Tightly coupled to the Gradio UI) ---
|
| 26 |
|
| 27 |
def populate_products_tab(products_json: str):
|
|
|
|
| 98 |
with gr.Group():
|
| 99 |
county_select = gr.Dropdown(label="Select County Lattice", choices=list(COUNTY_CONFIG.keys()), value="Kitsap County (Blueprint)")
|
| 100 |
address_input = gr.Textbox(label="Enter Address or Parcel ID", placeholder=COUNTY_CONFIG["Kitsap County (Blueprint)"]["example_query"])
|
| 101 |
+
|
| 102 |
+
# --- MODIFIED FOR HUGGING FACE SECRETS ---
|
| 103 |
+
# This Textbox will be populated by the environment variable if it exists.
|
| 104 |
+
# It will be hidden if the key is provided by the environment,
|
| 105 |
+
# but will remain visible for local development if the key is not set.
|
| 106 |
+
api_key_input = gr.Textbox(
|
| 107 |
+
label="Gemini API Key (for text report)",
|
| 108 |
+
type="password",
|
| 109 |
+
placeholder="Enter key starting with 'AIza...' or set in HF Secrets",
|
| 110 |
+
value=gemini_api_key_from_env,
|
| 111 |
+
visible=gemini_api_key_from_env is None
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
submit_btn = gr.Button("Submit Query", variant="primary")
|
| 115 |
gr.Markdown("### 🗺️ Parcel Map")
|
| 116 |
map_type_radio = gr.Radio(choices=ordered_basemap_choices, value="USGS Topo", label="Map Type", type="value", interactive=True, show_label=False, elem_id="map-type-radio")
|
|
|
|
| 169 |
map_init_script = gr.Textbox(visible=False, label="Map Initializer Script") # Stores the JS to render/update the map
|
| 170 |
|
| 171 |
with gr.Accordion("Examples", open=False):
|
| 172 |
+
# The example for the API key is now an empty string as it will be handled by the secret
|
| 173 |
gr.Examples(examples=[[c, v["example_query"], ""] for c, v in COUNTY_CONFIG.items()], inputs=[county_select, address_input, api_key_input], label=None)
|
| 174 |
|
| 175 |
# --- Event Wiring ---
|