# I try to embed a gradio interface in an HTML using FastAPI

**URL:** <https://discuss.huggingface.co/t/i-try-to-embed-a-gradio-interface-in-an-html-using-fastapi/142853>\
**Category:** Beginners\
**Created:** [February 25, 2025, 1:21pm UTC](https://discuss.huggingface.co/t/i-try-to-embed-a-gradio-interface-in-an-html-using-fastapi/142853 "2025-02-25T13:21:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanOcian](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/danocian/32/41945_2.png) [@DanOcian](https://discuss.huggingface.co/u/DanOcian)\
**Post date:** [February 25, 2025, 1:21pm UTC](https://discuss.huggingface.co/t/i-try-to-embed-a-gradio-interface-in-an-html-using-fastapi/142853/1 "2025-02-25T13:21:36Z")

</div>

WHen i try to embed the gradio interface in an HTML iframe and i call it i’m getting the error:  
File “C:\Users\docian\PycharmProjects\medical\_assistant\venv\lib\site-packages\fastapi\routing.py”, line 301, in app  
raw\_response = await run\_endpoint\_function(  
File “C:\Users\docian\PycharmProjects\medical\_assistant\venv\lib\site-packages\fastapi\routing.py”, line 212, in run\_endpoint\_function  
return await dependant.call(\*\*values)  
File “C:\Users\docian\PycharmProjects\medical\_assistant\venv\lib\site-packages\gradio\routes.py”, line 1066, in queue\_join  
return await queue\_join\_helper(body, request, username)  
File “C:\Users\docian\PycharmProjects\medical\_assistant\venv\lib\site-packages\gradio\routes.py”, line 1084, in queue\_join\_helper  
success, event\_id = await blocks.\_queue.push(  
File “C:\Users\docian\PycharmProjects\medical\_assistant\venv\lib\site-packages\gradio\queueing.py”, line 240, in push  
async with self.pending\_message\_lock:  
AttributeError: **aenter**

i have no clue what’s the matter. that interface exposed alone works like charm

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 25, 2025, 1:36pm UTC](https://discuss.huggingface.co/t/i-try-to-embed-a-gradio-interface-in-an-html-using-fastapi/142853/2 "2025-02-25T13:36:10Z")

</div>

Hmm, that’s difficult. If you can ask questions on the Gradio-question channel on HF Discord, I recommend that. It seems that there are developers there.

> <https://github.com/gradio-app/gradio/issues/1608>
>
> I am making a single fastapi app where one route leads to prediction, and a seco…nd route which leads to the gradio interface. My understanding is that gradio itself launches a fastapi instance. is it possible to achieve this?

> <https://github.com/gradio-app/gradio/issues/7174>
>
> \### Describe the bug
> 
> Related to existing issues:
> https://github.com/gradio-app…/gradio/issues/3472
> https://github.com/gradio-app/gradio/issues/4352
> 
> In my understanding, the two sample apps should have exactly the same behavior, with the \`/gradio/\` path leading to the Gradio app, but there's a slight difference: the first example also makes the root \`/\` serve the same Gradio app, it's as if it was equivalent to both:
> \`\`\`py
> app = gr.mount\_gradio\_app(app, io)
> app = gr.mount\_gradio\_app(app, io, path="/gradio")
> \`\`\`
> This difference leads to an error in CSS file loading only appearing in the second app:
> \<img width="585" alt="sample1" src="https://github.com/gradio-app/gradio/assets/1531031/915a2f3c-5380-4930-a8e7-5daf3c1c1276"\>
> \<img width="587" alt="sample2" src="https://github.com/gradio-app/gradio/assets/1531031/7e817eed-e138-47c7-80a8-667de6732b9f"\>
> 
> The file appears to be loaded two times, once in the HTML (\`\<link rel="stylesheet" href="./assets/index-20519b4d.css"\>\`), and then again in the web component's \`connectedCallback\` (\`await mount\_css(ENTRY\_CSS, document.head)\`).
> 
> Since \`ENTRY\_CSS\` is defined to './assets/index-20519b4d.css', what ends up happening is that the first time the correct path is loaded \`/gradio/assets/index-20519b4d.css\`, but the second time, the incorrect path is attempted \`/assets/index-20519b4d.css\`, succeeding in the vanilla Gradio app, but failing in the one with a custom FastAPI instance.
> 
> \### Have you searched existing issues? 🔎
> 
> \- \[X\] I have searched and found no existing issues
> 
> \### Reproduction
> 
> \`\`\`python
> import gradio as gr
> 
> io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
> io.launch(root\_path="/gradio")
> \`\`\`
> 
> vs
> 
> \`\`\`python
> from fastapi import FastAPI
> import gradio as gr
> 
> app = FastAPI()
> 
> io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
> app = gr.mount\_gradio\_app(app, io, path="/gradio")
> \`\`\`
> 
> \### Screenshot
> 
> \_No response\_
> 
> \### Logs
> 
> \_No response\_
> 
> \### System Info
> 
> \`\`\`shell
> Gradio Environment Information:
> \------------------------------
> Operating System: Darwin
> gradio version: 4.16.0
> gradio\_client version: 0.8.1
> 
> \------------------------------------------------
> gradio dependencies in your environment:
> 
> aiofiles: 23.2.1
> altair: 5.2.0
> fastapi: 0.109.0
> ffmpy: 0.3.1
> gradio-client==0.8.1 is not installed.
> httpx: 0.26.0
> huggingface-hub: 0.20.3
> importlib-resources: 6.1.1
> jinja2: 3.1.3
> markupsafe: 2.1.4
> matplotlib: 3.8.2
> numpy: 1.26.3
> orjson: 3.9.12
> packaging: 23.2
> pandas: 2.2.0
> pillow: 10.2.0
> pydantic: 2.5.3
> pydub: 0.25.1
> python-multipart: 0.0.6
> pyyaml: 6.0.1
> ruff: 0.1.14
> semantic-version: 2.10.0
> tomlkit==0.12.0 is not installed.
> typer: 0.9.0
> typing-extensions: 4.9.0
> uvicorn: 0.27.0
> authlib; extra == 'oauth' is not installed.
> itsdangerous; extra == 'oauth' is not installed.
> 
> 
> gradio\_client dependencies in your environment:
> 
> fsspec: 2023.12.2
> httpx: 0.26.0
> huggingface-hub: 0.20.3
> packaging: 23.2
> typing-extensions: 4.9.0
> websockets: 11.0.3
> \`\`\`
> 
> 
> \### Severity
> 
> I can work around it
