Repository: gradio-app/gradio

Issue:
UI not displaying correctly because of path to `theme.css`
### Describe the bug

The UI displays correctly on the local system. But when I upload it to the server, the UI CSS is not present. 

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

     NA

### Screenshot

<img width="1440" alt="Screenshot 2023-03-15 at 12 23 45 AM" src="https://user-images.githubusercontent.com/71621292/225127688-2ce7189c-70f5-44c4-bce7-ee96040967a6.png">


### Logs

```shell
No logs. Only a 404 error.
```


### System Info

```shell
This is hosted on railway.app.
```


### Severity

annoying


Discussion:
Here's the URL:
https://fastapi-production-72d5.up.railway.app/answer-ui/
I'm not super familiar with Railway but it seems like the problem is that Gradio needs access to `/theme.css` to load the CSS, and either this file is missing from the Railway app, or Railway is blocking this file
I tried loading the thing on a different account and it seems to be working. But it's only this account for some reason. Do you know how I can get this sorted?
> I'm not super familiar with Railway but it seems like the problem is that Gradio needs access to `/theme.css` to load the CSS, and either this file is missing from the Railway app, or Railway is blocking this file

Is there any way I can index the theme directly in the code?
> I tried loading the thing on a different account and it seems to be working. But it's only this account for some reason. Do you know how I can get this sorted?

It works on a different Railway app? Then it doesn't sound like a Gradio issue, it sounds like an issue with Railway, no?

> Is there any way I can index the theme directly in the code?

I don't think so. cc @aliabid94 for your thoughts
Yes, you're right. It's probably an issue with them. But is there any CDN that I can use to index the theme.css file?
@aliabid94 
No the theme.css file is creating specifically for your app and it might differ from app to app, so it wouldn't be available on a CDN. I'm going to close this issue as it doesn't seem related to Gradio, but rather Railway. If you could reach out to them and see how to serve a static css file, that should solve the issue you're seeing. 
It looks gradios's bug.

I ran into the same problem while trying the following case:

```python
app = gr.mount_gradio_app(app, io, path="/gradio")
```

This is an example of incorporating FastAPI into any of the FastAPI routes listed in the documentation.

https://gradio.app/docs/#mount_gradio_app

For some reason, the front end assumes that theme.css is directly under root and tries to load it, but in fact `/gradio/theme.css` is served.
Ah, thanks @hinaloe for the heads up. cc @aliabid94 we should resolve this before releasing themes

Resolving patch:
diff --git a/gradio/blocks.py b/gradio/blocks.py
--- a/gradio/blocks.py
+++ b/gradio/blocks.py
@@ -71,6 +71,7 @@ def __init__(
         self._skip_init_processing = _skip_init_processing
         self._style = {}
         self.parent: BlockContext | None = None
+        self.root = ""
 
         if render:
             self.render()
@@ -1102,6 +1103,7 @@ def get_config_file(self):
             "show_error": getattr(self, "show_error", False),
             "show_api": self.show_api,
             "is_colab": utils.colab_check(),
+            "root": self.root
         }
 
         def getLayout(block):
diff --git a/gradio/routes.py b/gradio/routes.py
--- a/gradio/routes.py
+++ b/gradio/routes.py
@@ -755,6 +755,7 @@ def read_main():
         # Then run `uvicorn run:app` from the terminal and navigate to http://localhost:8000/gradio.
     """
     blocks.dev_mode = False
+    blocks.root = path[:-1] if path.endswith("/") else path
     blocks.config = blocks.get_config_file()
     gradio_app = App.create_app(blocks)
 


Test patch: