The error you're encountering is a DuplicateBlockError, which typically happens when Gradio tries to render the same block twice in a single interface. In this case, it seems that you are attempting to render a block (a UI element like a slider or a text box) more than once, or there is some other conflict involving duplicated IDs for components.

Here’s what you can do to resolve it:

Key Points from the Error:

DuplicateBlockError: This indicates that a block (like a slider, button, etc.) with the same ID has already been rendered in your Gradio Blocks interface.
The specific block ID mentioned is 11, which suggests the same block is being rendered twice.

Potential Fix:

You should ensure that each block in Gradio is only rendered once and that each component (like sliders) is defined uniquely and not repeated across different parts of the UI.

Steps to fix this:

Check for Duplicate IDs: Ensure that each block, slider, button, or any other UI component has a unique ID and that none are repeated or re-rendered. You can add sliders separately for each tab to ensure the settings are independent, but you need to avoid rendering the same slider in multiple places.

Refactor Sliders to be Tab-Specific: Since you want the sliders to operate independently for each tab (and have different base values), make sure that the sliders are defined inside each tab block, not reused across multiple tabs.

Key Changes:

Unique Sliders in Each Tab:

Sliders are now defined uniquely within each tab, each with its own Max New Tokens and Temperature settings, ensuring they do not interfere with each other and are rendered only once in their respective tab.

Ensuring Unique Block IDs:

Blocks (like sliders, buttons, textboxes) are instantiated only once and separately for each tab, which resolves the duplicate block rendering issue.
Temperature and max token logic is passed correctly in the generate function.

The new code is shorter for a few reasons:

Simplified Slider Definitions: In the original code, the sliders for Max New Tokens and Temperature were defined once outside the tabs and reused in multiple places, which led to errors. In the revised code, each tab has its own sliders directly defined within that tab, which not only eliminates redundancy but also allows for unique sliders without additional references to those sliders in external logic.

No External Block Rendering: In the original code, sliders were rendered separately from the tabs and later referenced in multiple parts of the interface. In the updated code, the sliders are now embedded directly inside each tab, so there’s no need for separate references outside. This reduces the total number of lines required to handle and reuse the same sliders in multiple contexts.

Removed Duplicated Code: The new version eliminates any potential duplication, like the reused blocks or render calls that might have been unnecessary in the old code. Each component (textbox, button, slider) is now defined exactly where it’s used. The explicit render() calls in the original code for the sliders may have been duplicated, which added lines.

Cleaner Layout for Independent Controls: By making each tab handle its own slider separately, the code avoids managing references between different UI elements across tabs. This design makes the interface code more straightforward and thus shorter.

More Efficient Function Calls: The click event handlers in each tab are now simpler because they are directly tied to the UI elements in that tab (like sliders or textboxes), so no need to reference shared global objects, which was likely causing some overhead in the previous code.

Addaci changed pull request status to merged

Sign up or log in to comment