File size: 3,370 Bytes
0bd62e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
<script lang="ts">
import type { ComponentData } from "./utils";
import CopyButton from "$lib/icons/CopyButton.svelte";
import { BaseCode } from "@gradio/code";
import { onMount } from "svelte";
export let data: ComponentData;
let source_code_link = `https://huggingface.co/spaces/${data.id}`;
let author_link = `https://huggingface.co/${data.author}`;
let discussion_link = `https://huggingface.co/spaces/${data.id}/discussions/new`;
let code_url = `https://huggingface.co/spaces/${data.id}/raw/main/app.py`;
const tabs = ["Demo", "Code"];
let active_tab = 0;
let code: string;
onMount(async () => {
code = await fetch(code_url).then((res) => res.text());
});
</script>
<div class="card space-y-2 bg-gradient-to-tr {data.background_color} shadow-xl">
<h1 class="text-xl font-black">{data.description}</h1>
<div class="flex flex-row">
<div class="ml-2">
<code class="code text-md">
pip install {data.name.replace("_", "-")}
<CopyButton content={`pip install ${data.name.replace("_", "-")}`} />
</code>
</div>
<div class="ml-2">
<strong>ποΈ Author</strong>
<a
href={author_link}
target="_blank"
class="link text-orange-400 font-bold">{data.author}</a
>
</div>
<div class="ml-2">
<strong>π Template</strong>
{data.template}
</div>
<div class="ml-2">
<strong>π’ Version:</strong>
{data.version}
</div>
<div class="ml-2">
<strong>π§¬</strong>
<a
href={source_code_link}
target="_blank"
class="link text-orange-400 font-bold">code</a
>
</div>
</div>
<div class="flex flex-row">
<div class="ml-2">
<strong>π Tags:</strong>
{data.tags.split(",").join(", ")}
</div>
</div>
<div class="flex flex-row">
<div class="ml-2">
<strong>π€ Feedback? Stuck?</strong>
<a
href={discussion_link}
target="_blank"
class="link text-orange-400 font-bold"
>
Ask for help</a
>
</div>
</div>
<div class="flex flex-col relative h-full">
<div class="tabs flex flex-row relative">
{#each tabs as tab, index}
<div
class="tab bg-white {active_tab === index
? 'active'
: ''} {active_tab === index
? ''
: 'border-b-2'} px-8 py-1 rounded-t-md border-x-2 border-t-2 border-orange-300 content-center"
on:click={() => {
active_tab = index;
}}
>
{tab}
</div>
{/each}
</div>
{#if active_tab === 0}
<iframe
src={`https://${data.subdomain}.hf.space?__theme=light`}
height="100%"
width="100%"
></iframe>
{:else}
<div class="bg-white">
<BaseCode value={code} language="python" dark_mode={false} />
</div>
{/if}
</div>
</div>
<style>
.card {
border-radius: 8px;
padding: 16px;
margin: 16px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
overflow-y: auto;
height: 100%;
}
.card p {
margin: 8px 0;
color: rgb(206 100 0 / var(--tw-text-opacity));
}
.link {
text-decoration: underline;
}
.code {
font-family: monospace;
background-color: #f8f9fa;
padding: 0.2em 0.4em;
border-radius: 4px;
}
.tabs {
display: flex;
margin-bottom: -1px;
}
.tab {
cursor: pointer;
}
.active {
font-weight: bold;
}
</style>
|