feat: initial make-space full-stack release with weighted multi-provider LLM and Dockerfile
This commit is contained in:
commit
37b323c9ac
55 files changed
+17087
No files matched your search
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "domain"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
@@ -0,0 +1,174 @@
|
||||
//! Layout JSON: the central artifact rendered by three.js.
|
||||
//!
|
||||
//! Coordinate system per floor (meters): origin at the south-west corner,
|
||||
//! `x` grows east (0..width_m), `y` grows north (0..depth_m).
|
||||
//! The street/entrance side is conventionally south.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Layout {
|
||||
pub place_id: String,
|
||||
pub generated_at: String,
|
||||
pub model: String,
|
||||
pub confidence: f32,
|
||||
pub floors: Vec<Floor>,
|
||||
pub summary: Summary,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Floor {
|
||||
pub level: i32,
|
||||
pub label: String,
|
||||
pub confidence: f32,
|
||||
pub width_m: f32,
|
||||
pub depth_m: f32,
|
||||
pub openings: Vec<Opening>,
|
||||
pub zones: Vec<Zone>,
|
||||
pub verticals: Vec<Vertical>,
|
||||
pub notes: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Wall {
|
||||
North,
|
||||
South,
|
||||
East,
|
||||
West,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum OpeningKind {
|
||||
Entrance,
|
||||
Window,
|
||||
Door,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Opening {
|
||||
pub kind: OpeningKind,
|
||||
pub wall: Wall,
|
||||
/// Distance from the wall's start (west end for N/S walls, south end for E/W walls).
|
||||
pub offset_m: f32,
|
||||
pub length_m: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ZoneKind {
|
||||
Seating,
|
||||
Counter,
|
||||
Bar,
|
||||
Kitchen,
|
||||
Restroom,
|
||||
Terrace,
|
||||
Entrance,
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Zone {
|
||||
pub kind: ZoneKind,
|
||||
pub label: String,
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub w: f32,
|
||||
pub d: f32,
|
||||
pub furniture: Vec<FurnitureGroup>,
|
||||
pub evidence_photos: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FurnitureKind {
|
||||
Table2,
|
||||
Table4,
|
||||
Table6,
|
||||
CommunalTable,
|
||||
BarSeat,
|
||||
Sofa,
|
||||
CounterBar,
|
||||
Plant,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Arrangement {
|
||||
Grid,
|
||||
AlongWall,
|
||||
Row,
|
||||
Cluster,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FurnitureGroup {
|
||||
pub kind: FurnitureKind,
|
||||
pub count: u32,
|
||||
pub arrangement: Arrangement,
|
||||
pub along_wall: Option<Wall>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum VerticalKind {
|
||||
Stairs,
|
||||
Elevator,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Vertical {
|
||||
pub kind: VerticalKind,
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub w: f32,
|
||||
pub d: f32,
|
||||
pub to_level: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Tri {
|
||||
Yes,
|
||||
Likely,
|
||||
No,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Tri {
|
||||
pub fn label(&self) -> &'static str {
|
||||
match self {
|
||||
Tri::Yes => "있음",
|
||||
Tri::Likely => "있을 가능성 높음",
|
||||
Tri::No => "없음",
|
||||
Tri::Unknown => "확인 안 됨",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Accessibility {
|
||||
pub elevator: Tri,
|
||||
pub step_free_entrance: Tri,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Summary {
|
||||
pub area_pyeong_min: f32,
|
||||
pub area_pyeong_max: f32,
|
||||
pub seat_estimate: u32,
|
||||
pub seat_types: Vec<String>,
|
||||
pub highlights: Vec<String>,
|
||||
pub accessibility: Accessibility,
|
||||
pub caveats: Vec<String>,
|
||||
}
|
||||
|
||||
/// Everything the place page needs in one round-trip.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PlaceView {
|
||||
pub place: crate::Place,
|
||||
pub layout: Option<Layout>,
|
||||
pub photos: Vec<crate::PhotoSummary>,
|
||||
pub running_job: Option<String>,
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//! Shared domain types. Compiles for both native (server) and wasm32 (hydrate),
|
||||
//! so keep dependencies limited to `serde`.
|
||||
|
||||
mod layout;
|
||||
mod photo;
|
||||
mod place;
|
||||
|
||||
pub use layout::*;
|
||||
pub use photo::*;
|
||||
pub use place::*;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Progress events streamed to the browser over SSE while a place is analyzed.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum JobEvent {
|
||||
Started { place_id: String },
|
||||
PlaceResolved { name: String, naver_place_id: Option<String> },
|
||||
SourceDone { source: PhotoSourceId, photos: usize, texts: usize, error: Option<String> },
|
||||
PhotosStored { stored: usize, duplicates: usize, failed: usize },
|
||||
Classified { interior: usize, exterior: usize, food: usize, other: usize },
|
||||
FloorsDetected { floors: Vec<FloorEvidence> },
|
||||
LayoutDraft { attempt: u32 },
|
||||
Log { message: String },
|
||||
Done { place_id: String },
|
||||
Error { message: String },
|
||||
}
|
||||
|
||||
impl JobEvent {
|
||||
pub fn is_terminal(&self) -> bool {
|
||||
matches!(self, JobEvent::Done { .. } | JobEvent::Error { .. })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum JobStatus {
|
||||
Running,
|
||||
Done,
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// Aggregated evidence that a given floor exists.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FloorEvidence {
|
||||
/// 1 = ground floor, 2 = second floor, -1 = B1, 99 = rooftop.
|
||||
pub level: i32,
|
||||
pub label: String,
|
||||
pub score: f32,
|
||||
pub photo_ids: Vec<String>,
|
||||
pub text_snippets: Vec<String>,
|
||||
}
|
||||
|
||||
pub const ROOFTOP_LEVEL: i32 = 99;
|
||||
|
||||
pub fn floor_label(level: i32) -> String {
|
||||
match level {
|
||||
ROOFTOP_LEVEL => "루프탑".to_string(),
|
||||
l if l < 0 => format!("B{}", -l),
|
||||
l => format!("{l}F"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PhotoSourceId {
|
||||
NaverPlace,
|
||||
NaverBlog,
|
||||
KakaoPlace,
|
||||
GoogleMaps,
|
||||
Instagram,
|
||||
User,
|
||||
}
|
||||
|
||||
impl PhotoSourceId {
|
||||
pub fn label(&self) -> &'static str {
|
||||
match self {
|
||||
Self::NaverPlace => "네이버 플레이스",
|
||||
Self::NaverBlog => "네이버 블로그",
|
||||
Self::KakaoPlace => "카카오맵",
|
||||
Self::GoogleMaps => "구글 지도",
|
||||
Self::Instagram => "인스타그램",
|
||||
Self::User => "사용자 업로드",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A photo reference returned by a source before download.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct RawPhoto {
|
||||
pub source: PhotoSourceId,
|
||||
/// Direct image URL.
|
||||
pub image_url: String,
|
||||
/// Page where the image was found (for attribution).
|
||||
pub page_url: String,
|
||||
/// Text directly associated with the image (alt, caption, nearby paragraph).
|
||||
pub caption: String,
|
||||
/// Referer header required by some CDNs (e.g. postfiles.pstatic.net).
|
||||
pub referer: Option<String>,
|
||||
}
|
||||
|
||||
/// Free text found by a source (blog body, place description, reviews).
|
||||
/// Used as evidence for floors / seating.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct TextSnippet {
|
||||
pub source: PhotoSourceId,
|
||||
pub url: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct SourceOutput {
|
||||
pub photos: Vec<RawPhoto>,
|
||||
pub texts: Vec<TextSnippet>,
|
||||
}
|
||||
|
||||
/// Stored photo (MongoDB `photos`). Bytes live in MinIO under `object_key`.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Photo {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub place_id: String,
|
||||
pub source: PhotoSourceId,
|
||||
pub image_url: String,
|
||||
pub page_url: String,
|
||||
pub caption: String,
|
||||
pub object_key: String,
|
||||
/// 64-bit difference hash, hex encoded (BSON has no u64).
|
||||
pub dhash: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub tag: Option<PhotoTag>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PhotoKind {
|
||||
Interior,
|
||||
Exterior,
|
||||
Food,
|
||||
Menu,
|
||||
Person,
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PhotoZone {
|
||||
Entrance,
|
||||
Counter,
|
||||
Hall,
|
||||
WindowSide,
|
||||
Terrace,
|
||||
Restroom,
|
||||
Stairs,
|
||||
Kitchen,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// VLM classification of one photo.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PhotoTag {
|
||||
pub kind: PhotoKind,
|
||||
pub zone: PhotoZone,
|
||||
/// Same convention as `FloorEvidence::level`; `None` = unknown.
|
||||
pub floor_level: Option<i32>,
|
||||
pub floor_evidence: String,
|
||||
pub furniture: Vec<FurnitureCount>,
|
||||
pub quality: f32,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FurnitureCount {
|
||||
pub kind: crate::FurnitureKind,
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
/// Lightweight photo info sent to the UI.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PhotoSummary {
|
||||
pub id: String,
|
||||
pub source: PhotoSourceId,
|
||||
pub page_url: String,
|
||||
pub caption: String,
|
||||
pub kind: Option<PhotoKind>,
|
||||
pub zone: Option<PhotoZone>,
|
||||
pub floor_level: Option<i32>,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl From<&Photo> for PhotoSummary {
|
||||
fn from(p: &Photo) -> Self {
|
||||
Self {
|
||||
id: p.id.clone(),
|
||||
source: p.source,
|
||||
page_url: p.page_url.clone(),
|
||||
caption: p.caption.clone(),
|
||||
kind: p.tag.as_ref().map(|t| t.kind),
|
||||
zone: p.tag.as_ref().map(|t| t.zone),
|
||||
floor_level: p.tag.as_ref().and_then(|t| t.floor_level),
|
||||
description: p.tag.as_ref().map(|t| t.description.clone()).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A search result shown to the user before they confirm the place.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PlaceCandidate {
|
||||
/// Provider that produced this candidate (`kakao`, `naver`).
|
||||
pub provider: String,
|
||||
/// Provider-native id (Kakao place id, Naver place id).
|
||||
pub provider_id: String,
|
||||
pub name: String,
|
||||
pub category: String,
|
||||
pub address: String,
|
||||
pub road_address: String,
|
||||
pub phone: String,
|
||||
pub lat: f64,
|
||||
pub lng: f64,
|
||||
pub place_url: String,
|
||||
}
|
||||
|
||||
impl PlaceCandidate {
|
||||
/// Stable internal id, e.g. `kakao:12345`.
|
||||
pub fn place_id(&self) -> String {
|
||||
format!("{}:{}", self.provider, self.provider_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Canonical, normalized place persisted in MongoDB.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Place {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub kakao_id: Option<String>,
|
||||
pub naver_place_id: Option<String>,
|
||||
pub name: String,
|
||||
pub category: String,
|
||||
pub address: String,
|
||||
pub road_address: String,
|
||||
pub phone: String,
|
||||
pub lat: f64,
|
||||
pub lng: f64,
|
||||
pub place_url: String,
|
||||
}
|
||||
|
||||
/// A saved analysis that can be reopened without starting another analysis job.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct RecentPlace {
|
||||
pub place: Place,
|
||||
pub analyzed_at: String,
|
||||
pub last_viewed_at: Option<String>,
|
||||
pub floor_labels: Vec<String>,
|
||||
pub seat_estimate: u32,
|
||||
}
|
||||
|
||||
impl Place {
|
||||
pub fn from_candidate(c: &PlaceCandidate) -> Self {
|
||||
let (kakao_id, naver_place_id) = match c.provider.as_str() {
|
||||
"kakao" => (Some(c.provider_id.clone()), None),
|
||||
"naver" => (None, Some(c.provider_id.clone())),
|
||||
_ => (None, None),
|
||||
};
|
||||
Self {
|
||||
id: c.place_id(),
|
||||
kakao_id,
|
||||
naver_place_id,
|
||||
name: c.name.clone(),
|
||||
category: c.category.clone(),
|
||||
address: c.address.clone(),
|
||||
road_address: c.road_address.clone(),
|
||||
phone: c.phone.clone(),
|
||||
lat: c.lat,
|
||||
lng: c.lng,
|
||||
place_url: c.place_url.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Short region hint (e.g. "성동구 성수동") used to disambiguate web searches.
|
||||
pub fn region_hint(&self) -> String {
|
||||
let addr = if self.address.is_empty() { &self.road_address } else { &self.address };
|
||||
addr.split_whitespace().skip(1).take(2).collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user