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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use argparse in reload mode #3726

Closed
1 task done
LZY-the-boys opened this issue Apr 1, 2023 · 2 comments · Fixed by #4119
Closed
1 task done

Can't use argparse in reload mode #3726

LZY-the-boys opened this issue Apr 1, 2023 · 2 comments · Fixed by #4119
Labels
bug Something isn't working

Comments

@LZY-the-boys
Copy link

Describe the bug

When I use argparse in reload mode, it cause errors, for example:

import gradio as gr
import argparse
with gr.Blocks() as demo:
    gr.Markdown("# Greetings from Gradio!")
    inp = gr.Textbox(placeholder="What is your name?")
    out = gr.Textbox()

    inp.change(fn=lambda x: f"Welcome, {x}!", 
               inputs=inp, 
               outputs=out)

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--a", type=str, default="decapoda-research/llama-7b-hf")
    parser.add_argument("--b", type=str, default="./lora-Vicuna/checkpoint-3000")
    parser.add_argument("--c", type=int, default=1)
    parser.add_argument("--e", type=int, default=1)
    parser.add_argument("--d", type=int, default=1)
    args, unknown = parser.parse_known_args()
    demo.launch()

When I launch it using gradio tmp.py --a 1 , it throws

ERROR:    Error loading ASGI app. Attribute "--a.app" not found in module "tmp".

It seems that it interpet --a 1 to "--a.app" . I don't find any description in documents

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

above code

Screenshot

No response

Logs

ERROR:    Error loading ASGI app. Attribute "--a.app" not found in module "tmp".

System Info

linux

Severity

annoying

@LZY-the-boys LZY-the-boys added the bug Something isn't working label Apr 1, 2023
@freddyaboulton
Copy link
Collaborator

Hi @LZY-the-boys ! Thanks for filing.

I don't think we'll be able to support this use case. What gradio command does is delegate to uvicorn's run-in-reload mode, which imports the app object from your file, so the part in the if __name__ == '__main__' clause will not be run. Also, uvicorn's command line does not support arbitrary extra arguments (docs).

What I suggest you do is load those variables via an environment variable or from a config file!

@LZY-the-boys
Copy link
Author

OK, thanks for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants