Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reloads break when loading external CSS #8192

Closed
1 task done
jameszhou02 opened this issue May 1, 2024 · 6 comments 路 Fixed by #8194
Closed
1 task done

Hot reloads break when loading external CSS #8192

jameszhou02 opened this issue May 1, 2024 · 6 comments 路 Fixed by #8194
Labels
bug Something isn't working Regression Bugs did not exist in previous versions of Gradio

Comments

@jameszhou02
Copy link
Contributor

Describe the bug

When launching a gradio app with hot reloading, the initial load works but subsequent changes to CSS files and components using external CSS break the hot reload.

Have you searched existing issues? 馃攷

  • I have searched and found no existing issues

Reproduction

test.py

import gradio as gr
import os

STYLES_PATH = os.path.join(os.path.dirname(__file__), "styles.css")

with gr.Blocks(
    css=STYLES_PATH,
) as test_demo:
    with gr.Blocks():
        gr.Markdown(
            """
            ## Hello world
            """
        )

if __name__ == "__main__":
    test_demo.launch()

styles.css

html {
  background-color: white;
}

Run command: gradio test.py --demo-name=test_demo

Then change background-color to any other color, or add own CSS.

Screenshot

No response

Logs

Error output (path is just placeholder for where I was testing this python script):

gradio test.py --demo-name=test_demo
Watching: '[path]' '[path]'

Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.

Changes detected in: [path]/styles.css
Reloading test failed with the following exception:
Traceback (most recent call last):
  File "/Users/james/anaconda3/lib/python3.10/site-packages/gradio/utils.py", line 264, in watchfn
    changed_in_copy = _remove_no_reload_codeblocks(str(changed))
  File "/Users/james/anaconda3/lib/python3.10/site-packages/gradio/utils.py", line 173, in _remove_no_reload_codeblocks
    tree = ast.parse(code)
  File "/Users/james/anaconda3/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    html {
         ^
SyntaxError: invalid syntax


### System Info

```shell
gradio version: 4.28.3
python version: 3.10.13

Severity

I can work around it

@jameszhou02 jameszhou02 added the bug Something isn't working label May 1, 2024
@jameszhou02
Copy link
Contributor Author

Same error with python version: 3.11.7

@freddyaboulton
Copy link
Collaborator

Thanks @jameszhou02 ! This should be a straightforward fix. We need to skip lines 264 to 272 in this file if the source file that changed is not a python file.

Would you like to open a PR?

@freddyaboulton freddyaboulton added the Regression Bugs did not exist in previous versions of Gradio label May 2, 2024
@jameszhou02
Copy link
Contributor Author

On it!

@jameszhou02
Copy link
Contributor Author

jameszhou02 commented May 2, 2024

Submitted a PR that's passing all tests here: #8194

Was running into local issues when messing w/ hot-reloading but they're really minor. Essentially changes are detected but when the hot reload occurs seems to be dynamic. Here's a video of what was happening---wasn't sure if this is the intended behavior because it seems inconsistent.

Screen.Recording.2024-05-01.at.7.46.20.PM.mov

@freddyaboulton
Copy link
Collaborator

Hmm I think that may be an unrelated bug. Will review your PR shortly

@freddyaboulton
Copy link
Collaborator

Hi @jameszhou02 , that issue you saw where the textbox value was not updated in reload mode has been fixed in #8227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Regression Bugs did not exist in previous versions of Gradio
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants