Spaces:
Running
Running
File size: 1,858 Bytes
055707a 298baa9 055707a 298baa9 055707a 298baa9 055707a |
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 |
<script lang="ts">
import { BlockLabel, Empty, IconButton } from "@gradio/atoms";
import { File as FileIcon } from "@gradio/icons";
import { type FileData } from "@gradio/client";
import type { I18nFormatter } from "@gradio/utils";
export let value: null | FileData;
export let label: string | undefined = undefined;
export let show_label: boolean;
export let show_download_button = true;
export let selectable = false;
export let i18n: I18nFormatter;
let fasta_text = "";
async function loadFastaFile(filePath) {
const response = await fetch(filePath);
fasta_text = await response.text();
fasta_text = fasta_text.replaceAll("G", "<span style='color: green'>G</span>");
fasta_text = fasta_text.replaceAll("A", "<span style='color: red'>A</span>");
fasta_text = fasta_text.replaceAll("T", "<span style='color: blue'>T</span>");
fasta_text = fasta_text.replaceAll("C", "<span style='color: orange'>C</span>");
fasta_text = fasta_text.replaceAll(/^(>.*)$/gm, "<span style='color: gray !important'>$1</span>");
}
$: if (value && value.url) {
loadFastaFile(value.url);
}
</script>
<BlockLabel
{show_label}
Icon={FileIcon}
label={label || i18n("image.image")}
/>
{#if value === null || !value.url}
<Empty unpadded_box={true} size="large"><FileIcon /></Empty>
{:else}
<div id="fasta_content">{@html fasta_text}</div>
{/if}
<style>
.image-container :global(img),
button {
width: var(--size-full);
height: var(--size-full);
object-fit: contain;
display: block;
border-radius: var(--radius-lg);
}
.selectable {
cursor: crosshair;
}
.icon-buttons {
display: flex;
position: absolute;
top: 6px;
right: 6px;
gap: var(--size-1);
}
#fasta_content {
padding: 25px 5px 0px 5px;
overflow-x: scroll;
overflow-y: scroll;
font-family: Consolas, 'Courier New', monospace;
}
</style>
|