File size: 2,430 Bytes
f26fd20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eed4537
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from t2i_space import get_t2i_space_contents

css = """

.title { text-align: center; }

"""

with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
    gr.Markdown("# Gradio Demo Space creation helper V2", elem_classes="title")
    gr.Markdown(
        f"""

**The steps are the following**:

- Input model Repo ID which you want to use. e.g. 'user/model'.

- Click "Submit" and download generated README.md and app.py.

- [Create your new Gradio space](https://huggingface.co/new-space) with blank.

- Upload README.md and app.py to your space.

- If you got 500 / 504 error, it happens often, just restart space.

- If it does not work no matter how many times you try, there is often a problem with the settings of the original repo itself, or there is no generation function.

            """
    )
    with gr.Column():
        repo_id = gr.Textbox(label="Model repo ID", placeholder="username/modelname", value="", max_lines=1)
        with gr.Accordion("Advanced", open=False):
            with gr.Row():
                gradio_version = gr.Textbox(label="Gradio version", placeholder="username/modelname", value="5.11.0", max_lines=1)
                private_ok = gr.Checkbox(label="Allow private repo", value=True)
            with gr.Row():
                hf_user = gr.Textbox(label="Your HF user ID (Optional)", placeholder="username", value="", max_lines=1)
                hf_repo = gr.Textbox(label="New space name (Optional)", placeholder="spacename", info="If empty, auto-complete", value="", max_lines=1)
            hf_token = gr.Textbox(label="Your HF write token (Optional)", placeholder="hf_...", value="", max_lines=1)
            with gr.Row():
                is_private = gr.Checkbox(label="Create private repo (Optional)", value=True)
                is_setkey = gr.Checkbox(label="Set your token to space (Optional)", info="For private / gated models", value=False)
        run_button = gr.Button(value="Submit")
        space_file = gr.Files(label="Output", interactive=False)
        output_md = gr.Markdown(label="Output")

    gr.on(
        triggers=[repo_id.submit, run_button.click],
        fn=get_t2i_space_contents,
        inputs=[repo_id, gradio_version, private_ok, hf_user, hf_repo, is_private, is_setkey, hf_token],
        outputs=[space_file, output_md],
    )

demo.queue()
demo.launch(ssr_mode=False)