Skip to content

Commit

Permalink
Merge pull request #230 from earthpulse/229-ingest-models-through-ui
Browse files Browse the repository at this point in the history
added model ingestion through ui
  • Loading branch information
juansensio authored Oct 1, 2024
2 parents dc63ddd + 8cc6bda commit 8499b65
Show file tree
Hide file tree
Showing 10 changed files with 387 additions and 85 deletions.
78 changes: 0 additions & 78 deletions ui/src/components/Create.svelte

This file was deleted.

10 changes: 10 additions & 0 deletions ui/src/lib/models/createModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PUBLIC_EOTDL_API } from '$env/static/public';
import fetchEOTDL from '$lib/shared/fetchEOTDL';

export default async (name, authors, source, license, token) => {
const url = `${PUBLIC_EOTDL_API}/models`;
const body = {name, authors, license, source};
const { data, error } = await fetchEOTDL(url, token, 'POST', body);
if (error) throw new Error(error);
return data;
};
12 changes: 12 additions & 0 deletions ui/src/lib/models/ingestFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PUBLIC_EOTDL_API } from '$env/static/public';
import EOTDLFileUpload from '$lib/shared/EOTDLFileUpload';
import fileChecksum from '../datasets/fileChecksum';
export default async (model_id, file, token, version) => {
const url = `${PUBLIC_EOTDL_API}/models/${model_id}?version=${version.version}`;
const formData = new FormData();
formData.append("file", file);
formData.append("checksum", fileChecksum(await file.arrayBuffer()));
const { data, error } = await EOTDLFileUpload(url, token, formData);
if (error) throw new Error(error);
return data;
};
9 changes: 9 additions & 0 deletions ui/src/lib/models/setModelVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PUBLIC_EOTDL_API } from '$env/static/public';
import fetchEOTDL from '$lib/shared/fetchEOTDL';

export default async (model_id, token) => {
const url = `${PUBLIC_EOTDL_API}/models/version/${model_id}`;
const { data, error } = await fetchEOTDL(url, token, 'POST');
if (error) throw new Error(error);
return data;
};
2 changes: 1 addition & 1 deletion ui/src/routes/datasets/IngestForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
>
<button
class="btn btn-ghost btn-outline {loading && 'loading'}"
type="submit">Update</button
type="submit">Ingest</button
>
</span>
{#if error}
Expand Down
7 changes: 2 additions & 5 deletions ui/src/routes/models/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Skeleton from "$components/Skeleton.svelte";
import ModelsLeaderboard from "../ModelsLeaderboard.svelte";
import QualitySelector from "$components/QualitySelector.svelte";
import Ingest from "./Ingest.svelte";
export let data;
let loading = true;
Expand Down Expand Up @@ -99,14 +99,11 @@
>
<QualitySelector bind:selected_qualities />
</span>
<!-- <Ingest tags={data?.tags} /> -->
</div>
<Tags tags={data?.tags} bind:selected_tags {onToggleTag} />
</div>
<span class="flex flex-row w-full justify-between items-center">
<a href="/docs/models/ingest" class="text-green-200 hover:underline"
>Ingest model</a
>
<Ingest tags={data?.tags} />
</span>
{#if loading}
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3 w-full mt-3">
Expand Down
72 changes: 72 additions & 0 deletions ui/src/routes/models/Ingest.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script>
import { user, id_token } from "$stores/auth";
import { models } from "../../stores/models";
import IngestForm from "./IngestForm.svelte";
export let tags;
const submit = async (
files,
name,
content,
authors,
source,
license,
selected_tags
) => {
if (
!name ||
files?.length == 0 ||
authors.length == 0 ||
!license ||
!source ||
!content ||
content.length == 0
)
throw new Error("Please fill in all fields");
let data;
if (files.length == 0) throw new Error("Please upload a file");
const modelExists = $models.data.find(
(d) => d.name == name && d.uid == $user.uid
);
if (modelExists)
throw new Error("Model already exists, choose a different name");
const model_id = await models.create(
name,
authors,
source,
license,
$id_token
);
const version = await models.setVersion(model_id, $id_token);
for (var i = 0; i < files.length; i++) {
data = await models.ingest(model_id, files[i], $id_token, version, name);
}
await models.update(
model_id,
name,
content,
authors,
source,
license,
selected_tags,
$id_token
);
};
</script>
{#if $user}
<IngestForm
{tags}
{submit}
text="Ingest model"
forCreate={true}
required={true}
name={""}
authors={""}
source={""}
license={""}
content={""}>
<h3 class="text-lg font-bold">Ingest model</h3>
</IngestForm>
{/if}
Loading

0 comments on commit 8499b65

Please sign in to comment.