File size: 14,908 Bytes
a03b3ba |
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
<script lang="ts">
import Demos from "$lib/components/Demos.svelte";
import DocsNav from "$lib/components/DocsNav.svelte";
import FunctionDoc from "$lib/components/FunctionDoc.svelte";
import MetaTags from "$lib/components/MetaTags.svelte";
import anchor from "$lib/assets/img/anchor.svg";
import { onDestroy } from "svelte";
import { page } from "$app/stores";
export let data: any;
let objs = data.objs;
let mode = data.mode;
let description = data.description;
let components = data.components;
let helpers = data.helpers;
let modals = data.modals;
let routes = data.routes;
let headers = data.headers;
let method_headers = data.method_headers;
let py_client = data.py_client;
let current_selection = 0;
let y: number;
let header_targets: { [key: string]: HTMLElement } = {};
let target_elem: HTMLElement;
onDestroy(() => {
header_targets = {};
});
$: for (const target in header_targets) {
target_elem = document.querySelector(`#${target}`) as HTMLElement;
if (
y > target_elem?.offsetTop - 50 &&
y < target_elem?.offsetTop + target_elem?.offsetHeight
) {
header_targets[target]?.classList.add("current-nav-link");
} else {
header_targets[target]?.classList.remove("current-nav-link");
}
}
let on_main: boolean;
let wheel: string = data.wheel;
$: on_main = data.on_main;
$: components = data.components;
$: helpers = data.helpers;
$: modals = data.modals;
$: routes = data.routes;
$: py_client = data.py_client;
</script>
<MetaTags
title={"Gradio Flagging Docs"}
url={$page.url.pathname}
canonical={$page.url.pathname}
{description}
/>
<svelte:window bind:scrollY={y} />
<main class="container mx-auto px-4 flex gap-4">
<div class="flex w-full">
<DocsNav
current_nav_link={"flagging"}
{components}
{helpers}
{modals}
{routes}
{py_client}
/>
<div class="flex flex-col w-full min-w-full lg:w-8/12 lg:min-w-0">
<div>
<p
class="lg:ml-10 bg-gradient-to-r from-orange-100 to-orange-50 border border-orange-200 px-4 py-1 mr-2 rounded-full text-orange-800 mb-1 w-fit float-left"
>
New to Gradio? Start here: <a class="link" href="/quickstart"
>Getting Started</a
>
</p>
<p
class="bg-gradient-to-r from-green-100 to-green-50 border border-green-200 px-4 py-1 rounded-full text-green-800 mb-1 w-fit float-left sm:float-right"
>
See the <a class="link" href="/changelog">Release History</a>
</p>
</div>
{#if on_main}
<div
class="bg-gray-100 border border-gray-200 text-gray-800 px-3 py-1 mt-4 rounded-lg lg:ml-10"
>
<p class="my-2">
To install Gradio from main, run the following command:
</p>
<div class="codeblock">
<pre class="language-bash" style="padding-right: 50px;"><code
class="language-bash">pip install {wheel}</code
></pre>
</div>
<p class="float-right text-sm">
*Note: Setting <code style="font-size: 0.85rem">share=True</code> in
<code style="font-size: 0.85rem">launch()</code> will not work.
</p>
</div>
{/if}
<div class="lg:ml-10 flex justify-between mt-4">
<a
href="./mount_gradio_app"
class="text-left px-4 py-1 bg-gray-50 rounded-full hover:underline"
>
<div class="text-lg">
<span class="text-orange-500">←</span> mount_gradio_app
</div>
</a>
<a
href="./themes"
class="text-right px-4 py-1 bg-gray-50 rounded-full hover:underline"
>
<div class="text-lg">
Themes <span class="text-orange-500">→</span>
</div>
</a>
</div>
<div class="flex flex-row">
<div class="lg:ml-10">
<div class="obj" id="flagging">
<div class="flex flex-row items-center justify-between">
<h3 id="flagging-header" class="group text-3xl font-light py-4">
Flagging
<a href="#flagging" class="invisible group-hover-visible"
><img class="anchor-img" src={anchor} /></a
>
</h3>
</div>
<h4
class="mt-2 text-xl text-orange-500 font-light group"
id="description"
>
Description
<a href="#description" class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<p class="mb-2 text-lg text-gray-600">{@html description}</p>
</div>
{#each objs as obj}
<div class="obj" id={obj.slug}>
<div class="flex flex-row items-center justify-between">
<h3
id="{obj.slug}-header"
class="group text-3xl font-light py-4"
>
{obj.name}
<a
href="#{obj.slug}-header"
class="invisible group-hover-visible"
><img class="anchor-img" src={anchor} /></a
>
</h3>
</div>
{#if obj.override_signature}
<div class="codeblock">
<pre><code class="code language-python"
>{obj.override_signature}</code
></pre>
</div>
{:else}
<div class="codeblock">
<pre><code class="code language-python"
>{obj.parent}.<span>{obj.name}(</span
><!--
-->{#each obj.parameters as param}<!--
-->{#if !("kwargs" in param) && !("default" in param) && param.name != "self"}<!--
-->{param.name}, <!--
-->{/if}<!--
-->{/each}<!--
-->路路路<span
>)</span
></code
></pre>
</div>
{/if}
{#if mode === "components"}
<div class="embedded-component">
{#key obj.name}
<gradio-app
space={"gradio/" +
obj.name.toLowerCase() +
"_component_main"}
/>
{/key}
</div>
{/if}
<h4
class="mt-8 text-xl text-orange-500 font-light group"
id="{obj.name}-description"
>
Description
<a
href="#{obj.name}-description"
class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<p class="mb-2 text-lg text-gray-600">{@html obj.description}</p>
{#if mode === "components"}
<p class="mb-2 text-lg text-gray-500">
<span class="text-orange-500">As input: </span>
{@html obj.tags.preprocessing}
</p>
<p class="mb-2 text-lg text-gray-500">
<span class="text-orange-500">As output:</span>
{@html obj.tags.postprocessing}
</p>
{#if obj.tags.examples_format}
<p class="mb-2 text-lg text-gray-500">
<span class="text-orange-500"
>Format expected for examples:</span
>
{@html obj.tags.examples_format}
</p>
{/if}
{#if obj.tags.events && obj.tags.events.length > 0}
<p class="text-lg text-gray-500">
<span class="text-orange-500">Supported events:</span>
<em>{@html obj.tags.events}</em>
</p>
{/if}
{/if}
{#if obj.example}
<h4
class="mt-4 text-xl text-orange-500 font-light group"
id="{obj.name}-example-usage"
>
Example Usage
<a
href="#{obj.name}-example-usage"
class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<div class="codeblock">
<pre><code class="code language-python"
>{@html obj.highlighted_example}</code
></pre>
</div>
{/if}
{#if (obj.parameters.length > 0 && obj.parameters[0].name != "self") || obj.parameters.length > 1}
<h4
class="mt-6 text-xl text-orange-500 font-light group"
id="{obj.name}-initialization"
>
Initialization
<a
href="#{obj.name}-initialization"
class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<table class="table-fixed w-full leading-loose">
<thead class="text-left">
<tr>
<th class="px-3 pb-3 font-semibold w-2/5">Parameter</th>
<th class="px-3 pb-3 font-semibold">Description</th>
</tr>
</thead>
<tbody
class=" rounded-lg bg-gray-50 border border-gray-100 overflow-hidden text-left align-top divide-y"
>
{#each obj.parameters as param}
{#if param["name"] != "self"}
<tr
class="group hover:bg-gray-200/60 odd:bg-gray-100/80"
>
<td class="p-3 w-2/5 break-words">
<code class="block">
{param["name"]}
</code>
<p class="text-gray-500 italic">
{param["annotation"]}
</p>
{#if "default" in param}
<p class="text-gray-500 font-semibold">
default: {param["default"]}
</p>
{:else if !("kwargs" in param)}
<p class="text-orange-600 font-semibold italic">
required
</p>
{/if}
</td>
<td class="p-3 text-gray-700 break-words">
<p>{@html param["doc"] || ""}</p>
</td>
</tr>
{/if}
{/each}
</tbody>
</table>
{/if}
{#if mode === "components" && obj.string_shortcuts}
<table class="mb-4 table-fixed w-full mt-6">
<thead class="text-left">
<tr>
<th class="p-3 font-semibold w-2/5">Class</th>
<th class="p-3 font-semibold"
>Interface String Shortcut</th
>
<th class="p-3 font-semibold">Initialization</th>
</tr>
</thead>
<tbody
class="text-left divide-y rounded-lg bg-gray-50 border border-gray-100 overflow-hidden"
>
{#each obj.string_shortcuts as shortcut}
<tr class="group hover:bg-gray-200/60 odd:bg-gray-100/80">
<td class="p-3 w-2/5 break-words">
<p>
<code class="lang-python">gradio.{shortcut[0]}</code
>
</p>
</td>
<td class="p-3 w-2/5 break-words">
<p>"{shortcut[1]}"</p>
</td>
<td class="p-3 text-gray-700 break-words">
{shortcut[2]}
</td>
</tr>
{/each}
</tbody>
</table>
{/if}
{#if obj.fns && obj.fns.length > 0}
<h4 class="mt-4 p-3 font-semibold">Methods</h4>
<div class="flex flex-col gap-8 pl-12">
{#each obj.fns as fn}
<FunctionDoc {fn} />
{/each}
<div class="ml-12" />
</div>
{/if}
{#if obj.guides && obj.guides.length > 0}
<h4
class="mt-4 p-3 text-xl text-orange-500 font-light group"
id="guides"
>
Guides
<a href="#guides" class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<div
class="guides-list grid grid-cols-1 lg:grid-cols-4 gap-4 pb-3 px-3"
>
{#each obj.guides as guide, i}
<a
class="guide-box flex lg:col-span-1 flex-col group overflow-hidden relative rounded-xl shadow-sm hover:shadow-alternate transition-shadow bg-gradient-to-r {data
.COLOR_SETS[i][0]} {data.COLOR_SETS[i][1]}"
target="_blank"
href="..{guide.url}"
>
<div class="flex flex-col p-4 h-min">
<p class="group-hover:underline text-l">
{guide.pretty_name}
</p>
</div>
</a>
{/each}
</div>
{/if}
{#if obj.demos}
<div class="category my-8" id="examples">
<h4
class="text-xl text-orange-500 font-light group"
id="{obj.name}-demos"
>
Demos
<a
href="#{obj.name}-demos"
class="invisible group-hover-visible"
><img class="anchor-img-small" src={anchor} /></a
>
</h4>
<div>
<div class="demo-window overflow-y-auto h-full w-full mb-4">
<div
class="relative mx-auto my-auto rounded-md bg-white"
style="top: 5%; height: 90%"
>
<div class="flex overflow-auto pt-4">
{#each obj.demos as demo, i}
<button
on:click={() => (current_selection = i)}
class:selected-demo-tab={current_selection == i}
class="demo-btn px-4 py-2 text-lg min-w-max text-gray-600 hover:text-orange-500"
name={demo[0]}>{demo[0]}</button
>
{/each}
</div>
{#each obj.demos as demo, i}
<div
class:hidden={current_selection !== i}
class:selected-demo-window={current_selection == i}
class="demo-content px-4"
>
<Demos
name={demo[0]}
code={demo[1]}
highlighted_code={demo[2]}
{on_main}
/>
</div>
{/each}
</div>
</div>
</div>
</div>
{/if}
</div>
{/each}
</div>
</div>
<div class="lg:ml-10 flex justify-between my-4">
<a
href="./mount_gradio_app"
class="text-left px-4 py-1 bg-gray-50 rounded-full hover:underline"
>
<div class="text-lg">
<span class="text-orange-500">←</span> mount_gradio_app
</div>
</a>
<a
href="./themes"
class="text-right px-4 py-1 bg-gray-50 rounded-full hover:underline"
>
<div class="text-lg">
Themes <span class="text-orange-500">→</span>
</div>
</a>
</div>
</div>
<div
class="float-right top-8 hidden sticky h-screen overflow-y-auto lg:block lg:w-2/12"
>
<div class="mx-8">
<a class="thin-link py-2 block text-lg" href="#flagging">Flagging</a>
{#if headers.length > 0}
<ul class="text-slate-700 text-lg leading-6">
{#each headers as header}
<li>
<a
bind:this={header_targets[header[1]]}
href="#{header[1]}"
class="thin-link block py-2 font-light second-nav-link"
>{header[0]}</a
>
</li>
{/each}
{#if method_headers.length > 0}
{#each method_headers as method_header}
<li class="ml-4">
<a
href="#{method_header[1]}"
class="thin-link block py-2 font-light second-nav-link"
>{method_header[0]}</a
>
</li>
{/each}
{/if}
</ul>
{/if}
</div>
</div>
</div>
</main>
|