| | import os |
| | import json |
| | from typing import List, Dict, Any |
| |
|
| | import gradio as gr |
| | from dotenv import load_dotenv |
| |
|
| | from ui.components import build_ui |
| | from rag.ingest import build_corpus |
| | from rag.retriever import RagStore |
| | from services.weather import get_weather_summary |
| | from services.geocoding import geocode_city |
| | from services.planner import generate_plan |
| |
|
| | load_dotenv() |
| |
|
| | INDEX_DIR = "data/index" |
| | CORPUS_DIRS = { |
| | "blogs": "data/blogs", |
| | "reviews": "data/reviews", |
| | "events": "data/events", |
| | } |
| |
|
| | rag_store = RagStore(index_dir=INDEX_DIR) |
| |
|
| | |
| |
|
| | def seed_sample_data() -> str: |
| | from sample_data_seed import seed |
| | n = seed() |
| | return f"Seeded sample data: {n} files." |
| |
|
| | def handle_build_index(progress=gr.Progress(track_tqdm=True)) -> str: |
| | docs = build_corpus(CORPUS_DIRS) |
| | rag_store.build(docs) |
| | return f"Built index with {len(docs)} documents." |
| |
|
| | def handle_generate_plan( |
| | city: str, |
| | hours: float, |
| | traveler: str, |
| | interests: List[str], |
| | budget: str, |
| | pace: str, |
| | date: str, |
| | force_weather: str | None, |
| | mode_pref: str, |
| | show_costs: bool, |
| | ): |
| | if not rag_store.available(): |
| | return None, None, "Index not built yet. Click 'Build/Update RAG Index'." |
| |
|
| | loc = geocode_city(city) |
| | if not loc: |
| | return None, None, f"Failed to geocode: {city}" |
| | lat, lon = loc["lat"], loc["lon"] |
| |
|
| | weather = get_weather_summary(lat, lon, date=date, override=force_weather or None) |
| |
|
| | plan = generate_plan( |
| | rag=rag_store, |
| | center=(lat, lon), |
| | hours=hours, |
| | traveler=traveler, |
| | interests=interests, |
| | budget=budget, |
| | pace=pace, |
| | weather=weather, |
| | date=date, |
| | mode_pref=mode_pref, |
| | include_costs=show_costs, |
| | ) |
| |
|
| | return plan["map_html"], plan["table"], plan["narrative"] |
| |
|
| | with gr.Blocks(css=".small {font-size: 12px}") as demo: |
| | ( |
| | city_in, |
| | hours_in, |
| | traveler_in, |
| | interests_in, |
| | budget_in, |
| | pace_in, |
| | date_in, |
| | weather_in, |
| | mode_in, |
| | show_costs_in, |
| | build_btn, |
| | seed_btn, |
| | gen_btn, |
| | map_out, |
| | table_out, |
| | text_out, |
| | ) = build_ui() |
| |
|
| | seed_btn.click(fn=seed_sample_data, outputs=[text_out]) |
| | build_btn.click(fn=handle_build_index, outputs=[text_out]) |
| | gen_btn.click( |
| | fn=handle_generate_plan, |
| | inputs=[ |
| | city_in, |
| | hours_in, |
| | traveler_in, |
| | interests_in, |
| | budget_in, |
| | pace_in, |
| | date_in, |
| | weather_in, |
| | mode_in, |
| | show_costs_in, |
| | ], |
| | outputs=[map_out, table_out, text_out], |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |
| |
|