Fix bug displaying dataframe examples in csv/tsv files (#2877)

* Use loaded value for dataframe preview

* Add to CHANGELOG

* Changelog
This commit is contained in:
Freddy Boulton 2022-12-27 10:48:32 -05:00 committed by GitHub
parent 571e5eb66c
commit 6b77ea07d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -5,6 +5,7 @@
## Bug Fixes:
* Fixed bug where setting `default_enabled=False` made it so that the entire queue did not start by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2876](https://github.com/gradio-app/gradio/pull/2876)
* Fixed bug where csv preview for DataFrame examples would show filename instead of file contents by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2877](https://github.com/gradio-app/gradio/pull/2877)
* Fixed bug where an error raised after yielding iterative output would not be displayed in the browser by
[@JaySmithWpg](https://github.com/JaySmithWpg) in [PR 2889](https://github.com/gradio-app/gradio/pull/2889)
@ -21,7 +22,8 @@ No changes to highlight.
* The `default_enabled` parameter of the `Blocks.queue` method has no effect by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2876](https://github.com/gradio-app/gradio/pull/2876)
## Contributors Shoutout:
No changes to highlight.
* @JaySmithWpg for making their first contribution to gradio!
* @MohamedAliRashad for making their first contribution to gradio!
# Version 3.15.0

View File

@ -4,7 +4,8 @@
export let value: Array<Array<string | number>> | string;
export let samples_dir: string;
let hovered = false;
let loaded = Array.isArray(value);
let loaded_value: Array<Array<string | number>> | string = value;
let loaded = Array.isArray(loaded_value);
$: if (!loaded && typeof value === "string" && /\.[a-zA-Z]+$/.test(value)) {
fetch(samples_dir + value)
@ -18,7 +19,7 @@
.map((v) => v.split(",").slice(0, 4).join(","))
.join("\n");
value = csvParseRows(small_df);
loaded_value = csvParseRows(small_df);
} else if ((value as string).endsWith("tsv")) {
const small_df = v
.split("\n")
@ -26,7 +27,7 @@
.map((v) => v.split("\t").slice(0, 4).join("\t"))
.join("\n");
value = tsvParseRows(small_df);
loaded_value = tsvParseRows(small_df);
} else {
throw new Error(
"Incorrect format, only CSV and TSV files are supported"
@ -48,7 +49,7 @@
on:mouseleave={() => (hovered = false)}
>
<table class="gr-sample-dataframe relative">
{#each value.slice(0, 3) as row, i}
{#each loaded_value.slice(0, 3) as row, i}
<tr>
{#each row.slice(0, 3) as cell, j}
<td