-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix logic for detecting changes in
gr.Dataframe
table value (#10360)
* changes * changes * changes * add changeset * revert * add changeset * change * changes * add changeset * add changeset * allow non-string headers * add changeset * changes * docs * remove * changes * changes * revert * refactoring * changes * changes * revert * revert * add changeset * fix * add changeset * clean up * cleanup * more cleanup * notebook * test * format * add changeset * backend * format' * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
- Loading branch information
1 parent
40e0c48
commit 31cccc3
Showing
8 changed files
with
106 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@gradio/dataframe": patch | ||
"gradio": patch | ||
--- | ||
|
||
fix:Fix logic for detecting changes in `gr.Dataframe` table value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: dataframe_streaming"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import time\n", "\n", "def update_dataframe(df):\n", " df.iloc[:, :] = 1\n", " yield df, 1\n", " time.sleep(0.1)\n", " df.iloc[:, :] = 2\n", " yield df, 2\n", "\n", "initial_df = pd.DataFrame(0, index=range(5), columns=range(5))\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " button = gr.Button(\"Update DataFrame\")\n", " number = gr.Number(value=0, label=\"Number\")\n", " dataframe = gr.Dataframe(value=initial_df, label=\"Dataframe\")\n", " button.click(fn=update_dataframe, inputs=dataframe, outputs=[dataframe, number])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import gradio as gr | ||
import pandas as pd | ||
import time | ||
|
||
def update_dataframe(df): | ||
df.iloc[:, :] = 1 | ||
yield df, 1 | ||
time.sleep(0.1) | ||
df.iloc[:, :] = 2 | ||
yield df, 2 | ||
|
||
initial_df = pd.DataFrame(0, index=range(5), columns=range(5)) | ||
|
||
with gr.Blocks() as demo: | ||
with gr.Row(): | ||
button = gr.Button("Update DataFrame") | ||
number = gr.Number(value=0, label="Number") | ||
dataframe = gr.Dataframe(value=initial_df, label="Dataframe") | ||
button.click(fn=update_dataframe, inputs=dataframe, outputs=[dataframe, number]) | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { test, expect } from "@self/tootils"; | ||
|
||
test("DataFrame updates correctly when button is clicked", async ({ page }) => { | ||
await page.getByRole("button", { name: "Update DataFrame" }).click(); | ||
await expect( | ||
page.getByRole("table", { name: "Dataframe" }).locator("td").first() | ||
).toHaveText("2"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters