gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
29.49k stars 2.19k forks source link

Use mount_gradio_app(auth_dependency) can not submit #8171

Closed uniltone closed 2 weeks ago

uniltone commented 2 weeks ago

Describe the bug

When I use the mount_gradio_app() method, add the auth_dependency parameter, and start the fastapi service, I find that the send button submit event cannot take effect.

Have you searched existing issues? 🔎

Reproduction

from fastapi import FastAPI, Request
import gradio as gr
import uvicorn
app = FastAPI()
import re
def get_user(request: Request):
    host = request.client.host
    query = request.url.query
    query = re.split('=|&',query)
    new_dic = {'user':None}
    for i in range(len(query)):
        if i % 2 == 0 and len(query)>0: 
            try :new_dic[query[i]] = query[i+1]
            except Exception as e:print(e)
    print(new_dic)
    if host=="127.0.0.1": 
        if new_dic['user'] == '52HZ':
            return True
        else:
            return None
    else:     
        return None
def chat(message,history):
    return "Hello"

demo = gr.ChatInterface(fn=chat,)
demo.startup_events()

app = gr.mount_gradio_app(app, demo, path="/", auth_dependency=get_user)

if __name__ == '__main__':
    uvicorn.run(app,port=8001)

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.28.3
gradio_client version: 0.16.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.3.0
fastapi: 0.110.2
ffmpy: 0.3.2
gradio-client==0.16.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.22.2
importlib-resources: 6.4.0
jinja2: 3.1.3
markupsafe: 2.1.5
matplotlib: 3.8.4
numpy: 1.26.4
orjson: 3.10.1
packaging: 24.0
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.1
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.4.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.11.0
urllib3: 2.2.1
uvicorn: 0.29.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.3.1
httpx: 0.27.0
huggingface-hub: 0.22.2
packaging: 24.0
typing-extensions: 4.11.0
websockets: 11.0.3

Severity

Blocking usage of gradio

abidlabs commented 2 weeks ago

Hi @uniltone is it possible that get_user() is returning None?

abidlabs commented 2 weeks ago

Going to close for lack of follow up. Can reopen with more details