enzostvs HF staff commited on
Commit
727ce74
β€’
1 Parent(s): 644d65a

drawer add more informations about model

Browse files
src/lib/components/models/Card.svelte CHANGED
@@ -8,12 +8,12 @@
8
  export let card: ModelCard;
9
 
10
  const handleClick = async () => {
11
- const request = await fetch(`/api/models/${card?.id?.replace("/", "@")}?full=true`);
12
- const { model } = await request.json();
13
- modelStore.set({
14
- model,
15
- open: true
16
- });
17
  $page.url.searchParams.set('model', card?.id);
18
  goto(`?${$page.url.searchParams.toString()}`);
19
  };
 
8
  export let card: ModelCard;
9
 
10
  const handleClick = async () => {
11
+ // const request = await fetch(`/api/models/${card?.id?.replace("/", "@")}?full=true`);
12
+ // const { model } = await request.json();
13
+ // modelStore.set({
14
+ // model,
15
+ // open: true
16
+ // });
17
  $page.url.searchParams.set('model', card?.id);
18
  goto(`?${$page.url.searchParams.toString()}`);
19
  };
src/lib/components/models/drawer/Drawer.svelte CHANGED
@@ -9,7 +9,6 @@
9
  import UserIsLogged from '$lib/components/UserIsLogged.svelte';
10
  import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
11
  import { env } from '$env/dynamic/public';
12
- import Button from '$lib/components/Button.svelte';
13
 
14
  let { open, model } = get(modelStore);
15
 
@@ -29,6 +28,8 @@
29
  $page.url.searchParams.delete('model');
30
  goto(`?${$page.url.searchParams.toString()}`);
31
  };
 
 
32
  </script>
33
 
34
  <div
@@ -50,7 +51,7 @@
50
  <p class="text-white font-semibold text-lg lg:text-2xl mb-1 truncate">
51
  {model?.title ?? model?.id}
52
  </p>
53
- <a href="https://huggingface.co/{model?.id}" class="text-neutral-400 underline hover:text-blue-00 flex items-center justify-start gap-1">
54
  <Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
55
  View on HuggingFace
56
  </a>
@@ -60,24 +61,24 @@
60
  <Icon icon="carbon:close" class="w-6 h-6 text-white cursor-pointer" />
61
  </button>
62
  </header>
63
- <main>
64
- <div class="justify-start items-center gap-4 flex mb-6">
65
- <div class="bg-red-500 bg-opacity-20 border border-red-500 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 font-medium text-sm">
66
- <Icon icon="solar:heart-bold" class="lg:w-4 lg:h-4 w-3 h-3 text-red-500" />
67
  {model?.likes ?? 0}
68
  </div>
69
  <a
70
  href="/"
71
- class="bg-blue-500 bg-opacity-20 border border-blue-500 hover:bg-opacity-60 transition-all duration-200 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 font-medium text-sm"
72
  >
73
- <Icon icon="solar:download-square-bold" class="lg:w-4 lg:h-4 w-3 h-3 text-blue-500" />
74
  View files
75
  </a>
76
  <a
77
  href="/generate?model={model?.id}"
78
- class="bg-pink-500 bg-opacity-20 hover:bg-opacity-60 transition-all duration-200 border border-pink-500 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 font-medium text-sm"
79
  >
80
- <Icon icon="fluent:glance-horizontal-sparkles-16-filled" class="lg:w-4 lg:h-4 w-3 h-3 text-pink-500" />
81
  Generate
82
  </a>
83
  </div>
@@ -100,11 +101,27 @@
100
  </a>
101
  </div>
102
  {/if}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  </main>
104
  </div>
105
  <footer class="p-8 border-t border-neutral-900 bg-neutral-900/30">
106
  <p class="font-semibold text-neutral-100 text-base lg:text-lg mb-6">
107
- Commentaires ({model?.comments?.length ?? 0})
108
  </p>
109
  {#if model?.id}
110
  <UserIsLogged>
 
9
  import UserIsLogged from '$lib/components/UserIsLogged.svelte';
10
  import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
11
  import { env } from '$env/dynamic/public';
 
12
 
13
  let { open, model } = get(modelStore);
14
 
 
28
  $page.url.searchParams.delete('model');
29
  goto(`?${$page.url.searchParams.toString()}`);
30
  };
31
+
32
+ $: console.log(model);
33
  </script>
34
 
35
  <div
 
51
  <p class="text-white font-semibold text-lg lg:text-2xl mb-1 truncate">
52
  {model?.title ?? model?.id}
53
  </p>
54
+ <a href="https://huggingface.co/{model?.id}" target="_blank" class="text-neutral-400 underline hover:text-blue-00 flex items-center justify-start gap-1">
55
  <Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
56
  View on HuggingFace
57
  </a>
 
61
  <Icon icon="carbon:close" class="w-6 h-6 text-white cursor-pointer" />
62
  </button>
63
  </header>
64
+ <main class="grid grid-cols-1 gap-6">
65
+ <div class="justify-start items-center gap-4 flex">
66
+ <div class="bg-red-500 bg-opacity-20 border border-red-500 md:px-4 md:py-2 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 md:gap-2 font-medium text-sm md:text-base">
67
+ <Icon icon="solar:heart-bold" class="lg:w-5 lg:h-5 w-4 h-4 text-red-500" />
68
  {model?.likes ?? 0}
69
  </div>
70
  <a
71
  href="/"
72
+ class="bg-blue-500 bg-opacity-20 border border-blue-500 hover:bg-opacity-60 transition-all duration-200 md:px-4 md:py-2 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 md:gap-2 font-medium text-sm md:text-base"
73
  >
74
+ <Icon icon="solar:download-square-bold" class="lg:w-5 lg:h-5 w-4 h-4 text-blue-500" />
75
  View files
76
  </a>
77
  <a
78
  href="/generate?model={model?.id}"
79
+ class="bg-pink-500 bg-opacity-20 hover:bg-opacity-60 transition-all duration-200 border border-pink-500 md:px-4 md:py-2 px-3 py-1.5 rounded-full text-neutral-100 flex items-center justify-center gap-1 md:gap-2 font-medium text-sm md:text-base"
80
  >
81
+ <Icon icon="fluent:glance-horizontal-sparkles-16-filled" class="lg:w-5 lg:h-5 w-4 h-4 text-pink-500" />
82
  Generate
83
  </a>
84
  </div>
 
101
  </a>
102
  </div>
103
  {/if}
104
+ {#if model?.infos}
105
+ <div class="bg-neutral-900/70 rounded-lg border border-neutral-800/20">
106
+ <div class="border-b border-neutral-800/80 px-5 py-4">
107
+ <p class="text-neutral-400 uppercase text-[10px]">license</p>
108
+ <p class="text-neutral-100 font-medium text-sm mt-0.5">{model?.infos?.license ?? 'N/A'}</p>
109
+ </div>
110
+ <div class="border-b border-neutral-800/80 px-5 py-4">
111
+ <p class="text-neutral-400 uppercase text-[10px]">tags</p>
112
+ <p class="text-neutral-100 font-medium text-sm mt-0.5">{model?.infos?.tags?.join(', ')}</p>
113
+ </div>
114
+ <div class="px-5 py-4">
115
+ <p class="text-neutral-400 uppercase text-[10px]">base_model</p>
116
+ <p class="text-neutral-100 font-medium text-sm mt-0.5">{model?.infos?.base_model ?? 'N/A'}</p>
117
+ </div>
118
+ </div>
119
+ {/if}
120
  </main>
121
  </div>
122
  <footer class="p-8 border-t border-neutral-900 bg-neutral-900/30">
123
  <p class="font-semibold text-neutral-100 text-base lg:text-lg mb-6">
124
+ Commentaire{(model?.comments?.length ?? 0) > 1 ? 's' : ''} ({model?.comments?.length ?? 0})
125
  </p>
126
  {#if model?.id}
127
  <UserIsLogged>
src/lib/type.ts CHANGED
@@ -21,8 +21,13 @@ export interface ModelCard {
21
  likes: number,
22
  downloads: number,
23
  image: string,
24
- gallery?: CommunityCard[]
25
- comments?: CommentType[]
 
 
 
 
 
26
  }
27
 
28
  export interface ReactionType {
 
21
  likes: number,
22
  downloads: number,
23
  image: string,
24
+ gallery?: CommunityCard[],
25
+ comments?: CommentType[],
26
+ infos?: {
27
+ license?: string,
28
+ tags?: string[],
29
+ base_model?: string,
30
+ },
31
  }
32
 
33
  export interface ReactionType {
src/routes/+page.svelte CHANGED
@@ -2,7 +2,6 @@
2
  import { browser } from "$app/environment";
3
  import InfiniteScroll from "svelte-infinite-scroll";
4
 
5
- import { modelStore } from "$lib/stores/use-model.js";
6
  import Button from "$lib/components/Button.svelte";
7
  import Card from "$lib/components/models/Card.svelte";
8
  import Input from "$lib/components/fields/Input.svelte";
@@ -25,13 +24,6 @@
25
 
26
  $: elementScroll = browser ? document?.getElementById('app') : undefined;
27
 
28
- if (data?.model?.id) {
29
- modelStore.set({
30
- model: data.model,
31
- open: true
32
- });
33
- }
34
-
35
  const handleFetchMore = async () => {
36
  form = {...form, page: (Number(form.page) + 1).toString()};
37
  refetch(true);
 
2
  import { browser } from "$app/environment";
3
  import InfiniteScroll from "svelte-infinite-scroll";
4
 
 
5
  import Button from "$lib/components/Button.svelte";
6
  import Card from "$lib/components/models/Card.svelte";
7
  import Input from "$lib/components/fields/Input.svelte";
 
24
 
25
  $: elementScroll = browser ? document?.getElementById('app') : undefined;
26
 
 
 
 
 
 
 
 
27
  const handleFetchMore = async () => {
28
  form = {...form, page: (Number(form.page) + 1).toString()};
29
  refetch(true);
src/routes/+page.ts CHANGED
@@ -1,7 +1,8 @@
 
 
1
  export async function load({ fetch, url }) {
2
  const model_param = url.searchParams.get("model")
3
 
4
- let model;
5
 
6
  if (model_param) {
7
  const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
@@ -10,8 +11,11 @@ export async function load({ fetch, url }) {
10
  "Content-Type": "application/json"
11
  }
12
  })
13
- const model_response = await model_request?.clone().json().catch(() => null);
14
- model = model_response
 
 
 
15
  }
16
 
17
  const response = await fetch("/api/models?page=0&filter=hotest", {
@@ -24,6 +28,6 @@ export async function load({ fetch, url }) {
24
  return {
25
  models: models?.cards ?? [],
26
  total_items: models?.total_items ?? 0,
27
- model: model?.model ?? null
28
  }
29
  }
 
1
+ import { modelStore } from "$lib/stores/use-model";
2
+
3
  export async function load({ fetch, url }) {
4
  const model_param = url.searchParams.get("model")
5
 
 
6
 
7
  if (model_param) {
8
  const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
 
11
  "Content-Type": "application/json"
12
  }
13
  })
14
+ const data = await model_request?.clone().json().catch(() => null);
15
+ modelStore.set({
16
+ model: data?.model ?? null,
17
+ open: true
18
+ });
19
  }
20
 
21
  const response = await fetch("/api/models?page=0&filter=hotest", {
 
28
  return {
29
  models: models?.cards ?? [],
30
  total_items: models?.total_items ?? 0,
31
+ // model: model?.model ?? null
32
  }
33
  }
src/routes/api/models/[id]/+server.ts CHANGED
@@ -1,4 +1,5 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
 
2
  import prisma from '$lib/prisma';
3
 
4
  /** @type {import('./$types').RequestHandler} */
@@ -58,18 +59,26 @@ export async function GET({ url, params } : RequestEvent) {
58
  }, { status: 401 })
59
  }
60
 
61
- // const gallery = await prisma.gallery.findMany({
62
- // where: {
63
- // modelId: model.id
64
- // },
65
- // orderBy: {
66
- // createdAt: "desc"
67
- // },
68
- // take: 5
69
- // })
 
 
 
 
 
 
70
 
71
  return json({
72
- model,
73
- // gallery
 
 
74
  })
75
  }
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
+ import { env } from '$env/dynamic/private'
3
  import prisma from '$lib/prisma';
4
 
5
  /** @type {import('./$types').RequestHandler} */
 
59
  }, { status: 401 })
60
  }
61
 
62
+ let infos: Record<string, string | string[]> = {};
63
+
64
+ if (full) {
65
+ const hf_model_request = await fetch(`https://huggingface.co/api/models/${id}`, {
66
+ headers: {
67
+ "Authorization": `Bearer ${env.SECRET_HF_TOKEN}`
68
+ }
69
+ })
70
+ const hf_model_response = await hf_model_request.json();
71
+ infos = {
72
+ base_model: hf_model_response?.cardData?.base_model,
73
+ license: hf_model_response?.cardData?.license,
74
+ tags: hf_model_response?.cardData?.tags,
75
+ }
76
+ }
77
 
78
  return json({
79
+ model: {
80
+ ...model,
81
+ infos
82
+ }
83
  })
84
  }