Skip to content

Commit 530f8a0

Browse files
authored
chatbot component tweaks (#8594)
1 parent d35c290 commit 530f8a0

34 files changed

+721
-361
lines changed

.changeset/clear-cloths-dream.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@gradio/audio": patch
3+
"@gradio/chatbot": patch
4+
"@gradio/gallery": patch
5+
"@gradio/icons": patch
6+
"@gradio/image": patch
7+
"@gradio/plot": patch
8+
"@gradio/video": patch
9+
"@gradio/wasm": patch
10+
"gradio": patch
11+
---
12+
13+
fix:chatbot component tweaks

.config/playwright.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const base = defineConfig({
1919
timeout: 30000,
2020
testMatch: /.*\.spec\.ts/,
2121
testDir: "..",
22-
workers: process.env.CI ? 1 : undefined,
22+
workers: 1,
2323
retries: 3
2424
});
2525

demo/chatbot_core_components/run.ipynb

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

demo/chatbot_core_components/run.py

+50-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,48 @@
55

66
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
77

8+
txt = """
9+
Absolutely! The mycorrhizal network, often referred to as the "Wood Wide Web," is a symbiotic association between fungi and the roots of most plant species. Here’s a deeper dive into how it works and its implications:
10+
11+
### How It Works
12+
13+
1. **Symbiosis**: Mycorrhizal fungi attach to plant roots, extending far into the soil. The plant provides the fungi with carbohydrates produced via photosynthesis. In return, the fungi help the plant absorb water and essential nutrients like phosphorus and nitrogen from the soil.
14+
15+
2. **Network Formation**: The fungal hyphae (thread-like structures) connect individual plants, creating an extensive underground network. This network can link many plants together, sometimes spanning entire forests.
16+
17+
3. **Communication**: Trees and plants use this network to communicate and share resources. For example, a tree under attack by pests can send chemical signals through the mycorrhizal network to warn neighboring trees. These trees can then produce defensive chemicals to prepare for the impending threat.
18+
19+
### Benefits and Functions
20+
21+
1. **Resource Sharing**: The network allows for the redistribution of resources among plants. For instance, a large, established tree might share excess nutrients and water with smaller, younger trees, promoting overall forest health.
22+
23+
2. **Defense Mechanism**: The ability to share information about pests and diseases enhances the resilience of plant communities. This early warning system helps plants activate their defenses before they are directly affected.
24+
25+
3. **Support for Seedlings**: Young seedlings, which have limited root systems, benefit immensely from the mycorrhizal network. They receive nutrients and water from larger plants, increasing their chances of survival and growth.
26+
27+
### Ecological Impact
28+
29+
1. **Biodiversity**: The mycorrhizal network supports biodiversity by fostering a cooperative environment. Plants of different species can coexist and thrive because of the shared resources and information.
30+
31+
2. **Forest Health**: The network enhances the overall health of forests. By enabling efficient nutrient cycling and supporting plant defenses, it contributes to the stability and longevity of forest ecosystems.
32+
33+
3. **Climate Change Mitigation**: Healthy forests act as significant carbon sinks, absorbing carbon dioxide from the atmosphere. The mycorrhizal network plays a critical role in maintaining forest health and, consequently, in mitigating climate change.
34+
35+
### Research and Discoveries
36+
37+
1. **Suzanne Simard's Work**: Ecologist Suzanne Simard’s research has been pivotal in uncovering the complexities of the mycorrhizal network. She demonstrated that trees of different species can share resources and that "mother trees" (large, older trees) play a crucial role in nurturing younger plants.
38+
39+
2. **Implications for Conservation**: Understanding the mycorrhizal network has significant implications for conservation efforts. It highlights the importance of preserving not just individual trees but entire ecosystems, including the fungal networks that sustain them.
40+
41+
### Practical Applications
42+
43+
1. **Agriculture**: Farmers and horticulturists are exploring the use of mycorrhizal fungi to improve crop yields and soil health. By incorporating these fungi into agricultural practices, they can reduce the need for chemical fertilizers and enhance plant resilience.
44+
45+
2. **Reforestation**: In reforestation projects, introducing mycorrhizal fungi can accelerate the recovery of degraded lands. The fungi help establish healthy plant communities, ensuring the success of newly planted trees.
46+
47+
The "Wood Wide Web" exemplifies the intricate and often hidden connections that sustain life on Earth. It’s a reminder of the profound interdependence within natural systems and the importance of preserving these delicate relationships.
48+
"""
49+
850

951
def random_plot():
1052
df = px.data.iris()
@@ -28,7 +70,7 @@ def random_plot():
2870

2971
def html_src(harm_level):
3072
return f"""
31-
<div style="display: flex; gap: 5px;padding: 2px 4px;margin-top: -40px">
73+
<div style="display: flex; gap: 5px;">
3274
<div style="background-color: {color_map[harm_level]}; padding: 2px; border-radius: 5px;">
3375
{harm_level}
3476
</div>
@@ -149,7 +191,7 @@ def bot(history, response_type):
149191
html_src(random.choice(["harmful", "neutral", "beneficial"]))
150192
)
151193
else:
152-
history[-1][1] = "Cool!"
194+
history[-1][1] = txt
153195
return history
154196

155197

@@ -160,6 +202,12 @@ def bot(history, response_type):
160202
elem_id="chatbot",
161203
bubble_full_width=False,
162204
scale=1,
205+
show_copy_button=True,
206+
avatar_images=(
207+
None, # os.path.join("files", "avatar.png"),
208+
os.path.join("files", "avatar.png"),
209+
),
210+
# layout="panel",
163211
)
164212
response_type = gr.Radio(
165213
[

js/audio/player/AudioPlayer.svelte

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
pause: undefined;
4646
edit: undefined;
4747
end: undefined;
48+
load: undefined;
4849
}>();
4950
5051
const create_waveform = (): void => {
@@ -98,6 +99,10 @@
9899
dispatch("play");
99100
});
100101
102+
$: waveform?.on("load", () => {
103+
dispatch("load");
104+
});
105+
101106
const handle_trim_audio = async (
102107
start: number,
103108
end: number
@@ -149,6 +154,7 @@
149154
src={value.url}
150155
controls
151156
autoplay={waveform_settings.autoplay}
157+
on:load
152158
/>
153159
{:else}
154160
<div

js/audio/static/StaticAudio.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
on:pause
7171
on:play
7272
on:stop
73+
on:load
7374
/>
7475
{:else}
7576
<Empty size="small">

js/chatbot/Index.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
export let likeable = false;
3232
export let show_share_button = false;
3333
export let rtl = false;
34-
export let show_copy_button = false;
34+
export let show_copy_button = true;
3535
export let sanitize_html = true;
3636
export let bubble_full_width = true;
3737
export let layout: "bubble" | "panel" = "bubble";
@@ -88,7 +88,7 @@
8888
<BlockLabel
8989
{show_label}
9090
Icon={Chat}
91-
float={false}
91+
float={true}
9292
label={label || "Chatbot"}
9393
/>
9494
{/if}

js/chatbot/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@gradio/theme": "workspace:^",
1818
"@gradio/upload": "workspace:^",
1919
"@gradio/utils": "workspace:^",
20+
"@gradio/wasm": "workspace:^",
2021
"@types/dompurify": "^3.0.2",
2122
"@types/katex": "^0.16.0",
2223
"@types/prismjs": "1.26.4",

js/chatbot/shared/ButtonPanel.svelte

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<script lang="ts">
2+
import LikeDislike from "./LikeDislike.svelte";
3+
import Copy from "./Copy.svelte";
4+
import type { FileData } from "@gradio/client";
5+
import DownloadIcon from "./Download.svelte";
6+
import { DownloadLink } from "@gradio/wasm/svelte";
7+
8+
export let likeable: boolean;
9+
export let show_copy_button: boolean;
10+
export let show: boolean;
11+
export let message: Record<string, any>;
12+
export let position: "right" | "left";
13+
export let avatar: FileData | null;
14+
export let show_download = false;
15+
export let handle_action: (selected: string | null) => void;
16+
export let layout: "bubble" | "panel";
17+
18+
$: show_copy = show_copy_button && message && message?.type === "text";
19+
$: show_download =
20+
(show_download && message?.value?.video?.url) || message?.value?.url;
21+
</script>
22+
23+
{#if show}
24+
<div
25+
class="message-buttons-{position} {layout} message-buttons {avatar !==
26+
null && 'with-avatar'}"
27+
>
28+
{#if show_copy}
29+
<Copy value={message.value} />
30+
{/if}
31+
{#if show_download}
32+
<DownloadLink
33+
href={message?.value?.video?.url || message?.value?.url}
34+
download={message?.value?.video?.orig_name ||
35+
message.value.orig_name ||
36+
"image"}
37+
>
38+
<span class="icon-wrap">
39+
<DownloadIcon />
40+
</span>
41+
</DownloadLink>
42+
{/if}
43+
{#if likeable && position === "left"}
44+
<LikeDislike {handle_action} padded={show_copy || show_download} />
45+
{/if}
46+
</div>
47+
{/if}
48+
49+
<style>
50+
.icon-wrap {
51+
display: block;
52+
color: var(--body-text-color-subdued);
53+
}
54+
55+
.icon-wrap:hover {
56+
color: var(--body-text-color);
57+
}
58+
.message-buttons-right,
59+
.message-buttons-left {
60+
border-radius: var(--radius-md);
61+
display: flex;
62+
align-items: center;
63+
bottom: 0;
64+
height: var(--size-7);
65+
align-self: self-end;
66+
/* position: absolute; */
67+
bottom: -15px;
68+
margin: 2px;
69+
padding-left: 5px;
70+
z-index: 1;
71+
padding-bottom: var(--spacing-xl);
72+
padding: var(--spacing-md) 2px;
73+
}
74+
.message-buttons-left {
75+
align-self: start;
76+
left: 0px;
77+
}
78+
.message-buttons-right {
79+
right: 5px;
80+
}
81+
82+
.panel.message-buttons-left,
83+
.panel.message-buttons-right {
84+
margin: 10px 0 2px 0;
85+
}
86+
87+
.message-buttons {
88+
left: 0px;
89+
right: 0px;
90+
top: unset;
91+
bottom: calc(-30px - var(--spacing-xl));
92+
display: flex;
93+
justify-content: flex-start;
94+
align-items: center;
95+
gap: 0px;
96+
}
97+
98+
.message-buttons :global(> *) {
99+
margin-right: 7px;
100+
}
101+
</style>

0 commit comments

Comments
 (0)