File size: 1,222 Bytes
47ba4f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 yaml
import pyperclip
import gradio as gr

def get_options(file_path):
    with open(file_path, 'r') as file:
        options = yaml.load(file, Loader=yaml.FullLoader)
    return options

def generate_output(topic, options):
    output = topic + ', ' + ', '.join([options[key] for key in options])
    return output

def run_app(file_path='options.yaml'):
    options = get_options(file_path)

    inputs = [
        gr.inputs.Textbox(label="Enter image topic:")
    ]

    for key in options.keys():
        inputs.append(gr.inputs.Dropdown(options[key], label=key))

    outputs = gr.outputs.Textbox(label="Output:")

    def submit_handler(*input_values):
        topic = input_values[0]
        option_values = {}
        for i, key in enumerate(options.keys()):
            option_values[key] = input_values[i+1]
        output = generate_output(topic, option_values)
        pyperclip.copy(output)
        return output

    interface = gr.Interface(
        submit_handler, 
        inputs, 
        outputs, 
        title="Image Prompt Generator", 
        description="Select options to generate image prompt and copy to clipboard."
    )

    interface.launch()

if __name__ == '__main__':
    run_app()