import { useCallback, useRef, useState } from "react"; import { Link } from "react-router-dom"; import { Upload, Image as ImageIcon, PlayCircle, RotateCcw, LayoutList } from "lucide-react"; import { toast } from "sonner"; import { forgesight, fileToBase64 } from "@/lib/api"; import TelemetryWidget from "@/components/TelemetryWidget"; import AgentTranscript from "@/components/AgentTranscript"; import ReportDownloader from "@/components/ReportDownloader"; export default function Console() { const [file, setFile] = useState(null); const [preview, setPreview] = useState(""); const [notes, setNotes] = useState(""); const [spec, setSpec] = useState(""); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const [dragActive, setDragActive] = useState(false); const inputRef = useRef(null); const reportRef = useRef(null); const handleFile = useCallback((f) => { if (!f) return; if (!/(jpe?g|png|webp)$/i.test(f.type.split("/")[1] || f.name.split(".").pop())) { toast.error("Only JPEG / PNG / WEBP images are supported"); return; } setFile(f); setPreview(URL.createObjectURL(f)); setResult(null); }, []); const onDrop = (e) => { e.preventDefault(); setDragActive(false); const f = e.dataTransfer.files?.[0]; handleFile(f); }; const runInspection = async () => { if (!file) { toast.error("Upload an image first"); return; } setLoading(true); setResult(null); try { const image_base64 = await fileToBase64(file); const data = await forgesight.createInspection({ image_base64, notes, product_spec: spec, source: "upload", }); setResult(data); toast.success("Inspection complete"); } catch (e) { toast.error(e?.response?.data?.detail || "Inspection failed"); } finally { setLoading(false); } }; const reset = () => { setFile(null); setPreview(""); setNotes(""); setSpec(""); setResult(null); }; const summary = result?.summary; return (
Upload a construction site, road infrastructure, or housing image. Four agents will collaborate to deliver a structural or safety verdict.