Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maps/function-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function embed(location) {
loading="lazy"
allowfullscreen
referrerpolicy="no-referrer-when-downgrade"
sandbox="allow-scripts allow-popups allow-forms allow-same-origin allow-popups-to-escape-sandbox"
src="https://www.google.com/maps/embed/v1/place?key=${API_KEY}
&q=${location}"
>
Expand Down
3 changes: 3 additions & 0 deletions maps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

<body>
<div id="root"></div>
<div id="controls">
<button id="save-local-button">Save to Local</button>
</div>
<script src="script.js" type="module"></script>
</body>

Expand Down
14 changes: 14 additions & 0 deletions maps/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ async function init() {
} else {
document.documentElement.setAttribute("data-theme", "light");
}

const saveLocalButton = document.querySelector("#save-local-button");
saveLocalButton.addEventListener("click", () => {
const location = document.querySelector("#map iframe").src;
const caption = document.querySelector("#caption p")?.textContent || "";
const content = `Location: ${location}\nCaption: ${caption}`;
const blob = new Blob([content], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "map-data.txt";
a.click();
URL.revokeObjectURL(url);
});
}

init();
Expand Down
14 changes: 13 additions & 1 deletion spatial/src/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { useAtom } from "jotai";
import { useResetState } from "./hooks";
import { useResetState, useSaveState } from "./hooks";
import {
DetectTypeAtom,
HoverEnteredAtom,
Expand All @@ -25,6 +25,7 @@ import { modelOptions } from "./consts";

export function TopBar() {
const resetState = useResetState();
const saveState = useSaveState();
const [revealOnHover, setRevealOnHoverMode] = useAtom(RevealOnHoverModeAtom);
const [detectType] = useAtom(DetectTypeAtom);
const [, setHoverEntered] = useAtom(HoverEnteredAtom);
Expand All @@ -45,6 +46,17 @@ export function TopBar() {
>
<div>Reset session</div>
</button>
<button
onClick={() => {
saveState();
}}
className="p-0 border-none underline bg-transparent"
style={{
minHeight: "0",
}}
>
<div>Save to Local</div>
</button>
</div>
<div className="flex gap-3 items-center">
{detectType === "2D bounding boxes" ? (
Expand Down
32 changes: 32 additions & 0 deletions spatial/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
BumpSessionAtom,
ImageSentAtom,
PointsAtom,
ImageSrcAtom,
LinesAtom,
DetectTypeAtom,
} from "./atoms";

export function useResetState() {
Expand All @@ -36,3 +39,32 @@ export function useResetState() {
setPoints([]);
};
}

export function useSaveState() {
const [imageSrc] = useAtom(ImageSrcAtom);
const [boundingBoxes2D] = useAtom(BoundingBoxes2DAtom);
const [boundingBoxes3D] = useAtom(BoundingBoxes3DAtom);
const [points] = useAtom(PointsAtom);
const [lines] = useAtom(LinesAtom);
const [detectType] = useAtom(DetectTypeAtom);

return () => {
const state = {
imageSrc,
boundingBoxes2D,
boundingBoxes3D,
points,
lines,
detectType,
};

const content = JSON.stringify(state, null, 2);
const blob = new Blob([content], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "spatial-data.json";
a.click();
URL.revokeObjectURL(url);
};
}
28 changes: 28 additions & 0 deletions video/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ export default function App() {
const isCustomChartMode = isChartMode && chartMode === 'Custom'
const hasSubMode = isCustomMode || isChartMode

const saveState = () => {
const state = {
vidUrl,
timecodeList,
selectedMode,
activeMode,
customPrompt,
chartMode,
chartPrompt,
chartLabel,
};

const content = JSON.stringify(state, null, 2);
const blob = new Blob([content], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "video-data.json";
a.click();
URL.revokeObjectURL(url);
};

const setTimecodes = ({timecodes}) =>
setTimecodeList(
timecodes.map(t => ({...t, text: t.text.replaceAll("\\'", "'")}))
Expand Down Expand Up @@ -238,6 +260,12 @@ export default function App() {
>
▶️ Generate
</button>
<button
className="button saveButton"
onClick={saveState}
>
💾 Save to Local
</button>
</div>
</>
)}
Expand Down