You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reaching out because I'm experiencing an issue when trying to load external .css files into a Gradio Blocks interface. While inline CSS styles work correctly, external CSS files do not seem to be applied, regardless of the method I use to reference them.
Notably, this issue did not occur in previous versions of Gradio; the same code used to work as expected before updating to the latest version.
I previously encountered a similar situation in issue #884, where I had trouble displaying an image inside the gr.HTML component. I understand that managing all the nuances of such a versatile tool can be challenging, and I genuinely appreciate your efforts to address these issues.
Have you searched existing issues? 🔎
I have searched and found no existing issues
Reproduction
Create a Simple Gradio App with External CSS (This Does Not Work):
importgradioasgrdefcreate_gradio_interface():
withgr.Blocks() asdemo:
gr.HTML(""" <link rel="stylesheet" href="style.css"> <div class="custom-component"> <h1>Custom Component</h1> <p>This paragraph should be styled by external CSS.</p> </div> """)
returndemoif__name__=="__main__":
gradio_app=create_gradio_interface()
gradio_app.launch(allowed_paths=["."])
@abidlabs, is there a way to directly reference the original .css files rather than merging them all into css_paths? The current setup causes an issue when multiple .css files use the same component names but are meant for different .html files. Instead of each component applying its intended styles, the CSS classes are overridden by the next .css file in css_paths. This makes it difficult to maintain specific styles across different components. Any advice on selectively applying CSS files or perhaps a way to scope the styles to avoid conflicts?
Example
Let's say we have two .css files: style1.css and style2.css, both with a .button class:
Here, we expect page1.html to show a blue button and page2.html to show a green button. However, when both styles are added via css_paths, only the style2.css button style is applied across both pages.
importgradioasgrwithgr.Blocks(css=("style1.css", "style2.css")) asdemo:
gr.HTML(""" <link rel='stylesheet' href='style1.css'> <button class='button'>Button styled with style1.css</button> """)
# Button with style2.css appliedgr.HTML(""" <link rel='stylesheet' href='style2.css'> <button class='button'>Button styled with style2.css</button> """)
However, the current setup applies the .button style from style2.css to both buttons, since the styles in css_paths are globally merged. A way to scope each CSS file to its specific component would help retain unique styles for each button.
Describe the bug
Hello Gradio Team,
I'm reaching out because I'm experiencing an issue when trying to load external
.css
files into a GradioBlocks
interface. While inline CSS styles work correctly, external CSS files do not seem to be applied, regardless of the method I use to reference them.Notably, this issue did not occur in previous versions of Gradio; the same code used to work as expected before updating to the latest version.
I previously encountered a similar situation in issue #884, where I had trouble displaying an image inside the
gr.HTML
component. I understand that managing all the nuances of such a versatile tool can be challenging, and I genuinely appreciate your efforts to address these issues.Have you searched existing issues? 🔎
Reproduction
Create a Simple Gradio App with External CSS (This Does Not Work):
Create an External CSS File (
style.css
):style.css
file is located in the same directory as the Python script.Test with Inline CSS (This Works):
<style>
tags works as expected.Expected Behavior
style.css
should be loaded, and the styles should be applied to the HTML elements within the Gradio interface.Actual Behavior
<link rel="stylesheet" href="style.css">
.<style>
tags works correctly.404
error.Screenshot
Troubleshooting Steps Taken
I have tested the following methods and configurations:
Verified File Paths:
href
matches the actual location ofstyle.css
.href
attribute./file=./style.css
in thehref
.Used
allowed_paths
inlaunch()
:allowed_paths=["."]
togradio_app.launch()
.style.css
inallowed_paths
.Logs
No response
System Info
Gradio Version:
Current version where the issue occurs: 4.44.0 with client 1.3.0
Previous version where this worked: 4.25.0 with client 0.15.0
Python Version: 3.12.5
Operating System: Ubuntu 22.04
Browser: Google Chrome 129.0.6668.90 and Firefox 128.3.0esr
Severity
Blocking usage of gradio
The text was updated successfully, but these errors were encountered: