File size: 1,211 Bytes
a5078bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 gradio_promptweighting import PromptWeighting


example = PromptWeighting().example_value()


def predict(input):
    return (input, input)


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            prompt = PromptWeighting(
                value=[
                    {"prompt": "a cat", "scale": 1.5},
                    {"prompt": "a dog", "scale": 1},
                    {"prompt": "a bird", "scale": 0.5},
                ],
                step=0.001,
                info="Please drag up or down to adjust the weight of the prompt.",
            )
            btn = gr.Button("Update Prompt")
        with gr.Column():
            text = gr.Textbox(
                label="Prompt",
                placeholder="",
            )
            prompt2 = PromptWeighting(min=0, max=10, step=0.001)
    inputs = [prompt]
    outputs = [text, prompt2]

    btn.click(fn=predict, inputs=inputs, outputs=outputs, show_progress=False)
    prompt.change(
        fn=predict,
        inputs=inputs,
        outputs=outputs,
        queue=False,
        trigger_mode="always_last",
        show_progress=False,
    )


if __name__ == "__main__":
    demo.launch()