Skip to content

Commit f0cf3b7

Browse files
dawoodkhan82gradio-pr-botabidlabs
authored
Dataframe support in Chatbot (#10225)
* dataframe * dataframe * remove console log * add changeset * datatype * fix border * Update js/chatbot/shared/Component.svelte Co-authored-by: Abubakar Abid <[email protected]> * border fix --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]>
1 parent 9bdec8c commit f0cf3b7

File tree

7 files changed

+55
-9
lines changed

7 files changed

+55
-9
lines changed

.changeset/long-months-wave.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/chatbot": minor
3+
"gradio": minor
4+
---
5+
6+
feat:Dataframe support in Chatbot

demo/chatbot_core_components/run.ipynb

+1-1
Large diffs are not rendered by default.

demo/chatbot_core_components/run.py

+10
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def bot(history, response_type):
166166
content = gr.Gallery(
167167
[os.path.join("files", "avatar.png"), os.path.join("files", "avatar.png")]
168168
)
169+
elif response_type == "dataframe":
170+
content = gr.Dataframe(
171+
interactive=True,
172+
headers=["One", "Two", "Three"],
173+
col_count=(3, "fixed"),
174+
row_count=(3, "fixed"),
175+
value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
176+
label="Dataframe",
177+
)
169178
elif response_type == "image":
170179
content = gr.Image(os.path.join("files", "avatar.png"))
171180
elif response_type == "video":
@@ -216,6 +225,7 @@ def bot(history, response_type):
216225
"image",
217226
"text",
218227
"gallery",
228+
"dataframe",
219229
"video",
220230
"audio",
221231
"html",

js/chatbot/shared/ChatBot.svelte

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@
405405
}
406406
407407
/* table styles */
408-
.message-wrap :global(.bot table),
409-
.message-wrap :global(.bot tr),
410-
.message-wrap :global(.bot td),
411-
.message-wrap :global(.bot th) {
408+
.message-wrap :global(.bot:not(:has(.table-wrap)) table),
409+
.message-wrap :global(.bot:not(:has(.table-wrap)) tr),
410+
.message-wrap :global(.bot:not(:has(.table-wrap)) td),
411+
.message-wrap :global(.bot:not(:has(.table-wrap)) th) {
412412
border: 1px solid var(--border-color-primary);
413413
}
414414

js/chatbot/shared/Component.svelte

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<script lang="ts">
2-
export let type: "gallery" | "plot" | "audio" | "video" | "image" | string;
2+
export let type:
3+
| "gallery"
4+
| "plot"
5+
| "audio"
6+
| "video"
7+
| "image"
8+
| "dataframe"
9+
| string;
310
export let components;
411
export let value;
512
export let target;
@@ -27,6 +34,24 @@
2734
fixed_height={1}
2835
on:load
2936
/>
37+
{:else if type === "dataframe"}
38+
<svelte:component
39+
this={components[type]}
40+
{value}
41+
show_label={false}
42+
{i18n}
43+
label=""
44+
interactive={false}
45+
line_breaks={props.line_breaks}
46+
wrap={true}
47+
root=""
48+
gradio={{ dispatch: () => {} }}
49+
datatype={props.datatype}
50+
latex_delimiters={props.latex_delimiters}
51+
col_count={props.col_count}
52+
row_count={props.row_count}
53+
on:load
54+
/>
3055
{:else if type === "plot"}
3156
<svelte:component
3257
this={components[type]}

js/chatbot/shared/Message.svelte

+6
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@
352352
text-align: right;
353353
}
354354
355+
.bot:has(.table-wrap) {
356+
border: none;
357+
box-shadow: none;
358+
background: none;
359+
}
360+
355361
.panel .user :global(*) {
356362
text-align: right;
357363
}

js/chatbot/shared/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,12 @@ export async function load_components(
228228
if (_components[component_name] || component_name === "file") {
229229
return;
230230
}
231-
232-
const { name, component } = load_component(component_name, "base");
231+
const variant = component_name === "dataframe" ? "component" : "base";
232+
const { name, component } = load_component(component_name, variant);
233233
names.push(name);
234234
components.push(component);
235235
component_name;
236236
});
237-
238237
const loaded_components: LoadedComponent[] = await Promise.all(components);
239238
loaded_components.forEach((component, i) => {
240239
_components[names[i]] = component.default;

0 commit comments

Comments
 (0)